Add supportsRefund/doRefund for gateways whose Omnipay driver implements refund - #304
Open
magnolia61 wants to merge 1 commit into
Open
Add supportsRefund/doRefund for gateways whose Omnipay driver implements refund#304magnolia61 wants to merge 1 commit into
magnolia61 wants to merge 1 commit into
Conversation
magnolia61
force-pushed
the
refund-support
branch
from
July 4, 2026 12:43
33983c7 to
834e69f
Compare
…nts refund() Implements CiviCRM's refund contract (PaymentProcessor.refund API / supportsRefund capability) generically: supportsRefund() resolves the Omnipay gateway class without instantiating it and reports TRUE only when that class exposes a refund() method. doRefund() sends the refund via the gateway (transactionReference = original trxn_id) and returns refund_trxn_id / refund_status per the core contract. Failures throw PaymentProcessorException so CiviCRM never records a refund the gateway rejected. Details: - A description is always sent: Mollie's create-refund API requires one and it may be shown to the customer (e.g. on their bank statement). Callers can pass their own via $params['description']. - The existing alterPaymentProcessorParams hook fires before sending, with an 'action' => 'Refund' marker (removed after the hook), so extensions can customise refund parameters the same way they already can for purchases. - The fallback currency is resolved from the original transaction via APIv4 FinancialTrxn::get, defaulting to the processor currency. - refund_trxn_id prefers getTransactionId() (Mollie exposes the new re_... id there) and falls back to getTransactionReference(), which is where most other Omnipay drivers expose the refund reference. Verified live against Mollie (iDeal) on CiviCRM 6.x: refund accepted and the re_... id recorded as refund_trxn_id. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
magnolia61
force-pushed
the
refund-support
branch
from
July 4, 2026 13:17
834e69f to
4fc8707
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This adds refund support to the processor, wired to CiviCRM's standard refund contract (
supportsRefund()capability +doRefund()as called by thePaymentProcessor.refundAPIv4 action, and used by e.g. mjwshared's refund UI).Without this, extensions like mjwshared fall back to their record-only branch for any Omnipay processor: the refund is booked in CiviCRM but no money moves at the gateway.
Approach
supportsRefund()resolves the Omnipay gateway class via\Omnipay\Common\Helper::getGatewayClassName()without instantiating it and returns TRUE only when that class exposes arefund()method — so this stays generic across the Omnipay universe and is safe to call in listing contexts.doRefund()initializes the gateway (same sequenceinitialize()uses, minus the form/session steps that needcomponent/qfKey), then sendsrefund(['transactionReference' => trxn_id, 'amount', 'currency']). Currency defaults to the original financial_trxn's currency.refund_trxn_id(the gateway's refund id) andrefund_status'Completed' per the core contract. Any failure throwsPaymentProcessorExceptionrather than returning a failure array, so CiviCRM never records a refund the gateway rejected.Testing
Deployed and verified against Mollie (iDeal/Bancontact) on CiviCRM 6.x:
supportsRefund()correctly reports TRUE for Mollie processors (whose Omnipay driver implementsrefund()) and would report FALSE for drivers without one. New code passes civilint with zero findings.Related issue:
#242