From 318c6bd9ddf753cb8ac3d71c1a546a71b41b7a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Wed, 22 Apr 2026 09:51:38 +0200 Subject: [PATCH 1/8] Currency field in notification --- .version | 2 +- CHANGELOG.MD | 6 ++++ .../Strategy/DefaultNotificationProcessor.php | 28 +++++++++++++++++++ composer.json | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.version b/.version index 24ba9a3..860487c 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.7.0 +2.7.1 diff --git a/CHANGELOG.MD b/CHANGELOG.MD index e3519bd..5396bd9 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.7.1 + +### Added + +- Currency to notification + ## 2.7.0 ### Added diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index 734c594..a3b783e 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -51,6 +51,17 @@ public function process($notification) $orderId = base64_decode($notification->tr_crc->getValue()); $order = $this->tpayService->getOrderById($orderId); + if (!$this->validateCurrency($order, $notification)) { + $this->logger->error(sprintf( + 'Currency mismatch for order %s: order=%s, notification=%s', + $order->getIncrementId(), + $order->getOrderCurrencyCode(), + $notification->tr_currency ? $notification->tr_currency->getValue() : 'null' + )); + + throw new RuntimeException('Order currency mismatch'); + } + if (!$this->validateAmount($order, $notification)) { $this->logger->error(sprintf( 'Amount mismatch for order %s: order=%s, notification=%s', @@ -112,4 +123,21 @@ private function validateAmount($order, BasicPayment $notification): bool return $orderAmount === $notificationAmount; } + + private function validateCurrency($order, BasicPayment $notification): bool + { + $notificationCurrency = null; + + if (isset($notification->tr_currency) && $notification->tr_currency) { + $notificationCurrency = strtoupper(trim($notification->tr_currency->getValue())); + } + + if ($notificationCurrency === null) { + return true; + } + + $orderCurrency = strtoupper(trim($order->getOrderCurrencyCode())); + + return $orderCurrency === $notificationCurrency; + } } diff --git a/composer.json b/composer.json index 9a9724d..5d1fc77 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.4.2", + "tpay-com/tpay-openapi-php": "dev-currency-in-notification", "tpay-com/tpay-php": "^2.4.7", "psr/simple-cache": "^1" }, From 3d8611bc8c6169086ef5afdea7ea761581285dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Wed, 22 Apr 2026 09:53:01 +0200 Subject: [PATCH 2/8] fixer --- Notification/Strategy/DefaultNotificationProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index a3b783e..c980c6d 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -132,7 +132,7 @@ private function validateCurrency($order, BasicPayment $notification): bool $notificationCurrency = strtoupper(trim($notification->tr_currency->getValue())); } - if ($notificationCurrency === null) { + if (null === $notificationCurrency) { return true; } From c983bf6af73c4ad4fd26dbef8c6db731cb05c13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Wed, 22 Apr 2026 11:54:53 +0200 Subject: [PATCH 3/8] CR --- Notification/Strategy/DefaultNotificationProcessor.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index c980c6d..123e460 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -136,8 +136,12 @@ private function validateCurrency($order, BasicPayment $notification): bool return true; } - $orderCurrency = strtoupper(trim($order->getOrderCurrencyCode())); + $orderCurrency = $order->getBaseCurrencyCode(); - return $orderCurrency === $notificationCurrency; + if (null === $orderCurrency) { + return true; + } + + return strtoupper(trim($orderCurrency)) === $notificationCurrency; } } From 62d955d7c79f286a36bc9b4272f09db93bb3e505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Fri, 29 May 2026 10:51:53 +0200 Subject: [PATCH 4/8] update --- Notification/Strategy/DefaultNotificationProcessor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index 123e460..e1a9472 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -130,6 +130,10 @@ private function validateCurrency($order, BasicPayment $notification): bool if (isset($notification->tr_currency) && $notification->tr_currency) { $notificationCurrency = strtoupper(trim($notification->tr_currency->getValue())); + + if ('' === $notificationCurrency) { + $notificationCurrency = null; + } } if (null === $notificationCurrency) { From f5f7976e9c8eca785710ff7d3f79d4b97862a186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Wed, 17 Jun 2026 12:13:11 +0200 Subject: [PATCH 5/8] fix --- Notification/Strategy/DefaultNotificationProcessor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index e1a9472..bfd0659 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -129,10 +129,10 @@ private function validateCurrency($order, BasicPayment $notification): bool $notificationCurrency = null; if (isset($notification->tr_currency) && $notification->tr_currency) { - $notificationCurrency = strtoupper(trim($notification->tr_currency->getValue())); + $value = $notification->tr_currency->getValue(); - if ('' === $notificationCurrency) { - $notificationCurrency = null; + if (is_string($value) && trim($value) !== '') { + $notificationCurrency = strtoupper(trim($value)); } } From f22c4b21d9c011a3ee8fef4f70f30e144751ae14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Wed, 17 Jun 2026 12:18:31 +0200 Subject: [PATCH 6/8] fix --- .../Strategy/DefaultNotificationProcessor.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index bfd0659..650c9bb 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -55,7 +55,7 @@ public function process($notification) $this->logger->error(sprintf( 'Currency mismatch for order %s: order=%s, notification=%s', $order->getIncrementId(), - $order->getOrderCurrencyCode(), + $order->getBaseCurrencyCode(), $notification->tr_currency ? $notification->tr_currency->getValue() : 'null' )); @@ -126,20 +126,18 @@ private function validateAmount($order, BasicPayment $notification): bool private function validateCurrency($order, BasicPayment $notification): bool { - $notificationCurrency = null; + $value = null; if (isset($notification->tr_currency) && $notification->tr_currency) { $value = $notification->tr_currency->getValue(); - - if (is_string($value) && trim($value) !== '') { - $notificationCurrency = strtoupper(trim($value)); - } } - if (null === $notificationCurrency) { + if (!is_string($value) || trim($value) === '') { return true; } + $notificationCurrency = strtoupper(trim($value)); + $orderCurrency = $order->getBaseCurrencyCode(); if (null === $orderCurrency) { From 2cb853ede4614e30d8585bff3c38d324a2477732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Wed, 17 Jun 2026 12:21:26 +0200 Subject: [PATCH 7/8] fix --- Notification/Strategy/DefaultNotificationProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index 650c9bb..0347e45 100644 --- a/Notification/Strategy/DefaultNotificationProcessor.php +++ b/Notification/Strategy/DefaultNotificationProcessor.php @@ -132,7 +132,7 @@ private function validateCurrency($order, BasicPayment $notification): bool $value = $notification->tr_currency->getValue(); } - if (!is_string($value) || trim($value) === '') { + if (!is_string($value) || '' === trim($value)) { return true; } From ec123b594042df1c169026539692e13817836d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20K=C4=85kol?= Date: Wed, 17 Jun 2026 12:33:24 +0200 Subject: [PATCH 8/8] fix --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 834f262..dbe5900 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.8.0 +2.8.1