public function OnsiteBase::capturePayment in Commerce Authorize.Net 8
Captures the given authorized payment.
Only payments in the 'authorization' state can be captured.
Parameters
\Drupal\commerce_payment\Entity\PaymentInterface $payment: The payment to capture.
\Drupal\commerce_price\Price $amount: The amount to capture. If NULL, defaults to the entire payment amount.
Throws
\Drupal\commerce_payment\Exception\PaymentGatewayException Thrown when the transaction fails for any reason.
Overrides SupportsAuthorizationsInterface::capturePayment
1 method overrides OnsiteBase::capturePayment()
- Echeck::capturePayment in src/
Plugin/ Commerce/ PaymentGateway/ Echeck.php - Captures the given authorized payment.
File
- src/
Plugin/ Commerce/ PaymentGateway/ OnsiteBase.php, line 222
Class
- OnsiteBase
- Provides the Authorize.net payment gateway base class.
Namespace
Drupal\commerce_authnet\Plugin\Commerce\PaymentGatewayCode
public function capturePayment(PaymentInterface $payment, Price $amount = NULL) {
$this
->assertPaymentState($payment, [
'authorization',
]);
// If not specified, capture the entire amount.
$amount = $amount ?: $payment
->getAmount();
$request = new CreateTransactionRequest($this->authnetConfiguration, $this->httpClient);
$request
->setTransactionRequest(new TransactionRequest([
'transactionType' => TransactionRequest::PRIOR_AUTH_CAPTURE,
'amount' => $amount
->getNumber(),
'refTransId' => $payment
->getRemoteId(),
]));
$response = $request
->execute();
if ($response
->getResultCode() != 'Ok') {
$this
->logResponse($response);
$message = $response
->getMessages()[0];
throw new PaymentGatewayException($message
->getText());
}
$payment
->setState('completed');
$payment
->setAmount($amount);
$payment
->save();
}