You are here

public function ExpressCheckout::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/ExpressCheckout.php, line 309

Class

ExpressCheckout
Provides the Paypal Express Checkout payment gateway.

Namespace

Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway

Code

public function voidPayment(PaymentInterface $payment) {
  $this
    ->assertPaymentState($payment, [
    'authorization',
  ]);

  // GetExpressCheckoutDetails API Operation (NVP).
  // Shows information about an Express Checkout transaction.
  $paypal_response = $this
    ->doVoid($payment);
  if ($paypal_response['ACK'] == 'Failure') {
    $message = $paypal_response['L_LONGMESSAGE0'];
    throw new PaymentGatewayException($message, $paypal_response['L_ERRORCODE0']);
  }
  $payment
    ->setState('authorization_voided');
  $payment
    ->save();
}