From 5ef2a77dd6e0b7bbe2d531a3ff03e24759c6de84 Mon Sep 17 00:00:00 2001 From: MarkusHolstein Date: Wed, 14 May 2025 18:18:07 +0200 Subject: [PATCH 1/3] Fixes Bug with number rounding --- src/Verifier/PaymentAmountVerifier.php | 4 ++-- tests/Unit/PaymentAmountVerifierTest.php | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Verifier/PaymentAmountVerifier.php b/src/Verifier/PaymentAmountVerifier.php index 1d0795c6..30dee0bf 100644 --- a/src/Verifier/PaymentAmountVerifier.php +++ b/src/Verifier/PaymentAmountVerifier.php @@ -41,7 +41,7 @@ private function getTotalPaymentAmountFromPaypal(PaymentInterface $payment, arra foreach ($paypalOrderDetails['purchase_units'] as $unit) { $stringAmount = $unit['amount']['value'] ?? '0'; - $totalAmount += (int) ($stringAmount * 100); + $totalAmount += (int) round($stringAmount * 100); } return $totalAmount; @@ -53,4 +53,4 @@ private function getPaymentAmountFromDetails(PaymentInterface $payment): int return $details['payment_amount'] ?? 0; } -} +} \ No newline at end of file diff --git a/tests/Unit/PaymentAmountVerifierTest.php b/tests/Unit/PaymentAmountVerifierTest.php index 240ff369..3ff28437 100644 --- a/tests/Unit/PaymentAmountVerifierTest.php +++ b/tests/Unit/PaymentAmountVerifierTest.php @@ -47,6 +47,24 @@ public function testVerifySucceedsWhenAmountsMatch(): void $this->addToAssertionCount(1); } + public function testVerifySucceedsWhenAmountsMatchWithRoundedValue(): void + { + $payment = $this->createMock(PaymentInterface::class); + $order = $this->createMock(OrderInterface::class); + $payment->method('getOrder')->willReturn($order); + $order->method('getTotal')->willReturn(225845); + + $paypalOrderDetails = [ + 'purchase_units' => [ + ['amount' => ['value' => '2258.45']], + ], + ]; + + $this->verifier->verify($payment, $paypalOrderDetails); + + $this->addToAssertionCount(1); + } + public function testVerifyThrowsExceptionWhenAmountsDoNotMatch(): void { $payment = $this->createMock(PaymentInterface::class); @@ -130,4 +148,4 @@ public function testVerifyWithMissingAmountInPurchaseUnitShouldDefaultToZero(): $this->addToAssertionCount(1); } -} +} \ No newline at end of file From cecf0bbf532626c8b50e9159b6a05eb5e31b0fab Mon Sep 17 00:00:00 2001 From: MarkusHolstein Date: Wed, 4 Jun 2025 13:58:41 +0200 Subject: [PATCH 2/3] Makes PhpCsFixer happy --- src/Verifier/PaymentAmountVerifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Verifier/PaymentAmountVerifier.php b/src/Verifier/PaymentAmountVerifier.php index 30dee0bf..c68429dd 100644 --- a/src/Verifier/PaymentAmountVerifier.php +++ b/src/Verifier/PaymentAmountVerifier.php @@ -53,4 +53,4 @@ private function getPaymentAmountFromDetails(PaymentInterface $payment): int return $details['payment_amount'] ?? 0; } -} \ No newline at end of file +} From de0bd5fa8b51728d1c1ec0560ea79e83b14b7480 Mon Sep 17 00:00:00 2001 From: MarkusHolstein Date: Wed, 4 Jun 2025 13:59:11 +0200 Subject: [PATCH 3/3] Makes PhpCsFixer even more happy --- tests/Unit/PaymentAmountVerifierTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/PaymentAmountVerifierTest.php b/tests/Unit/PaymentAmountVerifierTest.php index 3ff28437..b0a00c90 100644 --- a/tests/Unit/PaymentAmountVerifierTest.php +++ b/tests/Unit/PaymentAmountVerifierTest.php @@ -148,4 +148,4 @@ public function testVerifyWithMissingAmountInPurchaseUnitShouldDefaultToZero(): $this->addToAssertionCount(1); } -} \ No newline at end of file +}