diff --git a/.version b/.version index 834f262..dbe5900 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.8.0 +2.8.1 diff --git a/CHANGELOG.MD b/CHANGELOG.MD index c5dc702..21f22f8 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.8.1 + +### Added + +- Currency to notification + ## 2.8.0 ### Added diff --git a/Notification/Strategy/DefaultNotificationProcessor.php b/Notification/Strategy/DefaultNotificationProcessor.php index 734c594..0347e45 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->getBaseCurrencyCode(), + $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,27 @@ private function validateAmount($order, BasicPayment $notification): bool return $orderAmount === $notificationAmount; } + + private function validateCurrency($order, BasicPayment $notification): bool + { + $value = null; + + if (isset($notification->tr_currency) && $notification->tr_currency) { + $value = $notification->tr_currency->getValue(); + } + + if (!is_string($value) || '' === trim($value)) { + return true; + } + + $notificationCurrency = strtoupper(trim($value)); + + $orderCurrency = $order->getBaseCurrencyCode(); + + if (null === $orderCurrency) { + return true; + } + + return strtoupper(trim($orderCurrency)) === $notificationCurrency; + } } diff --git a/composer.json b/composer.json index fa06f92..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.5", + "tpay-com/tpay-openapi-php": "dev-currency-in-notification", "tpay-com/tpay-php": "^2.4.7", "psr/simple-cache": "^1" },