If capturing of the payment is done at a later stage to the initial authorisation, the payment gateway should support the ability to cancel the transaction. The driver should therefore implement a cancel
method.
The cancel
method should return a Aero\Payment\Responses\PaymentResponse
instance.
public function cancel(Payment $payment)
{
$response = new \Aero\Payment\Responses\PaymentResponse();
// request to cancel the transaction using the 3rd party API
$capture = AcmePaymentsInc::cancelTransaction($payment->reference);
// check if the transaction status is "cancelled"
if ($capture->status !== AcmePaymentsInc::STATUS_CANCELLED) {
// set an error on the response
$response->setError('The transaction could not be cancelled.');
return $response;
}
// internally mark the aero payment as cancelled
$payment->cancel();
// mark the response as successful
$response->setSuccessful(true);
return $response;
}