fix(stripe-plugin): convert refund amounts for zero-decimal currencies - #53
Open
hayashi7752 wants to merge 1 commit into
Open
fix(stripe-plugin): convert refund amounts for zero-decimal currencies#53hayashi7752 wants to merge 1 commit into
hayashi7752 wants to merge 1 commit into
Conversation
Vendure stores money amounts multiplied by 100 and the charge side already converts them for Stripe via getAmountInStripeMinorUnits. createRefund, however, passed the raw Vendure amount straight to stripe.refunds.create, so refunds in zero-decimal currencies (JPY, KRW, ...) were sent as 100x the real amount and rejected by Stripe with "Refund amount (...) is greater than charge amount". Apply the same currency check on the refund side so both directions stay symmetric, and export currencyHasFractionPart from stripe-utils for reuse.
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Refunds fail for zero-decimal currencies (JPY, KRW, …).
Vendure stores money amounts multiplied by 100, and the charge side already converts them for Stripe via
getAmountInStripeMinorUnits(which divides by 100 for currencies without a fraction part).StripeService.createRefund, however, passes the raw Vendure amount straight tostripe.refunds.create, so a ¥1,300 refund (stored as130000) is sent to Stripe as130000— 100x the real amount — and rejected:This makes all refunds impossible on JPY stores (we hit this in production and have been running with a patched plugin since).
Fix
Apply the same currency check on the refund side so both directions stay symmetric with
getAmountInStripeMinorUnits:currencyHasFractionPartfromstripe-utils.tscreateRefund, divide the amount by 100 for currencies without a fraction partNo behavior change for fractional currencies (USD, EUR, …).
Notes
getAmountInStripeMinorUnits— the refund path was left unconverted.tsc -p tsconfig.build.jsonpasses. Happy to add an e2e case for a zero-decimal channel if you'd like — let me know the preferred setup for switching the fixture currency.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.