Repository navigation
Send zero-decimal currency amounts to Stripe Lite in whole units - #580
Conversation
Fixes Strategy11/business-directory-premium#391 JPY, KRW and other zero-decimal currencies are no longer charged 100x, and their renewals are recorded at the full amount.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 11 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
Approve — the zero-decimal fix is correct and complete for this gateway; one non-blocking note.
Verified
- Harness that loads the real
WPBDPStripeGateway::formated_amount()(via reflection) andWPBDPStrpAppHelperfrom basedac5326and heada973534: JPY 1000 →100000on base,1000at head; KRW, VND and BIF likewise; USD 10.5 →1050, EUR 19.99 →1999unchanged; ISK 1234.5 →123500and UGX 5000.4 →500000(whole units sent as two-decimal, as Stripe expects). - Webhook side:
amount_from_stripe( $invoice->total, ... )returns1000.0forjpy,19.99foreur,1234.0forisk(Stripe sends a lowercase currency code,strtoupperhandles it), and falls back to/ 100for a null currency. - All four
formated_amountcall sites (checkout line item, couponamount_off, plan fingerprint,create_stripe_plan) now pass$payment->currency_code, and$paymentis in scope at each. The only other/ 100on a Stripe amount in the gateway code is the one in the events controller. The zero-decimal list covers every zero-decimal currency insupports_currency(); the three-decimal currencies (BHD, KWD, …) are not in that supported list. - The plan fingerprint now differs for zero-decimal currencies, so a merchant who previously got a 100x JPY plan gets a new correctly-priced plan rather than reusing the old one.
php -lclean on all three files. CI ata973534: PHPCS, PHPStan and PHP 7.4 tests (WP 5.8 and master) all pass. The new code uses??(the plugin requires PHP 7.4).
Non-blocking: no test covers the new currency branching, and tests/unit is empty in this repo so there is nowhere obvious to add one. A small parameterized test on formated_amount / amount_from_stripe (JPY, USD, ISK) would pin it.
Not exercised: a live Stripe Checkout or renewal in JPY (no Stripe keys here). I read the code directly and did not run the code-review/security-review/simplify skills on this PR.
Tests run: PHP harness above (base vs a9735346) → base 100x, head correct.
Fixes Strategy11/business-directory-premium#391
Stripe Lite now sends JPY, KRW and other zero-decimal amounts (checkout, plans, coupons) in whole units and records their renewals at the full amount; ISK/UGX are sent without fractions. Mirrors Strategy11/business-directory-stripe#70.