public static function ErrorHelper::handleException in Commerce Stripe 8
Translates Stripe exceptions into Commerce exceptions.
Parameters
\Stripe\Exception\ApiErrorException $exception: The Stripe exception.
Throws
\Drupal\commerce_payment\Exception\PaymentGatewayException The Commerce exception.
8 calls to ErrorHelper::handleException()
- Stripe::capturePayment in src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php - Captures the given authorized payment.
- Stripe::createPayment in src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php - Creates a payment.
- Stripe::createPaymentIntent in src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php - Create a payment intent for an order.
- Stripe::deletePaymentMethod in src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php - Deletes the given payment method.
- Stripe::doCreatePaymentMethod in src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php - Creates the payment method on the gateway.
File
- src/
ErrorHelper.php, line 31
Class
- ErrorHelper
- Translates Stripe exceptions and errors into Commerce exceptions.
Namespace
Drupal\commerce_stripeCode
public static function handleException(ApiErrorException $exception) {
if ($exception instanceof CardException) {
\Drupal::logger('commerce_stripe')
->warning($exception
->getMessage());
if ($exception
->getStripeCode() == 'card_declined' && $exception
->getDeclineCode() == 'card_not_supported') {
// Stripe only supports Visa/MasterCard/Amex for non-USD transactions.
// @todo Find a better way to communicate this to the customer.
$message = t('Your card is not supported. Please use a Visa, MasterCard, or American Express card.');
\Drupal::messenger()
->addWarning($message);
throw new HardDeclineException($message);
}
else {
throw new DeclineException('We encountered an error processing your card details. Please verify your details and try again.');
}
}
elseif ($exception instanceof RateLimitException) {
\Drupal::logger('commerce_stripe')
->warning($exception
->getMessage());
throw new InvalidRequestException('Too many requests.');
}
elseif ($exception instanceof StripeInvalidRequestException) {
\Drupal::logger('commerce_stripe')
->warning($exception
->getMessage());
throw new InvalidRequestException('Invalid parameters were supplied to Stripe\'s API.');
}
elseif ($exception instanceof StripeAuthenticationException) {
\Drupal::logger('commerce_stripe')
->warning($exception
->getMessage());
throw new AuthenticationException('Stripe authentication failed.');
}
elseif ($exception instanceof ApiConnectionException) {
\Drupal::logger('commerce_stripe')
->warning($exception
->getMessage());
throw new InvalidResponseException('Network communication with Stripe failed.');
}
elseif ($exception instanceof ApiErrorException) {
\Drupal::logger('commerce_stripe')
->warning($exception
->getMessage());
throw new InvalidResponseException('There was an error with Stripe request.');
}
else {
throw new InvalidResponseException($exception
->getMessage());
}
}