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 
cancelmethod.
The 
cancelmethod should return a 
Aero\Payment\Responses\PaymentResponseinstance.
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;
}