You are here

public function HostedFields::voidPayment in Commerce Braintree 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/HostedFields.php, line 282

Class

HostedFields
Provides the HostedFields payment gateway.

Namespace

Drupal\commerce_braintree\Plugin\Commerce\PaymentGateway

Code

public function voidPayment(PaymentInterface $payment) {
  $this
    ->assertPaymentState($payment, [
    'authorization',
  ]);
  try {
    $remote_id = $payment
      ->getRemoteId();
    $result = $this->api
      ->transaction()
      ->void($remote_id);
    ErrorHelper::handleErrors($result);
  } catch (BraintreeException $e) {
    ErrorHelper::handleException($e);
  }
  $payment
    ->setState('authorization_voided');
  $payment
    ->save();
}