You are here

public function Echeck::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 OnsiteBase::capturePayment

File

src/Plugin/Commerce/PaymentGateway/Echeck.php, line 145

Class

Echeck
Provides the Authorize.net echeck payment gateway.

Namespace

Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway

Code

public function capturePayment(PaymentInterface $payment, Price $amount = NULL) {

  // If not specified, capture the entire amount.
  $amount = $amount ?: $payment
    ->getAmount();
  $this
    ->assertPaymentState($payment, [
    'pending',
  ]);
  $payment
    ->setState('completed');
  $payment
    ->setAmount($amount);
  $payment
    ->save();
}