diff --git a/CHANGELOG.md b/CHANGELOG.md index 90d6305e..77bc38bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ PrestaShop 1.6.x, 1.7.x and 8.x # Changelog +## [5.0.1] +### Added +- Ensure the payment request does not fail in cases where `checkoutSession` is not returned or fails, particularly for older gateway API versions. + ## [5.0.0] ### Added - Add support for `checkoutSession` for reusable checkout sessions improving fraud detection and conversion. @@ -12,7 +16,6 @@ PrestaShop 1.6.x, 1.7.x and 8.x > **Note:** `checkoutSession` requires gateway version `20260311` or later. - ## [4.0.2] ### Added - Add support for Checkout Design v2. diff --git a/altapay.php b/altapay.php index 637eae76..423c107a 100644 --- a/altapay.php +++ b/altapay.php @@ -33,7 +33,7 @@ public function __construct() { $this->name = 'altapay'; $this->tab = 'payments_gateways'; - $this->version = '5.0.0'; + $this->version = '5.0.1'; $this->author = 'AltaPay A/S'; $this->is_eu_compatible = 1; $this->ps_versions_compliancy = ['min' => '1.6.0.1', 'max' => '8.2.3']; @@ -3186,6 +3186,7 @@ public function createTransaction($savecard, $results = false; } + $sessionId = null; try { $sessionRequest = new API\PHP\Altapay\Api\Payments\CheckoutSession(getAuth()); $sessionRequest->setTerminals([$cgConf['terminal']]) @@ -3194,6 +3195,11 @@ public function createTransaction($savecard, ->setCurrency($cgConf['currency']); $sessionResponse = $sessionRequest->call(); $sessionId = $sessionResponse->Session->Id; + } catch (\Exception $e) { + PrestaShopLogger::addLog($e->getMessage(), 2, $e->getCode(), $this->name, $this->id, true); + } + + try { $config = new API\PHP\Altapay\Request\Config(); $config->setCallbackOk($callback['callback_ok']); $config->setCallbackFail($callback['callback_fail']); @@ -3234,7 +3240,6 @@ public function createTransaction($savecard, ->setShopOrderId($requestShopOrderId) ->setAmount($requestAmount) ->setCurrency($cgConf['currency']) - ->setSessionID($sessionId) ->setCustomerInfo($customer) ->setTransactionInfo($transactionInfo) ->setCookie($cgConf['cookie']) @@ -3242,6 +3247,10 @@ public function createTransaction($savecard, ->setOrderLines($requestOrderLines) ->setSaleReconciliationIdentifier(sha1(uniqid(time(), true))); + if ($sessionId) { + $request->setSessionID($sessionId); + } + if (!$isReservation) { $request->setConfig($config)->setLanguage($cgConf['language']); if (!$terminal->applepay) { @@ -3292,7 +3301,7 @@ public function createTransaction($savecard, $message = $e->getMessage(); } } catch (API\PHP\Altapay\Exceptions\ClientException $e) { - $message = $e->getResponse()->getBody(); + $message = (string) $e->getResponse()->getBody(); } catch (API\PHP\Altapay\Exceptions\ResponseHeaderException $e) { $message = $e->getHeader()->ErrorMessage; } catch (API\PHP\Altapay\Exceptions\ResponseMessageException $e) { diff --git a/config.xml b/config.xml index 7c2468de..dcea2cf1 100644 --- a/config.xml +++ b/config.xml @@ -10,7 +10,7 @@ altapay - + diff --git a/controllers/front/callbackformexternal.php b/controllers/front/callbackformexternal.php index fb05dec2..9211738b 100644 --- a/controllers/front/callbackformexternal.php +++ b/controllers/front/callbackformexternal.php @@ -43,6 +43,7 @@ public function postProcess() 'stylingclass' => $payment_style, 'amount' => $postData['amount'], 'shop_logo' => _PS_IMG_ . Configuration::get('PS_LOGO'), + 'shop_name' => Configuration::get('PS_SHOP_NAME'), ]); if (version_compare(_PS_VERSION_, $this->module::PS_17_MIN_VERSION, '>=')) { $this->setTemplate('module:altapay/views/templates/front/payment_form_independent.tpl'); diff --git a/helpers.php b/helpers.php index c7a5f438..db3b2b25 100644 --- a/helpers.php +++ b/helpers.php @@ -24,7 +24,7 @@ function transactionInfo($transactionInfo = []) { $pluginName = 'altapay'; - $pluginVersion = '5.0.0'; + $pluginVersion = '5.0.1'; // Transaction info $transactionInfo['ecomPlatform'] = 'PrestaShop'; diff --git a/tests/integration-tests-1.6.1.x/cypress/e2e/PageObjects/objects.cy.js b/tests/integration-tests-1.6.1.x/cypress/e2e/PageObjects/objects.cy.js index 65c8f1ab..3a2d1811 100644 --- a/tests/integration-tests-1.6.1.x/cypress/e2e/PageObjects/objects.cy.js +++ b/tests/integration-tests-1.6.1.x/cypress/e2e/PageObjects/objects.cy.js @@ -1,5 +1,3 @@ -require('@cypress/xpath'); - class Order { @@ -39,8 +37,6 @@ class Order cy.contains(CC_TERMINAL_NAME).click({force: true}) cy.get('[id=creditCardNumberInput]').type('4111111111111111') - cy.get('#emonth').select('12') - cy.get('#eyear').select('2025') cy.get('#cvcInput').type('123') cy.get('#cardholderNameInput').type('testname') cy.get('#pensioCreditCardPaymentSubmitButton').click().wait(4000) diff --git a/tests/integration-tests-1.7.7.x/cypress/e2e/PageObjects/objects.cy.js b/tests/integration-tests-1.7.7.x/cypress/e2e/PageObjects/objects.cy.js index b5aa751f..bb44b8ae 100644 --- a/tests/integration-tests-1.7.7.x/cypress/e2e/PageObjects/objects.cy.js +++ b/tests/integration-tests-1.7.7.x/cypress/e2e/PageObjects/objects.cy.js @@ -1,5 +1,3 @@ -require('@cypress/xpath'); - class Order { @@ -47,8 +45,6 @@ class Order cy.get('.condition-label > .js-terms').click() cy.get('.ps-shown-by-js > .btn').click() cy.get('[id=creditCardNumberInput]').type('4111111111111111') - cy.get('#emonth').select('12') - cy.get('#eyear').select('2025') cy.get('#cvcInput').type('123') cy.get('#cardholderNameInput').type('testname') cy.get('#pensioCreditCardPaymentSubmitButton').click().wait(4000) @@ -389,8 +385,6 @@ class Order cy.get('#generate-payment-link-btn').click().wait(8000) cy.get('a[href^="https://testgateway.pensio.com/eCommerce/API/requestForm?pid="]').click() cy.get('[id=creditCardNumberInput]').type('4111111111111111') - cy.get('#emonth').select('12') - cy.get('#eyear').select('2025') cy.get('#cvcInput').type('123') cy.get('#cardholderNameInput').type('testname') cy.get('#pensioCreditCardPaymentSubmitButton').click().wait(4000) diff --git a/views/templates/front/payment_form_independent.tpl b/views/templates/front/payment_form_independent.tpl index edb4c48b..9501e9b3 100644 --- a/views/templates/front/payment_form_independent.tpl +++ b/views/templates/front/payment_form_independent.tpl @@ -747,7 +747,7 @@