laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
238 stars 57 forks source link

JPY has two extra zeroes. #183

Closed patrickomeara closed 1 year ago

patrickomeara commented 1 year ago

Cashier Paddle Version

1.8.1

Laravel Version

9.52.6

PHP Version

8.2.3

Database Driver & Version

No response

Description

As mentioned here https://github.com/moneyphp/money/issues/684 by @driesvints there is an issue formatting JPY. The mentioned solution looks to be implemented in Cashier::formatAmount() However I am still getting an extra 2 zeroes for JPY, all other currencies work fine.

@driesvints Is this a known issue that we have to handle in our application code?

image image

Steps To Reproduce

Format a paddle price using JP country_code

driesvints commented 1 year ago

How are you displaying the price?

patrickomeara commented 1 year ago

I've tried ->price()->gross() as in the docs and tried using Cashier::formatAmount() directly.


Route::get('cashier', function() {
    return Cashier::productPrices(
        $planIds, 
        ['customer_country' => 'JP'],
    )->map(fn (ProductPrice $price) => $price->price()->gross());
});
driesvints commented 1 year ago

Hah, actually, it's not showing any decimal at all. You're being displayed 120000 Japanese Yen. This is because the modifier for other currencies shouldn't apply here. I've attempted to fix this here: https://github.com/laravel/cashier-paddle/pull/184

Can you try out that PR and let me know if things look better?

patrickomeara commented 1 year ago

Yep, sorry if that wasn't clear. Your solution in #184 will definitely work, as it's the same workaround I've just put live.


$multiplier = $productPrice->currency === 'JPY' ? 1 : 100;

return Cashier::formatAmount(
    (int) $productPrice->price()->rawGross() * $multiplier,
    $productPrice->price()->currency(),
    null,
    ['min_fraction_digits' => 0]
);