Skip to content

Commit

Permalink
Round to 5 decimals on total cost
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdnk committed Sep 2, 2024
1 parent 940602b commit abe7911
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Entities/Response/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion tests/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testConstructResponse()
'DK' => 4,
'SE' => 2
],
'total_cost' => 0.00596,
'total_cost' => 0.005964,
'currency' => 'eur'
],
'ids' => [1234567, 1234568]
Expand Down

0 comments on commit abe7911

Please sign in to comment.