Commerce: Add a cancel() method to Gateway Interface / Gateways

Created on 20 Dec 2018  路  8Comments  路  Source: craftcms/commerce

Description

When creating a Payment Gateway you can capture and refund, and you can authorize. But you can't unauthorize or cancel a payment.

For the payment provider that I currently is creating a Gateway for, un-captured payments will stay for several weeks before they are auto-cancelled.

馃挕 enhancement 馃挸 payments

Most helpful comment

Also would need to think about adding something to a transaction to know whether it can still be cancelled (time limits for cancellation by gateway usually) so a canCancel() method to transaction model, and canCancelTransaction() method to the transaction service.

All 8 comments

@andris thoughts?

No further update on this?

  • [ ] Should be able to cancel uncaptured payment if gateway supports it.

@lukeholder Is this something you are working on, or should I take a stab at at PR?

Just following up: Our use case is that all our refunds is cancellations of the payment intent instead of the already supported refund.

This is because payment have to happen on or after delivery, while most support cases happens before, usually because they did not get a delivery.

@sjelfull you are welcome to make a pull request.

Since you will need to add a cancel() and supportsCancel()method to the gateway interface this will be a breaking change for gateways that do not inherit from base gateway (if any) so would leave this for at least a point release.

Also would need to think about adding something to a transaction to know whether it can still be cancelled (time limits for cancellation by gateway usually) so a canCancel() method to transaction model, and canCancelTransaction() method to the transaction service.

@sjelfull Just thinking about the implementation of this.

Instead of changing the current GatewayInterface, we would want to create an additional CancellableGatewayInterface with the following 2 methods:

cancel(Transaction $transaction) : RequestResponseInterface
canCancel(Transaction $transaction) : bool

Then in Commerce 4 we will split out the other optional features of a gateway into their own interfaces. (Like partial refund).

You would still add canCancel() to the transaction model which calls the transaction service's canCancelTransaction(). That latter method would see if the gateway implements the CancellableGateway interface (which saves us having to call a supportsCancel() method, and also calls canCancel(Transaction) to know it cancellation is even possible.

Let me know if you have any questions.

Was this page helpful?
0 / 5 - 0 ratings