If you want to immediately capture the payment, just call purchase()
and completePurchase()
instead of authorize()
and completeAuthorize()
in your initial request (purchase does a combined authorize and capture).
If you want to capture the payment later (say, when the items are shipped), then you need to do the following.
// after initial completeAuthorize()
// store $ref in your database with the payment
$ref = $response->getTransactionReference();
// then later, when you want to capture it
$data = array(
'transactionReference' => $ref,
'amount' => '10.00', // pass original amount, or can be less
);
$response = $gateway->capture($data)->send();
if ($response->isSuccessful()) {
// success
} else {
// error, maybe you took too long to capture the transaction
echo $response->getMessage();
}