public static function ErrorHelper::handleErrors in Commerce Stripe 8
Translates Stripe errors into Commerce exceptions.
@todo Make sure this is really needed or handleException cover all possible errors.
Parameters
object $result: The Stripe result object.
Throws
\Drupal\commerce_payment\Exception\PaymentGatewayException The Commerce exception.
2 calls to ErrorHelper::handleErrors()
- Stripe::refundPayment in src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php - Refunds the given payment.
- Stripe::voidPayment in src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php - Voids the given payment.
File
- src/
ErrorHelper.php, line 82
Class
- ErrorHelper
- Translates Stripe exceptions and errors into Commerce exceptions.
Namespace
Drupal\commerce_stripeCode
public static function handleErrors($result) {
$result_data = $result
->toArray();
if ($result_data['status'] == 'succeeded') {
return;
}
if (!empty($result_data['failure_code'])) {
$failure_code = $result_data['failure_code'];
// https://stripe.com/docs/api?lang=php#errors
// Validation errors can be due to a module error (mapped to
// InvalidRequestException) or due to a user input error (mapped to
// a HardDeclineException).
$hard_decline_codes = [
'processing_error',
'missing',
'card_declined',
];
if (in_array($failure_code, $hard_decline_codes)) {
throw new HardDeclineException($result_data['failure_message'], $failure_code);
}
else {
throw new InvalidRequestException($result_data['failure_message'], $failure_code);
}
}
}