You are here

public function OnsiteBase::voidPayment in Commerce Authorize.Net 8

Voids the given payment.

Parameters

\Drupal\commerce_payment\Entity\PaymentInterface $payment: The payment to void.

Throws

\Drupal\commerce_payment\Exception\PaymentGatewayException Thrown when the transaction fails for any reason.

Overrides SupportsVoidsInterface::voidPayment

1 method overrides OnsiteBase::voidPayment()
Echeck::voidPayment in src/Plugin/Commerce/PaymentGateway/Echeck.php
Voids the given payment.

File

src/Plugin/Commerce/PaymentGateway/OnsiteBase.php, line 249

Class

OnsiteBase
Provides the Authorize.net payment gateway base class.

Namespace

Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway

Code

public function voidPayment(PaymentInterface $payment) {
  $this
    ->assertPaymentState($payment, [
    'authorization',
  ]);
  $request = new CreateTransactionRequest($this->authnetConfiguration, $this->httpClient);
  $request
    ->setTransactionRequest(new TransactionRequest([
    'transactionType' => TransactionRequest::VOID,
    'amount' => $payment
      ->getAmount()
      ->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('authorization_voided');
  $payment
    ->save();
}