How do I cancel a payment in my payment driver?

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

    // mark the response as successful

    return $response;

Articles in this section

Was this article helpful?
0 out of 0 found this helpful