There is some unexpected behaviour in the Money object regarding cents vs float amount.
For this Issue I'm going to use euro as currency, but this holds true for all currencies containing decimals.
Looking at the Money object, we'd expect to pass the value in euro's since it accepts a float amount, and has a getAmount() method returning float and it contains a getAmountInCents() method that returns the amount multiplied by 100.
/**
* @return float
*/
public function getAmountInCents(): float
{
return $this->amount * 100;
}
When we look at the usage of the money object in the api and the MoneyFormatter we see that it actually is expected to pass the amount in cents to the money object.
In order to avoid confusion, I suggest to remove the getAmountInCents() method from the Money VO. (It isn't used afaik).
A more breaking change would be to actually change the cents amount value to int (float amounts for cents probably don't make sense in the context of a psp / the api).
Id suggest to add static Money::fromAmount(10,50) and Money::fromBaseAmount(1050) static methods to the money VO in order to have an even clearer api.
There is some unexpected behaviour in the Money object regarding cents vs float amount. For this Issue I'm going to use euro as currency, but this holds true for all currencies containing decimals.
Looking at the Money object, we'd expect to pass the value in euro's since it accepts a float amount, and has a
getAmount()
method returning float and it contains agetAmountInCents()
method that returns the amount multiplied by 100.When we look at the usage of the money object in the api and the MoneyFormatter we see that it actually is expected to pass the amount in cents to the money object.
In order to avoid confusion, I suggest to remove the getAmountInCents() method from the Money VO. (It isn't used afaik).
A more breaking change would be to actually change the cents amount value to int (float amounts for cents probably don't make sense in the context of a psp / the api).
Id suggest to add static
Money::fromAmount(10,50)
andMoney::fromBaseAmount(1050)
static methods to the money VO in order to have an even clearer api.