If the gateway provides the option to defer capturing the payment (authorising and capturing are performed at different times), the capture
method should be implemented. This captured amount may be equal to or less than the authorised amount, and is always passed to the method in the lowest form of currency (pennies, cents, etc.).
The capture
method should return a Aero\Payment\Responses\PaymentResponse
instance.
public function capture(int $amount, Payment $payment)
{
$response = new \Aero\Payment\Responses\PaymentResponse();
// request to capture the transaction using the 3rd party API
$capture = AcmePaymentsInc::captureTransaction($payment->reference, $amount);
// check if the transaction status is "captured"
if ($capture->status !== AcmePaymentsInc::STATUS_CAPTURED) {
// update the status of the aero payment to "failed"
$payment->update([
'state' => \Aero\Payment\Models\Payment::FAILED,
]);
// set an error on the response
$response->setError('The transaction failed to be captured.');
return $response;
}
// internally capture the amount for the payment
$payment->capture([
'amount' => $amount,
]);
// mark the response as successful
$response->setSuccessful(true);
return $response;
}
Aero will attempt to auto-capture any authorised payments against an order when the order is marked as dispatched.