mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
553 stars 191 forks source link

Two proposals for canceling refunds #683

Closed Semvrij closed 1 year ago

Semvrij commented 1 year ago

Refund class canBeCanceled() method

A getter for the Refund class, to know if a refund can be canceled. Something like the canBeRefunded() method on the Payment class.

Change the RefundStatus after using the cancel() method

After using $refund->cancel() change the RefundStatus to STATUS_CANCELED or not if failed. It feels unnecessary to do another request right after.

$refund->cancel();

// Refresh the refund, because the status does not get updated
$refund = $payment->getRefund($refund->id);
Naoray commented 1 year ago

Hi @Semvrij,

Thank you for your suggestions!

We have implemented the canBeCanceled() method in the Refund class as you suggested in #683.

However, we have decided not to implement the change for the cancel() method. The primary reason behind this decision is that we want to maintain consistency with other cancel() calls in our package. Implementing a change to the cancel() method specifically for the Refund class would introduce an inconsistency within our package, which could potentially confuse users.

You can still implement the refund status change in your code by wrapping the $refund->cancel() method inside a try/catch statement and set the status to RefundStatus::STATUS_CANCELED if the call succeeds.