public function Checkout::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/ Checkout.php, line 552
Class
- Checkout
- Provides the PayPal Checkout payment gateway.
Namespace
Drupal\commerce_paypal\Plugin\Commerce\PaymentGatewayCode
public function voidPayment(PaymentInterface $payment) {
$this
->assertPaymentState($payment, [
'authorization',
]);
try {
$sdk = $this->checkoutSdkFactory
->get($this->configuration);
$response = $sdk
->voidPayment($payment
->getRemoteId());
} catch (BadResponseException $exception) {
$this->logger
->error($exception
->getResponse()
->getBody()
->getContents());
throw new PaymentGatewayException('An error occurred while voiding the payment.');
}
if ($response
->getStatusCode() == Response::HTTP_NO_CONTENT) {
$payment
->setState('authorization_voided');
$payment
->save();
}
}