From 303a555d0422fae0ae7d0f47cf161b7d8ff07079 Mon Sep 17 00:00:00 2001 From: afayadas Date: Thu, 6 Jan 2022 11:33:52 +0100 Subject: [PATCH 1/6] refs #32038 #32946 : fix handler classlib uses in code --- controllers/front/orderSuccess.php | 2 +- controllers/front/validation.php | 2 +- controllers/front/webhook.php | 2 +- stripe_official.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/front/orderSuccess.php b/controllers/front/orderSuccess.php index 3b58720..b146581 100644 --- a/controllers/front/orderSuccess.php +++ b/controllers/front/orderSuccess.php @@ -214,7 +214,7 @@ private function handleWebhookActions($intent) ); } - if (!$handler->process('ValidationOrder')) { + if (!$handler->process('ValidationOrderActions')) { // Handle error ProcessLoggerHandler::logError( 'Order creation process disrupted.', diff --git a/controllers/front/validation.php b/controllers/front/validation.php index d541499..1c4b691 100644 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -90,7 +90,7 @@ public function initContent() } // Process actions chain - if ($handler->process('ValidationOrder')) { + if ($handler->process('ValidationOrderActions')) { // Retrieve and use resulting data $returnValues = $handler->getConveyor(); } else { diff --git a/controllers/front/webhook.php b/controllers/front/webhook.php index 50a67e1..0390e61 100755 --- a/controllers/front/webhook.php +++ b/controllers/front/webhook.php @@ -570,7 +570,7 @@ private function handleWebhookActions($handler, $event) } // Process actions chain - if (!$handler->process('ValidationOrder')) { + if (!$handler->process('ValidationOrderActions')) { // Handle error ProcessLoggerHandler::logError( 'Webhook actions process failed.', diff --git a/stripe_official.php b/stripe_official.php index b80a08c..e6ce7e9 100755 --- a/stripe_official.php +++ b/stripe_official.php @@ -870,7 +870,7 @@ public function getContent() 'registerWebhookSignature' ); - $handler->process('Configuration'); + $handler->process('ConfigurationActions'); } $shopGroupId = Stripe_official::getShopGroupIdContext(); From 0f51bd6d1ec48fbc3db56471c59ff39a693b0887 Mon Sep 17 00:00:00 2001 From: afayadas Date: Thu, 6 Jan 2022 12:25:35 +0100 Subject: [PATCH 2/6] refs #32949 : fix issues with currency iso_code --- controllers/front/createIntent.php | 2 +- stripe_official.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/front/createIntent.php b/controllers/front/createIntent.php index a2faadc..f1f7529 100644 --- a/controllers/front/createIntent.php +++ b/controllers/front/createIntent.php @@ -52,7 +52,7 @@ public function initContent() $paymentOption = Tools::getValue('payment_option'); $paymentMethodId = Tools::getValue('id_payment_method'); - $intentData = $this->constructIntentData($amount, $currency, $paymentOption, $paymentMethodId); + $intentData = $this->constructIntentData($amount, $currency->iso_code, $paymentOption, $paymentMethodId); $cardData = $this->constructCardData($paymentMethodId); diff --git a/stripe_official.php b/stripe_official.php index e6ce7e9..8f00748 100755 --- a/stripe_official.php +++ b/stripe_official.php @@ -1678,7 +1678,7 @@ public function hookHeader() 'stripe_pk' => $this->getPublishableKey(), 'stripe_merchant_country_code' => $merchantCountry->iso_code, - 'stripe_currency' => Tools::strtolower($currency), + 'stripe_currency' => Tools::strtolower($currency->iso_code), 'stripe_amount' => Tools::ps_round($amount, 2), 'stripe_fullname' => $stripe_fullname, From 79907cedf3426fcee73bf5a90b12080590eef98e Mon Sep 17 00:00:00 2001 From: afayadas Date: Thu, 6 Jan 2022 16:15:06 +0100 Subject: [PATCH 3/6] refs #32949 : fix issue with payment intent update --- controllers/front/createIntent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/front/createIntent.php b/controllers/front/createIntent.php index f1f7529..51b69e6 100644 --- a/controllers/front/createIntent.php +++ b/controllers/front/createIntent.php @@ -57,8 +57,6 @@ public function initContent() $cardData = $this->constructCardData($paymentMethodId); $intent = $this->createIdempotencyKey($intentData); - - $this->registerStripeEvent($intent); } catch (Exception $e) { ProcessLoggerHandler::logError( "Retrieve Stripe Account Error => ".$e->getMessage(), @@ -229,7 +227,9 @@ private function createIdempotencyKey($intentData) if (empty($stripeIdempotencyKey->id) === true) { $intent = $stripeIdempotencyKey->createNewOne($cart->id, $intentData); + $this->registerStripeEvent($intent); } else { + unset($intentData['capture_method']); $intent = $stripeIdempotencyKey->updateIntentData($intentData); } From 255c81afb3dc1ac314ff4eaac941918f27db32db Mon Sep 17 00:00:00 2001 From: afayadas Date: Mon, 10 Jan 2022 15:36:40 +0100 Subject: [PATCH 4/6] refs #32970 #32977 : fix webhook return call issues after order creation --- controllers/front/createIntent.php | 6 +++- controllers/front/orderSuccess.php | 57 ++++++++++++++++++++---------- controllers/front/webhook.php | 3 +- 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/controllers/front/createIntent.php b/controllers/front/createIntent.php index 51b69e6..c19eda1 100644 --- a/controllers/front/createIntent.php +++ b/controllers/front/createIntent.php @@ -225,7 +225,10 @@ private function createIdempotencyKey($intentData) $stripeIdempotencyKey = new StripeIdempotencyKey(); $stripeIdempotencyKey = $stripeIdempotencyKey->getByIdCart($cart->id); - if (empty($stripeIdempotencyKey->id) === true) { + $lastRegisteredEvent = new StripeEvent(); + $lastRegisteredEvent = $lastRegisteredEvent->getLastRegisteredEventByPaymentIntent($stripeIdempotencyKey->id); + + if (empty($stripeIdempotencyKey->id) === true || $lastRegisteredEvent->status === 'FAILED') { $intent = $stripeIdempotencyKey->createNewOne($cart->id, $intentData); $this->registerStripeEvent($intent); } else { @@ -282,6 +285,7 @@ private function registerStripeEvent($intent) $stripeEvent->setStatus(StripeEvent::CREATED_STATUS); $stripeEvent->setDateAdd($intent->created); $stripeEvent->setIsProcessed(1); + $stripeEvent->setFlowType('direct'); if ($stripeEvent->save()) { ProcessLoggerHandler::logInfo( diff --git a/controllers/front/orderSuccess.php b/controllers/front/orderSuccess.php index b146581..f1da1b5 100644 --- a/controllers/front/orderSuccess.php +++ b/controllers/front/orderSuccess.php @@ -132,6 +132,10 @@ private function registerStripeEvent($paymentIntent) $stripeEventStatus = $this->checkEventStatus($paymentIntent); + if (empty($stripeEventStatus) === true) { + return false; + } + $stripeEventDate = new DateTime(); $stripeEventDate = $stripeEventDate->setTimestamp($eventCharge->created); @@ -196,7 +200,8 @@ private function handleWebhookActions($intent) 'addTentative' ); } elseif (($eventType == 'pending' && $payment_method == 'sofort') - || (($eventType == 'succeeded' || $eventType == 'requires_action') && $payment_method != 'sofort') + || (($eventType == 'succeeded' || $eventType == 'requires_action') + && Stripe_official::$paymentMethods[$payment_method]['flow'] == 'redirect') ) { ProcessLoggerHandler::logInfo( 'Payment method flow with redirection', @@ -266,24 +271,40 @@ private function displayOrderConfirmation($id_intent) $secure_key = false; } - $url = Context::getContext()->link->getPageLink( - 'order-confirmation', - true, - null, - array( - 'id_cart' => $stripePayment->id_cart, - 'id_module' => (int)$this->module->id, - 'id_order' => $id_order, - 'key' => $secure_key - ) - ); + if ($id_order === 0) { + $url = Context::getContext()->link->getModuleLink( + 'stripe_official', + 'orderFailure', + array(), + true + ); - ProcessLoggerHandler::logInfo( - 'Confirmation order url => '.$url, - null, - null, - 'orderSuccess - displayOrderConfirmation' - ); + ProcessLoggerHandler::logInfo( + 'Failed order url => '.$url, + null, + null, + 'orderSuccess - displayOrderConfirmation' + ); + } else { + $url = Context::getContext()->link->getPageLink( + 'order-confirmation', + true, + null, + array( + 'id_cart' => $stripePayment->id_cart, + 'id_module' => (int)$this->module->id, + 'id_order' => $id_order, + 'key' => $secure_key + ) + ); + + ProcessLoggerHandler::logInfo( + 'Confirmation order url => '.$url, + null, + null, + 'orderSuccess - displayOrderConfirmation' + ); + } ProcessLoggerHandler::closeLogger(); Tools::redirect($url); diff --git a/controllers/front/webhook.php b/controllers/front/webhook.php index 0390e61..d603e7a 100755 --- a/controllers/front/webhook.php +++ b/controllers/front/webhook.php @@ -549,7 +549,8 @@ private function handleWebhookActions($handler, $event) 'addTentative' ); } elseif (($eventType == 'charge.pending' && $paymentMethodType == 'sofort') - || (($eventType == 'charge.succeeded' || $eventType == 'payment_intent.requires_action') && $paymentMethodType != 'sofort') + || (($eventType == 'charge.succeeded' || $eventType == 'payment_intent.requires_action') + && Stripe_official::$paymentMethods[$paymentMethodType]['flow'] == 'redirect') ) { ProcessLoggerHandler::logInfo( 'Payment method flow with redirection', From f5cb48a771e6042d3003bb334d35086e014dc4cb Mon Sep 17 00:00:00 2001 From: afayadas Date: Tue, 11 Jan 2022 12:34:50 +0100 Subject: [PATCH 5/6] refs #32959 #33014 : fix error message display and button text duplicate in prestashop 1.6 --- _dev/js/payments.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/_dev/js/payments.js b/_dev/js/payments.js index 38770be..44c65d7 100644 --- a/_dev/js/payments.js +++ b/_dev/js/payments.js @@ -30,7 +30,7 @@ $(function(){ // Create references to the submit button. const $submit = $('#payment-confirmation button[type="submit"], .stripe-europe-payments[data-method="bancontact"], .ideal-submit-button[data-method="ideal"], .stripe-europe-payments[data-method="giropay"], .stripe-europe-payments[data-method="sofort"], .stripe-europe-payments[data-method="fpx"], .stripe-europe-payments[data-method="eps"], .stripe-europe-payments[data-method="p24"], .stripe-europe-payments[data-method="sepa_debit"], .stripe-submit-button, .sepa_debit-submit-button'); const $submitButtons = $('#payment-confirmation button[type="submit"], .stripe-submit-button'); - const submitInitialText = $submitButtons.text(); + const submitInitialText = $submitButtons.first().text(); $form = $('#stripe-card-payment'); let payment = ''; @@ -647,10 +647,14 @@ $(function(){ // Update error message function updateError(element, error) { const $error = $(".stripe-payment-form:visible .stripe-error-message"); - var elementError = $(element).find('.stripe-error-message'); - var disableElement = $(element).siblings('.stripe-submit-button'); if (error) { - if (stripe_ps_version == '1.6') { + if (stripe_ps_version === '1.6') { + let elementError; + if (payment === 'card') { + elementError = $('#stripe-card-payment .stripe-error-message'); + } else { + elementError = $('#stripe-'+ payment +'-element .stripe-error-message'); + } $(elementError).text(error.message).show(); } else { $error.text(error.message).show(); @@ -660,11 +664,7 @@ $(function(){ } enableSubmit($submitButtons); } else { - if (stripe_ps_version == '1.6') { - $(elementError).text("").hide(); - } else { - $error.text("").hide(); - } + $error.text("").hide(); } } From 1835fc9a42eb591cf4a250c0d10cdca3cec80519 Mon Sep 17 00:00:00 2001 From: afayadas Date: Tue, 11 Jan 2022 15:35:07 +0100 Subject: [PATCH 6/6] refs #30674 : fix duplicate logo display on payment page with old card form --- stripe_official.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stripe_official.php b/stripe_official.php index 8f00748..e23ee61 100755 --- a/stripe_official.php +++ b/stripe_official.php @@ -1408,9 +1408,9 @@ public function getPaymentMethods() $query->from('configuration'); $query->where('name LIKE "STRIPE_PAYMENT%"'); $query->where('value = "on"'); - if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') === 1) { - $query->where('id_shop = '.$this->context->shop->id); - } + $query->where('id_shop_group = '.$this->context->shop->id_shop_group); + $query->where('id_shop = '.$this->context->shop->id); + $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query->build()); foreach ($results as &$result) {