From abe791122d821bbf2af00f4b35133729acf8910c Mon Sep 17 00:00:00 2001 From: Nicolai Cornelis Date: Mon, 2 Sep 2024 15:48:59 +0200 Subject: [PATCH] Round to 5 decimals on total cost --- src/Entities/Response/Result.php | 5 ++++- tests/ResultTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Entities/Response/Result.php b/src/Entities/Response/Result.php index a52d58d..f7fab3b 100644 --- a/src/Entities/Response/Result.php +++ b/src/Entities/Response/Result.php @@ -40,6 +40,9 @@ public function __construct(float $totalCost, int $smsCount, string $currency, a /** * * Returns the total cost for the request as a decimal number. + * Rounded to a maximum of 5 decimal points using `PHP_ROUND_HALF_UP`. + * In practice, GatewayAPI only uses 4 decimal points, but their transaction + * log shows 5 digits. * * @return float */ @@ -123,7 +126,7 @@ public static function constructFromArray(array $array): Result } return new self( - $array['usage']['total_cost'], + round($array['usage']['total_cost'], 5), $smsCount, $array['usage']['currency'], $array['usage']['countries'], diff --git a/tests/ResultTest.php b/tests/ResultTest.php index f0c5fc3..59a8487 100644 --- a/tests/ResultTest.php +++ b/tests/ResultTest.php @@ -22,7 +22,7 @@ public function testConstructResponse() 'DK' => 4, 'SE' => 2 ], - 'total_cost' => 0.00596, + 'total_cost' => 0.005964, 'currency' => 'eur' ], 'ids' => [1234567, 1234568]