From b14e515d2e091524612d46eac64b6abee7d457eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Mon, 2 Mar 2026 14:09:00 +0100 Subject: [PATCH 1/6] New SDK notifications --- .version | 2 +- .../NotificationProcessorFactoryInterface.php | 7 +- .../NotificationProcessorInterface.php | 2 +- CHANGELOG.MD | 6 ++ Notification/NotificationProcessor.php | 87 ++++++++++++++----- .../BlikAliasNotificationProcessor.php | 30 ++++--- .../Strategy/CardNotificationProcessor.php | 12 +-- .../Strategy/DefaultNotificationProcessor.php | 75 ++++++++-------- .../Factory/NotificationProcessorFactory.php | 19 ++-- composer.json | 2 +- 10 files changed, 150 insertions(+), 92 deletions(-) diff --git a/.version b/.version index e70b452..6a6a3d8 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.6.0 +2.6.1 diff --git a/Api/Notification/Strategy/NotificationProcessorFactoryInterface.php b/Api/Notification/Strategy/NotificationProcessorFactoryInterface.php index 2cf017b..decef3b 100644 --- a/Api/Notification/Strategy/NotificationProcessorFactoryInterface.php +++ b/Api/Notification/Strategy/NotificationProcessorFactoryInterface.php @@ -2,7 +2,12 @@ namespace Tpay\Magento2\Api\Notification\Strategy; +use Tpay\OpenApi\Model\Objects\Objects; + interface NotificationProcessorFactoryInterface { - public function create(array $data): NotificationProcessorInterface; + /** + * @param array|Objects $notification + */ + public function create($notification): NotificationProcessorInterface; } diff --git a/Api/Notification/Strategy/NotificationProcessorInterface.php b/Api/Notification/Strategy/NotificationProcessorInterface.php index 09c9818..4d2efab 100644 --- a/Api/Notification/Strategy/NotificationProcessorInterface.php +++ b/Api/Notification/Strategy/NotificationProcessorInterface.php @@ -4,5 +4,5 @@ interface NotificationProcessorInterface { - public function process(?int $storeId); + public function process($notification, ?int $storeId = null); } diff --git a/CHANGELOG.MD b/CHANGELOG.MD index ec57203..a1059af 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -5,6 +5,12 @@ 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.6.1 + +### Changed + +- New SDK notifications support + ## 2.6.0 ### Changed diff --git a/Notification/NotificationProcessor.php b/Notification/NotificationProcessor.php index 42a2ba4..a2a0743 100644 --- a/Notification/NotificationProcessor.php +++ b/Notification/NotificationProcessor.php @@ -2,59 +2,104 @@ namespace Tpay\Magento2\Notification; +use _PHPStan_5adafcbb8\Psr\Http\Message\RequestInterface; use Magento\Framework\App\RequestInterface; +use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorFactoryInterface; -use Tpay\Magento2\Notification\Strategy\BlikAliasNotificationProcessor; +use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Service\TpayService; +use Tpay\OpenApi\Model\Objects\NotificationBody\BasicPayment; +use Tpay\OpenApi\Utilities\Cache; +use Tpay\OpenApi\Utilities\CacheCertificateProvider; +use Tpay\OpenApi\Webhook\JWSVerifiedPaymentNotification as OpenApiWebhook; +use Tpay\OriginApi\Webhook\JWSVerifiedPaymentNotification as OriginApiWebhook; class NotificationProcessor { + /** @var RequestInterface */ + private $request; + /** @var NotificationProcessorFactoryInterface */ protected $factory; /** @var TpayService */ protected $tpayService; - /** @var RequestInterface */ - private $request; + /** @var TpayConfigInterface */ + private $config; - public function __construct(NotificationProcessorFactoryInterface $factory, TpayService $tpayService, RequestInterface $request) - { + /** @var StoreManagerInterface */ + private $storeManager; + + public function __construct( + RequestInterface $request, + NotificationProcessorFactoryInterface $factory, + TpayService $tpayService, + TpayConfigInterface $config, + StoreManagerInterface $storeManager + ) { + $this->request = $request; $this->factory = $factory; $this->tpayService = $tpayService; - $this->request = $request; + $this->config = $config; + $this->storeManager = $storeManager; } public function process() { - $strategy = $this->factory->create($this->request->getPost()->toArray()); - $storeId = null; - - if (!$strategy instanceof BlikAliasNotificationProcessor) { - $orderId = $this->getOrderId(); - if ($orderId) { - $storeId = $this->getOrderStore($orderId); - } + $defaultStoreId = $this->storeManager->getDefaultStoreView()->getId(); + $webhook = $this->createWebhook($defaultStoreId); + + $notification = $webhook->getNotification(); + $storeId = $this->resolveStoreId($notification, $defaultStoreId); + + if ($storeId !== $defaultStoreId) { + $webhook = $this->createWebhook($storeId); + $notification = $webhook->getNotification(); } + $strategy = $this->factory->create($notification); + $strategy->process($storeId); } - private function getOrderId(): ?string + private function resolveStoreId($notification, int $defaultStoreId): ?int { - $value = $this->request->getPost('order_id') ?? $this->request->getPost('tr_crc'); + if ($notification instanceof BasicPayment) { + $value = $notification->tr_crc->getValue(); + } elseif (is_array($notification)) { + $value = $notification['order_id'] ?? $notification['tr_crc'] ?? null; + } else { + return null; + } - if (null === $value) { + if (!$value) { return null; } - return base64_decode($value); + $orderId = base64_decode($value); + $order = $this->tpayService->getOrderById($orderId); + + return $order->getStoreId() ? (int) $order->getStoreId() : $defaultStoreId; } - private function getOrderStore(string $orderId): ?int + /** + * @return OriginApiWebhook|OpenApiWebhook + */ + private function createWebhook(?int $storeId) { - $order = $this->tpayService->getOrderById($orderId); + if (null !== $this->request->getPost('card')) { + return new OriginApiWebhook( + $this->config->getApiPassword($storeId), + !$this->config->useSandboxMode($storeId) + ); + } - return $order->getStoreId() ? (int) $order->getStoreId() : null; + $certificateProvider = new CacheCertificateProvider(new Cache()); + return new OpenApiWebhook( + $certificateProvider, + $this->config->getSecurityCode($storeId), + !$this->config->useSandboxMode($storeId) + ); } } diff --git a/Notification/Strategy/BlikAliasNotificationProcessor.php b/Notification/Strategy/BlikAliasNotificationProcessor.php index 3f460b1..5bb3dec 100644 --- a/Notification/Strategy/BlikAliasNotificationProcessor.php +++ b/Notification/Strategy/BlikAliasNotificationProcessor.php @@ -4,35 +4,39 @@ namespace Tpay\Magento2\Notification\Strategy; -use Magento\Framework\App\RequestInterface; use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorInterface; use Tpay\Magento2\Service\TpayAliasServiceInterface; +use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasRegister; +use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasUnregister; class BlikAliasNotificationProcessor implements NotificationProcessorInterface { /** @var TpayAliasServiceInterface */ protected $aliasService; - /** @var RequestInterface */ - private $request; - - public function __construct(TpayAliasServiceInterface $aliasService, RequestInterface $request) + public function __construct(TpayAliasServiceInterface $aliasService) { $this->aliasService = $aliasService; - $this->request = $request; } - public function process(?int $storeId = null) + public function process($notification, ?int $storeId = null) { - $response = $this->request->getPost()->toArray(); - $userId = (int) explode('-', $response['msg_value']['value'])[1]; + if ($notification instanceof BlikAliasRegister) { + $alias = (string) $notification->value->getValue(); + $userId = (int) explode('-', $alias)[1]; - if ('ALIAS_REGISTER' === $response['event']) { - $this->aliasService->saveCustomerAlias($userId, $response['msg_value']['value']); + $this->aliasService->saveCustomerAlias($userId, $alias); + return; } - if ('ALIAS_UNREGISTER' === $response['event']) { - $this->aliasService->removeCustomerAlias($userId, $response['msg_value']['value']); + if ($notification instanceof BlikAliasUnregister) { + $alias = (string) $notification->value->getValue(); + $userId = (int) explode('-', $alias)[1]; + + $this->aliasService->removeCustomerAlias($userId, $alias); + return; } + + throw new \RuntimeException('Unsupported BLIK notification type'); } } diff --git a/Notification/Strategy/CardNotificationProcessor.php b/Notification/Strategy/CardNotificationProcessor.php index 915aed8..5bde8f0 100644 --- a/Notification/Strategy/CardNotificationProcessor.php +++ b/Notification/Strategy/CardNotificationProcessor.php @@ -7,7 +7,6 @@ use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Service\TpayService; use Tpay\Magento2\Service\TpayTokensService; -use Tpay\OriginApi\Webhook\JWSVerifiedPaymentNotification; class CardNotificationProcessor implements NotificationProcessorInterface { @@ -27,21 +26,16 @@ public function __construct( TpayConfigInterface $tpayConfig, TpayService $tpayService, TpayTokensService $tokensService, - TpayInterface $tpayModel + TpayInterface $tpay ) { $this->tpayConfig = $tpayConfig; $this->tpayService = $tpayService; $this->tokensService = $tokensService; - $this->tpay = $tpayModel; + $this->tpay = $tpay; } - public function process(?int $storeId) + public function process($notification, ?int $storeId = null) { - $notification = (new JWSVerifiedPaymentNotification( - $this->tpayConfig->getSecurityCode($storeId), - !$this->tpayConfig->useSandboxMode($storeId) - ))->getNotification(); - $orderId = base64_decode($notification['order_id']); $order = $this->tpayService->getOrderById($orderId); diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index 5b7eb4a..c265afb 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -3,17 +3,13 @@ namespace Tpay\Magento2\Notification\Strategy; use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorInterface; -use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Service\TpayService; use Tpay\Magento2\Service\TpayTokensService; -use Tpay\OpenApi\Webhook\JWSVerifiedPaymentNotificationFactory; +use Tpay\OpenApi\Model\Objects\NotificationBody\BasicPayment; class DefaultNotificationProcessor implements NotificationProcessorInterface { - /** @var TpayConfigInterface */ - protected $tpayConfig; - /** @var TpayService */ protected $tpayService; @@ -23,54 +19,65 @@ class DefaultNotificationProcessor implements NotificationProcessorInterface /** @var TpayInterface */ protected $tpay; - /** @var JWSVerifiedPaymentNotificationFactory */ - private $notificationFactory; - public function __construct( - TpayConfigInterface $tpayConfig, TpayService $tpayService, TpayTokensService $tokensService, - TpayInterface $tpayModel, - JWSVerifiedPaymentNotificationFactory $notificationFactory + TpayInterface $tpay ) { - $this->tpayConfig = $tpayConfig; $this->tpayService = $tpayService; $this->tokensService = $tokensService; - $this->tpay = $tpayModel; - $this->notificationFactory = $notificationFactory; + $this->tpay = $tpay; } - public function process(?int $storeId) + public function process($notification, ?int $storeId = null) { - $notification = $this->notificationFactory->create(['merchantSecret' => $this->tpayConfig->getSecurityCode($storeId), 'productionMode' => !$this->tpayConfig->useSandboxMode($storeId)])->getNotification(); - - $notification = $notification->getNotificationAssociative(); - $orderId = base64_decode($notification['tr_crc']); + if (!$notification instanceof BasicPayment) { + throw new \RuntimeException('Invalid payment notification type'); + } + $orderId = base64_decode($notification->tr_crc->getValue()); $order = $this->tpayService->getOrderById($orderId); - if ('TRUE' === $notification['tr_status']) { - $this->tpayService->confirmPayment($order, $notification['tr_amount'], $notification['tr_id'], []); - $this->saveCard($notification, $orderId); - } - if ('CHARGEBACK' === $notification['tr_status']) { - $this->tpayService->addCommentToHistory($orderId, __('Transaction has been refunded via Tpay Transaction Panel')); + switch ($notification->tr_status->getValue()) { + case 'TRUE': + case 'PAID': + $this->tpayService->confirmPayment( + $order, + $notification->tr_amount->getValue(), + $notification->tr_id->getValue(), + [] + ); + break; + case 'CHARGEBACK': + $this->tpayService->addCommentToHistory( + $orderId, + __('Transaction has been refunded via Tpay Transaction Panel') + ); + break; } + + $this->saveCard($notification, $orderId); } - private function saveCard(array $notification, string $orderId) + private function saveCard(BasicPayment $notification, string $orderId) { + if (!$notification->card_token) { + return; + } + + if ($this->tpay->isCustomerGuest($orderId)) { + return; + } + $order = $this->tpayService->getOrderById($orderId); - if (isset($notification['card_token']) && !$this->tpay->isCustomerGuest($orderId)) { - $token = $this->tokensService->getWithoutAuthCustomerTokens( - (string) $order->getCustomerId(), - $notification['tr_crc'] - ); + $token = $this->tokensService->getWithoutAuthCustomerTokens( + (string) $order->getCustomerId(), + $notification->tr_crc->getValue() + ); - if (!empty($token)) { - $this->tokensService->updateTokenById((int) $token['tokenId'], $notification['card_token']); - } + if (!empty($token)) { + $this->tokensService->updateTokenById((int) $token['tokenId'], $notification->card_token->getValue()); } } } diff --git a/Notification/Strategy/Factory/NotificationProcessorFactory.php b/Notification/Strategy/Factory/NotificationProcessorFactory.php index 4db9c97..bc8ae8a 100644 --- a/Notification/Strategy/Factory/NotificationProcessorFactory.php +++ b/Notification/Strategy/Factory/NotificationProcessorFactory.php @@ -2,32 +2,29 @@ namespace Tpay\Magento2\Notification\Strategy\Factory; -use Magento\Framework\App\RequestInterface; use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorFactoryInterface; use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorInterface; +use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasRegister; +use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasUnregister; class NotificationProcessorFactory implements NotificationProcessorFactoryInterface { /** @var list */ protected $strategies; - /** @var RequestInterface */ - private $request; - - public function __construct(RequestInterface $request, array $strategies = []) + public function __construct(array $strategies = []) { $this->strategies = $strategies; - $this->request = $request; } - public function create(array $data): NotificationProcessorInterface + public function create($notification): NotificationProcessorInterface { - if (null !== $this->request->getPost('card')) { - return $this->strategies['card']; + if ($notification instanceof BlikAliasRegister || $notification instanceof BlikAliasUnregister) { + return $this->strategies['blikAlias']; } - if (null !== $this->request->getPost('event')) { - return $this->strategies['blikAlias']; + if (is_array($notification) && isset($data['card'])) { + return $this->strategies['card']; } return $this->strategies['default']; diff --git a/composer.json b/composer.json index abbe147..7d9de92 100755 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": ">=7.1", "ext-json": "*", "composer-runtime-api": "^2.0", - "tpay-com/tpay-openapi-php": "^2.2.3", + "tpay-com/tpay-openapi-php": "^2.4.0", "tpay-com/tpay-php": "^2.4.7" }, "suggest": { From 7a673a7503a5b293edd2aae6851704d7e9a7c5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Mon, 2 Mar 2026 14:10:48 +0100 Subject: [PATCH 2/6] New SDK notifications --- Notification/NotificationProcessor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Notification/NotificationProcessor.php b/Notification/NotificationProcessor.php index a2a0743..0547740 100644 --- a/Notification/NotificationProcessor.php +++ b/Notification/NotificationProcessor.php @@ -2,7 +2,6 @@ namespace Tpay\Magento2\Notification; -use _PHPStan_5adafcbb8\Psr\Http\Message\RequestInterface; use Magento\Framework\App\RequestInterface; use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorFactoryInterface; From fc324c2c4a007022d740b41fc32ff1886d355767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Mon, 2 Mar 2026 14:14:28 +0100 Subject: [PATCH 3/6] fixer --- .../NotificationProcessorFactoryInterface.php | 4 +--- Notification/NotificationProcessor.php | 11 +++++------ .../Strategy/BlikAliasNotificationProcessor.php | 5 ++++- .../Strategy/DefaultNotificationProcessor.php | 3 ++- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Api/Notification/Strategy/NotificationProcessorFactoryInterface.php b/Api/Notification/Strategy/NotificationProcessorFactoryInterface.php index decef3b..67fdf5c 100644 --- a/Api/Notification/Strategy/NotificationProcessorFactoryInterface.php +++ b/Api/Notification/Strategy/NotificationProcessorFactoryInterface.php @@ -6,8 +6,6 @@ interface NotificationProcessorFactoryInterface { - /** - * @param array|Objects $notification - */ + /** @param array|Objects $notification */ public function create($notification): NotificationProcessorInterface; } diff --git a/Notification/NotificationProcessor.php b/Notification/NotificationProcessor.php index 0547740..a4dfd64 100644 --- a/Notification/NotificationProcessor.php +++ b/Notification/NotificationProcessor.php @@ -15,15 +15,15 @@ class NotificationProcessor { - /** @var RequestInterface */ - private $request; - /** @var NotificationProcessorFactoryInterface */ protected $factory; /** @var TpayService */ protected $tpayService; + /** @var RequestInterface */ + private $request; + /** @var TpayConfigInterface */ private $config; @@ -82,9 +82,7 @@ private function resolveStoreId($notification, int $defaultStoreId): ?int return $order->getStoreId() ? (int) $order->getStoreId() : $defaultStoreId; } - /** - * @return OriginApiWebhook|OpenApiWebhook - */ + /** @return OriginApiWebhook|OpenApiWebhook */ private function createWebhook(?int $storeId) { if (null !== $this->request->getPost('card')) { @@ -95,6 +93,7 @@ private function createWebhook(?int $storeId) } $certificateProvider = new CacheCertificateProvider(new Cache()); + return new OpenApiWebhook( $certificateProvider, $this->config->getSecurityCode($storeId), diff --git a/Notification/Strategy/BlikAliasNotificationProcessor.php b/Notification/Strategy/BlikAliasNotificationProcessor.php index 5bb3dec..6474e43 100644 --- a/Notification/Strategy/BlikAliasNotificationProcessor.php +++ b/Notification/Strategy/BlikAliasNotificationProcessor.php @@ -4,6 +4,7 @@ namespace Tpay\Magento2\Notification\Strategy; +use RuntimeException; use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorInterface; use Tpay\Magento2\Service\TpayAliasServiceInterface; use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasRegister; @@ -26,6 +27,7 @@ public function process($notification, ?int $storeId = null) $userId = (int) explode('-', $alias)[1]; $this->aliasService->saveCustomerAlias($userId, $alias); + return; } @@ -34,9 +36,10 @@ public function process($notification, ?int $storeId = null) $userId = (int) explode('-', $alias)[1]; $this->aliasService->removeCustomerAlias($userId, $alias); + return; } - throw new \RuntimeException('Unsupported BLIK notification type'); + throw new RuntimeException('Unsupported BLIK notification type'); } } diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index c265afb..2781a84 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -2,6 +2,7 @@ namespace Tpay\Magento2\Notification\Strategy; +use RuntimeException; use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorInterface; use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Service\TpayService; @@ -32,7 +33,7 @@ public function __construct( public function process($notification, ?int $storeId = null) { if (!$notification instanceof BasicPayment) { - throw new \RuntimeException('Invalid payment notification type'); + throw new RuntimeException('Invalid payment notification type'); } $orderId = base64_decode($notification->tr_crc->getValue()); From fe282dfe901dcea41c660cafbac367fd32a40dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Mon, 2 Mar 2026 14:15:47 +0100 Subject: [PATCH 4/6] fixer --- Notification/NotificationProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notification/NotificationProcessor.php b/Notification/NotificationProcessor.php index a4dfd64..68e6490 100644 --- a/Notification/NotificationProcessor.php +++ b/Notification/NotificationProcessor.php @@ -82,7 +82,7 @@ private function resolveStoreId($notification, int $defaultStoreId): ?int return $order->getStoreId() ? (int) $order->getStoreId() : $defaultStoreId; } - /** @return OriginApiWebhook|OpenApiWebhook */ + /** @return OpenApiWebhook|OriginApiWebhook */ private function createWebhook(?int $storeId) { if (null !== $this->request->getPost('card')) { From 84d42937088413b63e30c4f2328b33607109a282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Mon, 2 Mar 2026 14:17:05 +0100 Subject: [PATCH 5/6] fixer --- Notification/Strategy/Factory/NotificationProcessorFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notification/Strategy/Factory/NotificationProcessorFactory.php b/Notification/Strategy/Factory/NotificationProcessorFactory.php index bc8ae8a..959b724 100644 --- a/Notification/Strategy/Factory/NotificationProcessorFactory.php +++ b/Notification/Strategy/Factory/NotificationProcessorFactory.php @@ -23,7 +23,7 @@ public function create($notification): NotificationProcessorInterface return $this->strategies['blikAlias']; } - if (is_array($notification) && isset($data['card'])) { + if (is_array($notification) && isset($notification['card'])) { return $this->strategies['card']; } From 3eeb7ce4063969989cca0c4a1b4a729808e0d5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Tue, 3 Mar 2026 09:37:56 +0100 Subject: [PATCH 6/6] CR --- .../NotificationProcessorInterface.php | 2 +- Notification/NotificationProcessor.php | 33 ++----------------- .../BlikAliasNotificationProcessor.php | 2 +- .../Strategy/CardNotificationProcessor.php | 2 +- .../Strategy/DefaultNotificationProcessor.php | 2 +- 5 files changed, 7 insertions(+), 34 deletions(-) diff --git a/Api/Notification/Strategy/NotificationProcessorInterface.php b/Api/Notification/Strategy/NotificationProcessorInterface.php index 4d2efab..f1c5f66 100644 --- a/Api/Notification/Strategy/NotificationProcessorInterface.php +++ b/Api/Notification/Strategy/NotificationProcessorInterface.php @@ -4,5 +4,5 @@ interface NotificationProcessorInterface { - public function process($notification, ?int $storeId = null); + public function process($notification); } diff --git a/Notification/NotificationProcessor.php b/Notification/NotificationProcessor.php index 68e6490..6d77d56 100644 --- a/Notification/NotificationProcessor.php +++ b/Notification/NotificationProcessor.php @@ -7,7 +7,6 @@ use Tpay\Magento2\Api\Notification\Strategy\NotificationProcessorFactoryInterface; use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Service\TpayService; -use Tpay\OpenApi\Model\Objects\NotificationBody\BasicPayment; use Tpay\OpenApi\Utilities\Cache; use Tpay\OpenApi\Utilities\CacheCertificateProvider; use Tpay\OpenApi\Webhook\JWSVerifiedPaymentNotification as OpenApiWebhook; @@ -46,40 +45,14 @@ public function __construct( public function process() { - $defaultStoreId = $this->storeManager->getDefaultStoreView()->getId(); - $webhook = $this->createWebhook($defaultStoreId); + $storeId = $this->storeManager->getStore()->getId(); + $webhook = $this->createWebhook($storeId); $notification = $webhook->getNotification(); - $storeId = $this->resolveStoreId($notification, $defaultStoreId); - - if ($storeId !== $defaultStoreId) { - $webhook = $this->createWebhook($storeId); - $notification = $webhook->getNotification(); - } $strategy = $this->factory->create($notification); - $strategy->process($storeId); - } - - private function resolveStoreId($notification, int $defaultStoreId): ?int - { - if ($notification instanceof BasicPayment) { - $value = $notification->tr_crc->getValue(); - } elseif (is_array($notification)) { - $value = $notification['order_id'] ?? $notification['tr_crc'] ?? null; - } else { - return null; - } - - if (!$value) { - return null; - } - - $orderId = base64_decode($value); - $order = $this->tpayService->getOrderById($orderId); - - return $order->getStoreId() ? (int) $order->getStoreId() : $defaultStoreId; + $strategy->process($notification); } /** @return OpenApiWebhook|OriginApiWebhook */ diff --git a/Notification/Strategy/BlikAliasNotificationProcessor.php b/Notification/Strategy/BlikAliasNotificationProcessor.php index 6474e43..a967dcf 100644 --- a/Notification/Strategy/BlikAliasNotificationProcessor.php +++ b/Notification/Strategy/BlikAliasNotificationProcessor.php @@ -20,7 +20,7 @@ public function __construct(TpayAliasServiceInterface $aliasService) $this->aliasService = $aliasService; } - public function process($notification, ?int $storeId = null) + public function process($notification) { if ($notification instanceof BlikAliasRegister) { $alias = (string) $notification->value->getValue(); diff --git a/Notification/Strategy/CardNotificationProcessor.php b/Notification/Strategy/CardNotificationProcessor.php index 5bde8f0..2f3111e 100644 --- a/Notification/Strategy/CardNotificationProcessor.php +++ b/Notification/Strategy/CardNotificationProcessor.php @@ -34,7 +34,7 @@ public function __construct( $this->tpay = $tpay; } - public function process($notification, ?int $storeId = null) + public function process($notification) { $orderId = base64_decode($notification['order_id']); $order = $this->tpayService->getOrderById($orderId); diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index 2781a84..a9d2a57 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -30,7 +30,7 @@ public function __construct( $this->tpay = $tpay; } - public function process($notification, ?int $storeId = null) + public function process($notification) { if (!$notification instanceof BasicPayment) { throw new RuntimeException('Invalid payment notification type');