From 03860227bbf49f03d3c885d73db0c184e6a754e0 Mon Sep 17 00:00:00 2001 From: kGablo Date: Thu, 18 Jul 2024 09:52:09 +0200 Subject: [PATCH 1/5] Refund scope update --- .version | 2 +- Api/TpayConfigInterface.php | 10 +++++----- CHANGELOG.MD | 4 ++++ Model/ApiFacade/Refund/RefundApiFacade.php | 12 +++++++---- .../ApiFacade/Refund/RefundCardOriginApi.php | 12 +++++------ Model/ApiFacade/Refund/RefundOriginApi.php | 12 +++++------ Model/TpayPayment.php | 3 ++- Provider/ConfigurationProvider.php | 20 +++++++++---------- view/base/web/css/tpay.css | 4 +--- view/base/web/css/tpaycards.css | 4 ++++ view/base/web/js/open_render_channels.js | 7 ++----- view/base/web/js/renderSavedCards.js | 2 +- view/base/web/js/render_channels.js | 8 ++------ view/base/web/js/tpayCards.js | 5 ++--- .../method-renderer/tpay-card-method.js | 2 +- .../method-renderer/tpay-generic-onsite.js | 2 +- .../payment/method-renderer/tpay-method.js | 2 +- .../web/template/payment/card-tpay-form.html | 4 ++-- .../web/template/payment/tpay-form.html | 4 ++-- .../template/payment/tpay-generic-onsite.html | 4 ++-- 20 files changed, 63 insertions(+), 60 deletions(-) diff --git a/.version b/.version index 815e68d..09843e3 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.0.8 +2.0.9 diff --git a/Api/TpayConfigInterface.php b/Api/TpayConfigInterface.php index 18f48ef..2d531ab 100644 --- a/Api/TpayConfigInterface.php +++ b/Api/TpayConfigInterface.php @@ -49,17 +49,17 @@ public function getInvoiceSendMail(): string; public function useSandboxMode(?int $storeId = null): bool; - public function getCardApiKey(): ?string; + public function getCardApiKey(?int $storeId = null): ?string; - public function getCardApiPassword(): ?string; + public function getCardApiPassword(?int $storeId = null): ?string; public function getCardSaveEnabled(): bool; - public function getRSAKey(): ?string; + public function getRSAKey(?int $storeId = null): ?string; - public function getHashType(): ?string; + public function getHashType(?int $storeId = null): ?string; - public function getVerificationCode(): ?string; + public function getVerificationCode(?int $storeId = null): ?string; public function isAllowSpecific(): bool; diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 49f9efc..776cfc9 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.9] +### Fixed +- Fixed refund scope + ## [2.0.8] ### Fixed - Fixed admin scope config diff --git a/Model/ApiFacade/Refund/RefundApiFacade.php b/Model/ApiFacade/Refund/RefundApiFacade.php index c0aded9..685dce5 100755 --- a/Model/ApiFacade/Refund/RefundApiFacade.php +++ b/Model/ApiFacade/Refund/RefundApiFacade.php @@ -23,12 +23,16 @@ class RefundApiFacade /** @var bool */ private $useOpenApi; + /** @var null|bool */ + private $storeId; + private $cache; - public function __construct(TpayConfigInterface $tpay, CacheInterface $cache) + public function __construct(TpayConfigInterface $tpay, CacheInterface $cache, ?int $storeId = null) { $this->tpay = $tpay; $this->cache = $cache; + $this->storeId = $storeId; } public function makeRefund(InfoInterface $payment, float $amount) @@ -37,7 +41,7 @@ public function makeRefund(InfoInterface $payment, float $amount) return $this->getCurrentApi()->makeRefund($payment, $amount); } if (!empty($payment->getAdditionalInformation('card_data'))) { - return (new RefundCardOriginApi($this->tpay))->makeCardRefund($payment, $amount); + return (new RefundCardOriginApi($this->tpay, $this->storeId))->makeCardRefund($payment, $amount); } return $this->originApi->makeRefund($payment, $amount); @@ -61,7 +65,7 @@ private function connectApi() private function createRefundOriginApiInstance(TpayConfigInterface $tpay) { try { - $this->originApi = new RefundOriginApi($tpay); + $this->originApi = new RefundOriginApi($tpay, $this->storeId); } catch (Exception $exception) { $this->originApi = null; } @@ -70,7 +74,7 @@ private function createRefundOriginApiInstance(TpayConfigInterface $tpay) private function createOpenApiInstance(TpayConfigInterface $tpay) { try { - $this->openApi = new OpenApi($tpay, $this->cache); + $this->openApi = new OpenApi($tpay, $this->cache, $this->storeId); $this->useOpenApi = true; } catch (Exception $exception) { $this->openApi = null; diff --git a/Model/ApiFacade/Refund/RefundCardOriginApi.php b/Model/ApiFacade/Refund/RefundCardOriginApi.php index c7d28c9..6e7537e 100755 --- a/Model/ApiFacade/Refund/RefundCardOriginApi.php +++ b/Model/ApiFacade/Refund/RefundCardOriginApi.php @@ -9,14 +9,14 @@ class RefundCardOriginApi extends CardRefunds { - public function __construct(TpayConfigInterface $tpay) + public function __construct(TpayConfigInterface $tpay, ?int $storeId = null) { Util::$loggingEnabled = false; - $this->cardApiKey = $tpay->getCardApiKey(); - $this->cardApiPass = $tpay->getCardApiPassword(); - $this->cardVerificationCode = $tpay->getVerificationCode(); - $this->cardKeyRSA = $tpay->getRSAKey(); - $this->cardHashAlg = $tpay->getHashType(); + $this->cardApiKey = $tpay->getCardApiKey($storeId); + $this->cardApiPass = $tpay->getCardApiPassword($storeId); + $this->cardVerificationCode = $tpay->getVerificationCode($storeId); + $this->cardKeyRSA = $tpay->getRSAKey($storeId); + $this->cardHashAlg = $tpay->getHashType($storeId); parent::__construct(); } diff --git a/Model/ApiFacade/Refund/RefundOriginApi.php b/Model/ApiFacade/Refund/RefundOriginApi.php index ec50d6d..6f78f7e 100755 --- a/Model/ApiFacade/Refund/RefundOriginApi.php +++ b/Model/ApiFacade/Refund/RefundOriginApi.php @@ -10,14 +10,14 @@ class RefundOriginApi extends BasicRefunds { - public function __construct(TpayConfigInterface $tpay) + public function __construct(TpayConfigInterface $tpay, ?int $storeId = null) { - $this->trApiKey = $tpay->getApiPassword(); - $this->trApiPass = $tpay->getApiKey(); - $this->merchantId = $tpay->getMerchantId(); - $this->merchantSecret = $tpay->getSecurityCode(); + $this->trApiKey = $tpay->getApiPassword($storeId); + $this->trApiPass = $tpay->getApiKey($storeId); + $this->merchantId = $tpay->getMerchantId($storeId); + $this->merchantSecret = $tpay->getSecurityCode($storeId); parent::__construct(); - if ($tpay->useSandboxMode()) { + if ($tpay->useSandboxMode($storeId)) { $this->apiURL = 'https://secure.sandbox.tpay.com/api/gw/'; } } diff --git a/Model/TpayPayment.php b/Model/TpayPayment.php index b5c7523..9685923 100755 --- a/Model/TpayPayment.php +++ b/Model/TpayPayment.php @@ -255,7 +255,8 @@ public function assignData(DataObject $data) */ public function refund(InfoInterface $payment, $amount) { - $refundService = new RefundApiFacade($this->configurationProvider, $this->cache); + $storeId = $payment->getOrder()->getStoreId() ? (int) $payment->getOrder()->getStoreId() : null; + $refundService = new RefundApiFacade($this->configurationProvider, $this->cache, $storeId); $refundResult = $refundService->makeRefund($payment, (float) $amount); try { diff --git a/Provider/ConfigurationProvider.php b/Provider/ConfigurationProvider.php index 74ff3e8..fbb0f7d 100755 --- a/Provider/ConfigurationProvider.php +++ b/Provider/ConfigurationProvider.php @@ -61,9 +61,9 @@ public function getApiKey(?int $storeId = null): ?string return $this->getConfigData('originapi_settings/api_key_tpay', $storeId); } - public function getCardApiKey(): ?string + public function getCardApiKey(?int $storeId = null): ?string { - return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_key_tpay'); + return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_key_tpay', $storeId); } public function getApiPassword(?int $storeId = null): ?string @@ -71,9 +71,9 @@ public function getApiPassword(?int $storeId = null): ?string return $this->getConfigData('originapi_settings/api_password', $storeId); } - public function getCardApiPassword(): ?string + public function getCardApiPassword(?int $storeId = null): ?string { - return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_password'); + return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_password', $storeId); } public function getInvoiceSendMail(): string @@ -174,19 +174,19 @@ public function getCardSaveEnabled(): bool return (bool) $this->getConfigData('cardpayment_settings/card_save_enabled'); } - public function getRSAKey(): ?string + public function getRSAKey(?int $storeId = null): ?string { - return $this->getConfigData('cardpayment_settings/rsa_key'); + return $this->getConfigData('cardpayment_settings/rsa_key', $storeId); } - public function getHashType(): ?string + public function getHashType(?int $storeId = null): ?string { - return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/hash_type'); + return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/hash_type', $storeId); } - public function getVerificationCode(): ?string + public function getVerificationCode(?int $storeId = null): ?string { - return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/verification_code'); + return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/verification_code', $storeId); } public function isAllowSpecific(): bool diff --git a/view/base/web/css/tpay.css b/view/base/web/css/tpay.css index b3757e7..3c18b66 100644 --- a/view/base/web/css/tpay.css +++ b/view/base/web/css/tpay.css @@ -594,10 +594,8 @@ form select.wrong .TpayRegulations input { display: none; - margin: 0; - position: static; } .tpay-regulations-offset { max-width: 630px; -} \ No newline at end of file +} diff --git a/view/base/web/css/tpaycards.css b/view/base/web/css/tpaycards.css index 8c35d9b..1526d34 100644 --- a/view/base/web/css/tpaycards.css +++ b/view/base/web/css/tpaycards.css @@ -591,6 +591,10 @@ form select.wrong flex: 1; } +.TpayRegulations input { + display: none; +} + @media (min-width: 956px) { #card_payment { flex-direction: row; diff --git a/view/base/web/js/open_render_channels.js b/view/base/web/js/open_render_channels.js index 6101528..589e1a1 100644 --- a/view/base/web/js/open_render_channels.js +++ b/view/base/web/js/open_render_channels.js @@ -7,8 +7,7 @@ */ require(['jquery', 'mage/translate'], function ($, $t) { - var payButton = $('#tpaycom_magento2basic_submit'), - tos = $('#accept_tos'); + var payButton = $('#tpaycom_magento2basic_submit'); function getBankTile(groupId, groupName, logoSrc) { return ' - \ No newline at end of file + diff --git a/view/frontend/web/template/payment/tpay-form.html b/view/frontend/web/template/payment/tpay-form.html index 6c404f3..f4079ec 100644 --- a/view/frontend/web/template/payment/tpay-form.html +++ b/view/frontend/web/template/payment/tpay-form.html @@ -64,7 +64,7 @@
- +
- \ No newline at end of file + diff --git a/view/frontend/web/template/payment/tpay-generic-onsite.html b/view/frontend/web/template/payment/tpay-generic-onsite.html index 4e18318..588ed23 100644 --- a/view/frontend/web/template/payment/tpay-generic-onsite.html +++ b/view/frontend/web/template/payment/tpay-generic-onsite.html @@ -16,7 +16,7 @@
- +
- \ No newline at end of file + From 15da06672b4c7b9b952ad85fdb76fa038006d978 Mon Sep 17 00:00:00 2001 From: kGablo Date: Thu, 18 Jul 2024 13:21:17 +0200 Subject: [PATCH 2/5] Notification scope update --- Controller/Tpay/Notification.php | 89 +++++++++----------------------- 1 file changed, 24 insertions(+), 65 deletions(-) diff --git a/Controller/Tpay/Notification.php b/Controller/Tpay/Notification.php index b6cc4b8..55b812e 100644 --- a/Controller/Tpay/Notification.php +++ b/Controller/Tpay/Notification.php @@ -11,8 +11,6 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\App\ResponseInterface; use Magento\Sales\Model\Order; -use Magento\Store\Api\Data\StoreInterface; -use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Service\TpayService; @@ -35,9 +33,6 @@ class Notification implements CsrfAwareActionInterface /** @var TpayTokensService */ private $tokensService; - /** @var StoreManagerInterface */ - private $storeManager; - /** @var ResponseInterface */ private $response; @@ -46,55 +41,27 @@ public function __construct( TpayConfigInterface $tpayConfig, TpayService $tpayService, TpayTokensService $tokensService, - StoreManagerInterface $storeManager, ResponseInterface $response ) { $this->tpay = $tpayModel; $this->tpayConfig = $tpayConfig; $this->tpayService = $tpayService; $this->tokensService = $tokensService; - $this->storeManager = $storeManager; $this->response = $response; Util::$loggingEnabled = false; } public function execute(): ?Response { - if (isset($_POST['card'])) { - return $this->executeCardNotification(); - } - - return $this->executeNotification(); - } - - public function executeNotification(): ?Response - { - $response = null; - - foreach ($this->storeManager->getStores() as $store) { - $response = $this->extractNotification($store); - - if (Response::STATUS_CODE_200 === $response->getStatusCode()) { - break; - } - } - - return $response; - } - - public function executeCardNotification(): ?Response - { - $response = null; - - foreach ($this->storeManager->getStores() as $store) { - $response = $this->extractCardNotification($store); + $orderId = base64_decode($_POST['tr_crc']); + $order = $this->tpayService->getOrderById($orderId); + $storeId = $order->getStoreId() ? (int)$order->getStoreId() : null; - if (Response::STATUS_CODE_200 === $response->getStatusCode()) { - break; - } + if (isset($_POST['card'])) { + return $this->extractCardNotification($storeId); } - return $response; + return $this->extractNotification($storeId); } public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException @@ -160,10 +127,8 @@ private function saveOriginCard(array $notification, string $orderId) } } - private function extractNotification(StoreInterface $store): Response + private function extractNotification(?int $storeId = null): Response { - $storeId = (int) $store->getStoreId(); - try { $notification = (new JWSVerifiedPaymentNotification( $this->tpayConfig->getSecurityCode($storeId), @@ -184,25 +149,14 @@ private function extractNotification(StoreInterface $store): Response return $this->response->setStatusCode(Response::STATUS_CODE_200)->setContent('TRUE'); } catch (Exception $e) { - Util::log( - 'Notification exception', - sprintf( - '%s in file %s line: %d \n\n %s', - $e->getMessage(), - $e->getFile(), - $e->getLine(), - $e->getTraceAsString() - ) - ); + $this->handleException($e); return $this->response->setStatusCode(Response::STATUS_CODE_400)->setContent('FALSE'); } } - private function extractCardNotification(StoreInterface $store): ?Response + private function extractCardNotification(?int $storeId = null): ?Response { - $storeId = (int) $store->getStoreId(); - try { $notification = (new OriginJWSVerifiedPaymentNotification( $this->tpayConfig->getSecurityCode($storeId), @@ -216,18 +170,23 @@ private function extractCardNotification(StoreInterface $store): ?Response return $this->response->setStatusCode(Response::STATUS_CODE_200)->setContent('TRUE'); } catch (Exception $e) { - Util::log( - 'Notification exception', - sprintf( - '%s in file %s line: %d \n\n %s', - $e->getMessage(), - $e->getFile(), - $e->getLine(), - $e->getTraceAsString() - ) - ); + $this->handleException($e); return $this->response->setStatusCode(Response::STATUS_CODE_400)->setContent('FALSE'); } } + + private function handleException(Exception $e) + { + Util::log( + 'Notification exception', + sprintf( + '%s in file %s line: %d \n\n %s', + $e->getMessage(), + $e->getFile(), + $e->getLine(), + $e->getTraceAsString() + ) + ); + } } From 02666da98558bb0a68d2796952cafd386ee96c33 Mon Sep 17 00:00:00 2001 From: kGablo Date: Thu, 18 Jul 2024 13:23:33 +0200 Subject: [PATCH 3/5] Notification scope update --- Controller/Tpay/Notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Tpay/Notification.php b/Controller/Tpay/Notification.php index 55b812e..9c048fe 100644 --- a/Controller/Tpay/Notification.php +++ b/Controller/Tpay/Notification.php @@ -55,7 +55,7 @@ public function execute(): ?Response { $orderId = base64_decode($_POST['tr_crc']); $order = $this->tpayService->getOrderById($orderId); - $storeId = $order->getStoreId() ? (int)$order->getStoreId() : null; + $storeId = $order->getStoreId() ? (int) $order->getStoreId() : null; if (isset($_POST['card'])) { return $this->extractCardNotification($storeId); From 2cbce65e72b7b8395e8dfbc5ba23dd74d9220eb1 Mon Sep 17 00:00:00 2001 From: kGablo Date: Thu, 18 Jul 2024 14:26:15 +0200 Subject: [PATCH 4/5] Notification scope update --- Controller/Tpay/Notification.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Controller/Tpay/Notification.php b/Controller/Tpay/Notification.php index 9c048fe..673995b 100644 --- a/Controller/Tpay/Notification.php +++ b/Controller/Tpay/Notification.php @@ -53,15 +53,15 @@ public function __construct( public function execute(): ?Response { - $orderId = base64_decode($_POST['tr_crc']); - $order = $this->tpayService->getOrderById($orderId); - $storeId = $order->getStoreId() ? (int) $order->getStoreId() : null; - if (isset($_POST['card'])) { - return $this->extractCardNotification($storeId); + $orderId = base64_decode($_POST['order_id']); + + return $this->extractCardNotification($this->getOrderStore($orderId)); } - return $this->extractNotification($storeId); + $orderId = base64_decode($_POST['tr_crc']); + + return $this->extractNotification($this->getOrderStore($orderId)); } public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException @@ -189,4 +189,11 @@ private function handleException(Exception $e) ) ); } + + private function getOrderStore(string $orderId): ?int + { + $order = $this->tpayService->getOrderById($orderId); + + return $order->getStoreId() ? (int) $order->getStoreId() : null; + } } From 465569bdfb9846cade04bab8e3e876e1a3bb9c00 Mon Sep 17 00:00:00 2001 From: kGablo Date: Fri, 19 Jul 2024 13:38:04 +0200 Subject: [PATCH 5/5] Add tax id --- Model/ApiFacade/OpenApi.php | 4 ++++ Model/ApiFacade/Transaction/TransactionApiFacade.php | 1 + Model/TpayPayment.php | 1 + 3 files changed, 6 insertions(+) diff --git a/Model/ApiFacade/OpenApi.php b/Model/ApiFacade/OpenApi.php index 8f380a6..87dec06 100755 --- a/Model/ApiFacade/OpenApi.php +++ b/Model/ApiFacade/OpenApi.php @@ -164,6 +164,10 @@ private function handleDataStructure(array $data): array $paymentData['pay']['channelId'] = $data['channel']; } + if ($data['tax_id']) { + $paymentData['payer']['taxId'] = $data['tax_id']; + } + return $paymentData; } diff --git a/Model/ApiFacade/Transaction/TransactionApiFacade.php b/Model/ApiFacade/Transaction/TransactionApiFacade.php index 130631b..77d378c 100755 --- a/Model/ApiFacade/Transaction/TransactionApiFacade.php +++ b/Model/ApiFacade/Transaction/TransactionApiFacade.php @@ -118,6 +118,7 @@ public function originApiFieldCorrect(array $data): array unset($data['channel']); unset($data['currency']); unset($data['language']); + unset($data['tax_id']); } return $data; diff --git a/Model/TpayPayment.php b/Model/TpayPayment.php index 9685923..f1bc51d 100755 --- a/Model/TpayPayment.php +++ b/Model/TpayPayment.php @@ -198,6 +198,7 @@ public function getTpayFormData(?string $orderId = null): array 'city' => $this->escaper->escapeHtml($order->getBillingAddress()->getData('city')), 'zip' => $this->escaper->escapeHtml($order->getBillingAddress()->getData('postcode')), 'country' => $this->escaper->escapeHtml($order->getBillingAddress()->getData('country_id')), + 'tax_id' => $this->escaper->escapeHtml($order->getBillingAddress()->getData('vat_id')), 'return_error_url' => $this->urlBuilder->getUrl('magento2basic/tpay/error'), 'result_url' => $this->urlBuilder->getUrl('magento2basic/tpay/notification'), 'return_url' => $this->urlBuilder->getUrl('magento2basic/tpay/success'),