From 24998335e6750167ce62f81cf0b8ff537809bea4 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Tue, 12 Nov 2024 12:25:02 +0100 Subject: [PATCH] Display error when card is declined --- Application/translations/de/stripe_lang.php | 1 + Application/translations/en/stripe_lang.php | 1 + extend/Application/Controller/PaymentController.php | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Application/translations/de/stripe_lang.php b/Application/translations/de/stripe_lang.php index c6ba11c..7a393a9 100644 --- a/Application/translations/de/stripe_lang.php +++ b/Application/translations/de/stripe_lang.php @@ -36,6 +36,7 @@ 'STRIPE_ERROR_SOMETHING_WENT_WRONG' => 'Ein unbekannter Fehler ist aufgetreten', 'STRIPE_ERROR_ORDER_CANCELED' => 'Die Bezahlung wurde storniert, bitte versuchen Sie es erneut', 'STRIPE_ERROR_ORDER_FAILED' => 'Die Bezahlung ist fehlgeschlagen, bitte versuchen Sie es erneut', + 'STRIPE_ERROR_CARD_DECLINED' => 'Kartenzahlung abgelehnt', 'STRIPE_SECOND_CHANCE_MAIL_SUBJECT' => 'Abschluss Ihrer Bestellung bei', 'STRIPE_ERROR_ORDER_CONFIG_PUBKEY' => 'Bitte konfigurieren Sie den veröffentlichbaren Stripe-Schlüssel, um diese Zahlungsmethode zu verwenden.', 'STRIPE_WEBHOOK_CREATE_ERROR' => 'Der Webhook-Endpunkt konnte nicht erstellt werden.', diff --git a/Application/translations/en/stripe_lang.php b/Application/translations/en/stripe_lang.php index ddce621..792b006 100644 --- a/Application/translations/en/stripe_lang.php +++ b/Application/translations/en/stripe_lang.php @@ -36,6 +36,7 @@ 'STRIPE_ERROR_SOMETHING_WENT_WRONG' => 'An unknown error occured', 'STRIPE_ERROR_ORDER_CANCELED' => 'Payment was canceled, please try again', 'STRIPE_ERROR_ORDER_FAILED' => 'Payment failed, please try again', + 'STRIPE_ERROR_CARD_DECLINED' => 'Payment failed, card was declined', 'STRIPE_SECOND_CHANCE_MAIL_SUBJECT' => 'Completion of your order at', 'STRIPE_ERROR_ORDER_CONFIG_PUBKEY' => 'Please configure Stripe publishable key to use this payment method.', 'STRIPE_WEBHOOK_CREATE_ERROR' => 'The Webhook Endpoint could not be created.', diff --git a/extend/Application/Controller/PaymentController.php b/extend/Application/Controller/PaymentController.php index 1a1f470..7152ee3 100644 --- a/extend/Application/Controller/PaymentController.php +++ b/extend/Application/Controller/PaymentController.php @@ -11,6 +11,7 @@ use OxidEsales\Eshop\Application\Model\Basket; use OxidEsales\Eshop\Application\Model\Country; use OxidEsales\Eshop\Core\Registry; +use Stripe\Exception\CardException; class PaymentController extends PaymentController_parent { @@ -145,7 +146,17 @@ public function validatepayment() Registry::getSession()->setVariable('stripe_current_payment_method_id', $oPaymentMethod->id); } } - } catch (\Exception $oEx) { + } + catch (CardException $stripeCardException){ + Registry::getLogger()->error($stripeCardException->getTraceAsString()); + + if("card_declined" === $stripeCardException->getStripeCode()){ + Registry::getUtilsView()->addErrorToDisplay('STRIPE_ERROR_CARD_DECLINED'); + } + + $mRet = 'payment'; + } + catch (\Exception $oEx) { Registry::getLogger()->error($oEx->getTraceAsString()); $mRet = 'payment'; }