Skip to content

Validate donation amount to prevent Stripe overflow error#8490

Merged
iHiD merged 1 commit into
mainfrom
fix/8484
Feb 9, 2026
Merged

Validate donation amount to prevent Stripe overflow error#8490
iHiD merged 1 commit into
mainfrom
fix/8484

Conversation

@iHiD
Copy link
Copy Markdown
Member

@iHiD iHiD commented Feb 9, 2026

Closes #8484

Summary

  • Client-side: Added max amount validation ($999,999.99) to CustomAmountInput — both as an HTML max attribute and a JavaScript check in the change handler. Values exceeding the max are treated as NaN, which all parent components already handle gracefully by falling back to defaults.
  • Server-side: Added amount range validation (1–99,999,999 cents) in PaymentIntentsController#create before calling the Stripe API, returning an error in the existing format.
  • Added controller tests for over-max, zero, and negative amounts.

The root cause was that extremely large custom amounts (e.g. 10000000000000000000) get multiplied by 100 via currency.js intValue, producing 1e+21 in JavaScript scientific notation, which Stripe Elements rejects.

Test plan

  • bundle exec rails test test/controllers/api/payments/payment_intents_controller_test.rb — 8 tests, 0 failures
  • Pre-commit hooks pass (rubocop, prettier)

🤖 Generated with Claude Code

Large custom amounts (e.g. 10 quintillion) caused currency.js intValue
to produce 1e+21 in scientific notation, which Stripe rejects. Add max
validation in CustomAmountInput (client-side) and PaymentIntentsController
(server-side) capped at Stripe's $999,999.99 limit.

Closes #8484

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@iHiD iHiD requested a review from dem4ron as a code owner February 9, 2026 14:17
@iHiD iHiD merged commit 6c45bf3 into main Feb 9, 2026
41 checks passed
@iHiD iHiD deleted the fix/8484 branch February 9, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IntegrationError: Invalid value for elements(): amount should be a positive amount in the currency's subunit. You specified: 1e+21.

1 participant