fix(paypal): handle zero-decimal currencies properly during order creation - #29992
Conversation
|
Welcome to Cal.diy, @misinierijon4-debug! Thanks for opening this pull request. A few things to keep in mind:
A maintainer will review your PR soon. Thanks for contributing! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughPayPal order creation now imports the shared Merge Risk: ⚪ Minimal · up to This change corrects PayPal order amounts for zero-decimal currencies while preserving existing formatting for currencies such as USD and EUR; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
Problem
When an event type is configured to accept PayPal payments in zero-decimal currencies such as Japanese Yen (JPY), the order creation path divides the stored amount by 100, causing PayPal to bill attendees only 1/100th of the configured price. For prices not divisible by 100 (e.g. ¥1,050), PayPal rejects the resulting decimal value and order creation fails.
Root cause
packages/app-store/paypal/lib/Paypal.tsincreateOrderhardcodes(amount / 100).toString()for purchase unit values, assuming all currencies have 2 decimal places. Unlike standard currencies stored in minor units (e.g. USD cents), zero-decimal currencies like JPY are stored unscaled in integer units throughout the application.Change
Updated
createOrderinpackages/app-store/paypal/lib/Paypal.tsto useconvertFromSmallestToPresentableCurrencyUnit(amount, currency).toString()from@calcom/lib/currencyConversions. This ensures zero-decimal currencies (JPY, KRW, etc.) retain their full integer amount while minor-unit currencies (USD, EUR, etc.) continue to be divided by 100.Proof
Test Red (Before Fix)
Test Green (After Fix)
Reference
Fixes #29983
/claim 29983
Disclosure
This fix was written with AI assistance.