mollie / mollie-api-php

Mollie API client for PHP

Home Page:http://www.mollie.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible total amount bug

frits191 opened this issue · comments

Specifications

  • API Version: 2.44.1

Describe the issue

Hello, I have already resolved this but wondering if it is a bug. I have for a few years now had a line of code which can be seen below in my sites (str_replace), worked completely fine, customers could pay etc.
This saturday or sunday however suddenly the total amount of all mollie payments increased dramatically (basically it was ignoring the comma making 33.85 -> 3385 euro. I did not change anything myself but found out that removing the str_replace did the trick.
Did something change in the api? We had several customers complain about this and I am wondering why this changed suddenly and/or if someone else had this problem.

Maybe a better question: why did this used to work?

Note: I am the only developer, no one else has access to the source code.

//shippingCost = 3,95
//subTotal = 14,95
//Total becomes 
$total = $subTotal + $shippingCost;

$total = str_replace(",", "", $total);

//This is how I send the total to the api
"amount" => [
	"currency" => "EUR",
	"value" => number_format($total, 2, ".", "")
],

image

Hi @frits191,

I've just tried your code sample and tinkered a bit with it. The str_replace does not affect the payload that's getting sent to Mollie's API in any way. Looks like nothing changed on their end.

$shippingCost = 3.95;
$subTotal = 14.95;
$total = $subTotal + $shippingCost;

$strReplaced = str_replace(",", "", $total);

dd(
  $total, // 18.9
  $strReplaced, // string "18.9"
  number_format($total, 2, ".", ""), // string "18.90"
  number_format($strReplaced, 2, ".", ""), // string "18.90"
);

Glad to hear you've already solved it on your end.

Strange, then it must be something else I'm missing here.
Thank you for looking into it!