You are here

public static function ErrorHelper::handleException in Commerce Braintree 8

Translates Braintree exceptions into Commerce exceptions.

Parameters

\Braintree\Exception $exception: The Braintree exception.

Throws

\Drupal\commerce_payment\Exception\PaymentGatewayException The Commerce exception.

8 calls to ErrorHelper::handleException()
Braintree3DSReview::buildPaneForm in src/Plugin/Commerce/CheckoutPane/Braintree3DSReview.php
Builds the pane form.
Braintree3DSReview::validatePaneForm in src/Plugin/Commerce/CheckoutPane/Braintree3DSReview.php
Validates the pane form.
HostedFields::capturePayment in src/Plugin/Commerce/PaymentGateway/HostedFields.php
Captures the given authorized payment.
HostedFields::createPayment in src/Plugin/Commerce/PaymentGateway/HostedFields.php
Creates a payment.
HostedFields::deletePaymentMethod in src/Plugin/Commerce/PaymentGateway/HostedFields.php
Deletes the given payment method.

... See full list

File

src/ErrorHelper.php, line 28

Class

ErrorHelper
Translates Braintree exceptions and errors into Commerce exceptions.

Namespace

Drupal\commerce_braintree

Code

public static function handleException(\Braintree\Exception $exception) {
  if ($exception instanceof \Braintree\Exception\Authentication) {
    throw new AuthenticationException('Braintree authentication failed.');
  }
  elseif ($exception instanceof \Braintree\Exception\Authorization) {
    throw new AuthenticationException('The used API key is not authorized to perform the attempted action.');
  }
  elseif ($exception instanceof \Braintree\Exception\NotFound) {
    throw new InvalidRequestException('Braintree resource not found.');
  }
  elseif ($exception instanceof \Braintree\Exception\UpgradeRequired) {
    throw new InvalidRequestException('The Braintree client library needs to be updated.');
  }
  elseif ($exception instanceof \Braintree\Exception\TooManyRequests) {
    throw new InvalidRequestException('Too many requests.');
  }
  elseif ($exception instanceof \Braintree\Exception\ServerError) {
    throw new InvalidResponseException('Server error.');
  }
  elseif ($exception instanceof \Braintree\Exception\DownForMaintenance) {
    throw new InvalidResponseException('Request timed out.');
  }
  else {
    throw new InvalidResponseException($exception
      ->getMessage());
  }
}