Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am using Commerce 2 with the Stripe payment gateway.
I have products with prices in yen. For example, 3,000 yen.
Inside Commerce, the price is shown as 3,000 yen. However, when I test ordering the product using Stripe, the charge to the credit card is 300,000 yen, 100x the correct price!
If I set the price in Commerce to 30 yen, then 3,000 yen is billed to the card.
Yen is a non-decimal currency, but it seems that somewhere in the process the yen price is getting treated like a decimal currency, increasing it by a factor of 100.
Comment | File | Size | Author |
---|---|---|---|
#11 | 2913605-11.patch | 2.28 KB | bojanz |
#10 | 2913605-10.patch | 3.13 KB | bojanz |
#8 | 2913605-8_commerce_stripe-currency_fraction_digits.patch | 3.06 KB | ptmkenny |
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedThis is a Stripe module bug. For some reason the gateway does this:
Comment #3
ptmkenny CreditAttribution: ptmkenny commentedOk, so the code presupposes all currencies have two decimal places.
On the currencies configuration screen, you can set the number of fraction digits per currency, so the module needs to take this into account.
Comment #4
bojanz CreditAttribution: bojanz at Centarro commentedYeah.
This feels like something that should be easier (perhaps with a PaymentGatewayBase helper?). In any case, let's fix Stripe first.
Comment #5
ptmkenny CreditAttribution: ptmkenny commentedPatch based on code by bojanz. I had to make some changes because in formatNumber, $amount is an int not an object. Tested with yen and dollars, appears to be working OK for both.
Comment #6
ptmkenny CreditAttribution: ptmkenny commentedSecond patch, left some debugging code in the first, sorry.
Comment #7
ptmkenny CreditAttribution: ptmkenny commentedOne more patch, this time fixing a stray space.
Comment #8
ptmkenny CreditAttribution: ptmkenny commentedI updated the patch to get the currency based on the $payment object; this way, it will still be easy to call formatNumber() because you won't need to get the $currencycode first (which is what the previous patch required).
Comment #9
bojanz CreditAttribution: bojanz at Centarro commentedWe should be passing the entire Price object and getting both the number and currency code from there. No need to look at the payment.
Comment #10
bojanz CreditAttribution: bojanz at Centarro commentedCan you confirm that this works?
Comment #11
bojanz CreditAttribution: bojanz at Centarro commentedAdded the helper to Commerce 2.2.
Update Commerce, and then test the attached patch.
Comment #12
ptmkenny CreditAttribution: ptmkenny commented@bojanz I tested the patch in #11 with Commerce 2.2 by purchasing products in JPY and then again in USD; in both cases, the currency amounts were correct. Thank you!
Comment #14
bojanz CreditAttribution: bojanz at Centarro commentedCommitted. Thank you for your work.