You are here

public function Payflow::voidPayment in Commerce PayPal 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

File

src/Plugin/Commerce/PaymentGateway/Payflow.php, line 419

Class

Payflow
Provides the PayPal Payflow payment gateway.

Namespace

Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway

Code

public function voidPayment(PaymentInterface $payment) {
  $this
    ->validatePayment($payment, 'authorization');
  $remoteId = $this
    ->getTransactionNumber($payment);
  if (empty($remoteId)) {
    throw new PaymentGatewayException('Remote authorization ID could not be determined.');
  }
  try {
    $data = $this
      ->executeTransaction([
      'trxtype' => 'V',
      'origid' => $this
        ->getTransactionNumber($payment),
      'verbosity' => 'HIGH',
    ]);
    if ($data['result'] !== '0') {
      throw new PaymentGatewayException('Payment could not be voided. Message: ' . $data['respmsg'], $data['result']);
    }
    $payment
      ->setState('authorization_voided');
    $payment
      ->save();
  } catch (RequestException $e) {
    throw new InvalidArgumentException('Only payments in the "authorization" state can be voided.');
  }
}