From 5817bfe6434f4c8bc2ae6aa8f5eb9bb143bd53c8 Mon Sep 17 00:00:00 2001 From: Laurent Clouet Date: Mon, 30 Sep 2024 16:10:50 +0200 Subject: [PATCH 1/7] CHECMAG2003-252: Add support of multi-region support for api call --- Model/Service/ApiHandlerService.php | 14 +++++++++++--- composer.json | 2 +- etc/adminhtml/system.xml | 6 ++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Model/Service/ApiHandlerService.php b/Model/Service/ApiHandlerService.php index bd532878..a73c2acc 100644 --- a/Model/Service/ApiHandlerService.php +++ b/Model/Service/ApiHandlerService.php @@ -37,6 +37,7 @@ use CheckoutCom\Magento2\Gateway\Config\Config; use CheckoutCom\Magento2\Helper\Logger; use CheckoutCom\Magento2\Helper\Utilities; +use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigRegion; use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigService; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\ProductMetadataInterface; @@ -172,6 +173,8 @@ public function init( string $secretKey = null, string $publicKey = null ): ApiHandlerService { + $region = $this->config->getValue('region', null, $storeCode, $scope); + if (!$secretKey) { $secretKey = $this->config->getValue('secret_key', null, $storeCode, $scope); } @@ -190,11 +193,16 @@ public function init( $api = $api->staticKeys(); } - $this->checkoutApi = $api + $sdkBuilder = $api ->publicKey($publicKey) ->secretKey($secretKey) - ->environment($environment) - ->build(); + ->environment($environment); + + if ($region != ConfigRegion::REGION_GLOBAL) { // do not set subdomain when global region is used + $sdkBuilder->environmentSubdomain($region); + } + + $this->checkoutApi = $sdkBuilder->build(); return $this; } diff --git a/composer.json b/composer.json index 0b8d91fd..961bbb70 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "checkoutcom/magento2", "description": "Checkout.com Payment Gateway for Magento 2", "require": { - "checkout/checkout-sdk-php": "3.2.0", + "checkout/checkout-sdk-php": "3.2.4", "php": "~7.4.0||~8.1.0||~8.2.0", "magento/framework": ">=100.0.1" }, diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 9c2bb46e..2be5d8bf 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -176,6 +176,12 @@ + + + CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigRegion + settings/checkoutcom_configuration/region + required-entry + CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigService From 6b519a1324639a767c38694418679c8b1b14a4e9 Mon Sep 17 00:00:00 2001 From: Benjamin Houillon Date: Thu, 10 Oct 2024 09:38:06 +0200 Subject: [PATCH 2/7] CHECMAG2003-256: fix success result on REST API --- Model/Api/V3.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Model/Api/V3.php b/Model/Api/V3.php index f4b255a3..adab3e7a 100644 --- a/Model/Api/V3.php +++ b/Model/Api/V3.php @@ -336,8 +336,9 @@ private function processPayment(): array // Get the payment $response = $this->getPaymentResponse($amount, $currency, $reference); + $isValidResponse = $this->api->isValidResponse($response); - if ($this->api->isValidResponse($response)) { + if ($isValidResponse) { // Process the payment response $is3ds = property_exists($response, '_links') && isset($response->_links['redirect']) @@ -357,7 +358,7 @@ private function processPayment(): array } // Update the result - $this->result['success'] = $response->isSuccessful(); + $this->result['success'] = $isValidResponse; } else { // Payment failed if (isset($response->response_code)) { From b577785506c3068f9804e47d68724c0c947349df Mon Sep 17 00:00:00 2001 From: Benjamin Houillon Date: Fri, 18 Oct 2024 16:56:10 +0200 Subject: [PATCH 3/7] CHECMAG2003-252: fix missing source model --- Model/Config/Backend/Source/ConfigRegion.php | 47 ++++++++++++++++++++ Model/Service/ApiHandlerService.php | 8 ++-- 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 Model/Config/Backend/Source/ConfigRegion.php diff --git a/Model/Config/Backend/Source/ConfigRegion.php b/Model/Config/Backend/Source/ConfigRegion.php new file mode 100644 index 00000000..262c3999 --- /dev/null +++ b/Model/Config/Backend/Source/ConfigRegion.php @@ -0,0 +1,47 @@ + + * @copyright 2010-present Checkout.com + * @license https://opensource.org/licenses/mit-license.html MIT License + * @link https://docs.checkout.com/ + */ + +declare(strict_types=1); + +namespace CheckoutCom\Magento2\Model\Config\Backend\Source; + +use Magento\Framework\Data\OptionSourceInterface; + +class ConfigRegion implements OptionSourceInterface +{ + public const REGION_GLOBAL = ''; + public const REGION_KSA = 'ksa'; + + /** + * Options getter + * + * @return string[][] + */ + public function toOptionArray(): array + { + return [ + [ + 'value' => '', + 'label' => __('--') + ], + [ + 'value' => self::REGION_KSA, + 'label' => __('KSA') + ] + ]; + } +} diff --git a/Model/Service/ApiHandlerService.php b/Model/Service/ApiHandlerService.php index a73c2acc..34b0fbcc 100644 --- a/Model/Service/ApiHandlerService.php +++ b/Model/Service/ApiHandlerService.php @@ -184,7 +184,7 @@ public function init( } $service = $this->scopeConfig->getValue(ConfigService::SERVICE_CONFIG_PATH, $scope, $storeCode); - $environment = $this->config->getEnvironment($storeCode, $scope); + $environment = $this->config->getEnvironment((string)$storeCode, $scope); $api = CheckoutSdk::builder(); if ($service === ConfigService::SERVICE_ABC) { @@ -197,8 +197,8 @@ public function init( ->publicKey($publicKey) ->secretKey($secretKey) ->environment($environment); - - if ($region != ConfigRegion::REGION_GLOBAL) { // do not set subdomain when global region is used + + if ($region !== ConfigRegion::REGION_GLOBAL) { // do not set subdomain when global region is used $sdkBuilder->environmentSubdomain($region); } @@ -216,7 +216,7 @@ public function initAbcForRefund( $publicKey = $this->config->getValue('abc_refund_public_key', null, $storeCode, $scope); $api = CheckoutSdk::builder(); - $environment = $this->config->getEnvironment($storeCode, $scope); + $environment = $this->config->getEnvironment((string)$storeCode, $scope); $this->checkoutApi = $api ->previous()->staticKeys() From e9f45777ee29a8d9e79c624ed6caa7fd0916539c Mon Sep 17 00:00:00 2001 From: Benjamin Houillon Date: Mon, 21 Oct 2024 10:09:36 +0200 Subject: [PATCH 4/7] CHECMAG2003-252: fix global region config value --- Model/Config/Backend/Source/ConfigRegion.php | 4 ++-- Model/Service/ApiHandlerService.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Model/Config/Backend/Source/ConfigRegion.php b/Model/Config/Backend/Source/ConfigRegion.php index 262c3999..84653c13 100644 --- a/Model/Config/Backend/Source/ConfigRegion.php +++ b/Model/Config/Backend/Source/ConfigRegion.php @@ -23,7 +23,7 @@ class ConfigRegion implements OptionSourceInterface { - public const REGION_GLOBAL = ''; + public const REGION_GLOBAL = 'global'; public const REGION_KSA = 'ksa'; /** @@ -35,7 +35,7 @@ public function toOptionArray(): array { return [ [ - 'value' => '', + 'value' => self::REGION_GLOBAL, 'label' => __('--') ], [ diff --git a/Model/Service/ApiHandlerService.php b/Model/Service/ApiHandlerService.php index 34b0fbcc..03b62a6c 100644 --- a/Model/Service/ApiHandlerService.php +++ b/Model/Service/ApiHandlerService.php @@ -198,7 +198,8 @@ public function init( ->secretKey($secretKey) ->environment($environment); - if ($region !== ConfigRegion::REGION_GLOBAL) { // do not set subdomain when global region is used + // Do not set subdomain when global region is used + if ($region !== ConfigRegion::REGION_GLOBAL) { $sdkBuilder->environmentSubdomain($region); } From 3271b45ff36a12c376da31416e61aad115c30fee Mon Sep 17 00:00:00 2001 From: Benjamin Houillon Date: Mon, 21 Oct 2024 10:28:20 +0200 Subject: [PATCH 5/7] CHECMAG2003-252: add region default configuration --- etc/config.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/config.xml b/etc/config.xml index 65f0b709..7b02ff57 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -27,6 +27,7 @@ 0 1 + global ABC From 44d69570cdf85061683307d8d344060c2d37d56d Mon Sep 17 00:00:00 2001 From: Benjamin Houillon Date: Tue, 22 Oct 2024 14:31:10 +0200 Subject: [PATCH 6/7] CHECMAG2003-252: Add region configuration field translation --- i18n/en_GB.csv | 2 ++ i18n/en_US.csv | 2 ++ 2 files changed, 4 insertions(+) diff --git a/i18n/en_GB.csv b/i18n/en_GB.csv index 06f0b4da..bd713ff6 100644 --- a/i18n/en_GB.csv +++ b/i18n/en_GB.csv @@ -1,3 +1,4 @@ +"--","Others" " for an amount of %1. Action ID: %2. Event ID: %3. Payment ID: %4. Error: %5 %6"," for an amount of %1. Action ID: %2. Event ID: %3. Payment ID: %4. Error: %5 %6" "3DS authorization code","3DS authorization code" "3DS has expired or authentication failed, please try again","3DS has expired or authentication failed, please try again" @@ -63,6 +64,7 @@ "Invalid request. No session ID found.","Invalid request. No session ID found." "It looks like this transaction has been blocked due to account holder action, please contact your bank or use another card or payment method","It looks like this transaction has been blocked due to account holder action, please contact your bank or use another card or payment method" "It looks like your card is invalid or blocked, please try with another card","It looks like your card is invalid or blocked, please try with another card" +"KSA","KSA" "Learn More","Learn More" "Match Not Capable","Match Not Capable" "Mismatched Address (fraud check)","Mismatched Address (fraud check)" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 06f0b4da..bd713ff6 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -1,3 +1,4 @@ +"--","Others" " for an amount of %1. Action ID: %2. Event ID: %3. Payment ID: %4. Error: %5 %6"," for an amount of %1. Action ID: %2. Event ID: %3. Payment ID: %4. Error: %5 %6" "3DS authorization code","3DS authorization code" "3DS has expired or authentication failed, please try again","3DS has expired or authentication failed, please try again" @@ -63,6 +64,7 @@ "Invalid request. No session ID found.","Invalid request. No session ID found." "It looks like this transaction has been blocked due to account holder action, please contact your bank or use another card or payment method","It looks like this transaction has been blocked due to account holder action, please contact your bank or use another card or payment method" "It looks like your card is invalid or blocked, please try with another card","It looks like your card is invalid or blocked, please try with another card" +"KSA","KSA" "Learn More","Learn More" "Match Not Capable","Match Not Capable" "Mismatched Address (fraud check)","Mismatched Address (fraud check)" From ce1fa3c39370917c24a7717720591683b3a5e116 Mon Sep 17 00:00:00 2001 From: Benjamin HOUILLON Date: Tue, 22 Oct 2024 12:44:40 +0000 Subject: [PATCH 7/7] Bump composer.json version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c0a3bff2..bf34db5c 100755 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "magento/framework": ">=100.0.1" }, "type": "magento2-module", - "version": "6.3.2", + "version": "6.4.0", "autoload": { "files": [ "registration.php"