If the payment gateway provides the ability to externally make refund requests, the payment driver can use the Aero\Payment\SupportsRefunding
trait.
The refund
method should then be implemented, which returns an instance of Aero\Payment\Responses\PaymentResponse
.
public function refund(int $amount, Payment $payment)
{
$response = new \Aero\Payment\Responses\PaymentResponse();
// request to refund the transaction using the 3rd party API, with a given amount
$capture = AcmePaymentsInc::refundTransaction($payment->reference, $amount);
// check if the transaction status is "refunded"
if ($capture->status !== AcmePaymentsInc::STATUS_REFUNDED) {
// set an error on the response
$response->setError('The transaction could not be refunded.');
return $response;
}
// internally refund the amount for the aero payment
$payment->refund([
'amount' => $amount,
]);
// mark the response as successful
$response->setSuccessful(true);
return $response;
}