Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.0
2.8.1
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions Notification/Strategy/DefaultNotificationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Loading