Error Codes
stripe402 defines six error codes in the PaymentErrorCode type. These are returned in the errorCode field of PaymentResponse when a payment fails.
Error Code Reference
payment_required
payment_requiredThe initial 402 challenge. No error has occurred — the server is informing the client that this resource requires payment.
When: Client requests a paid route without a
paymentheaderHTTP Status: 402
Included in:
PaymentRequiredResponse.errorfield
insufficient_credits
insufficient_creditsThe client has an existing credit balance, but it's not enough for this request.
When:
store.deductBalance()returnsnull(balance < amount) and nopaymentMethodIdwas providedHTTP Status: 402
Action: Client should retry with a
paymentMethodIdto top up credits
card_declined
card_declinedStripe rejected the card (e.g., insufficient funds, expired card, fraud detection).
When: Stripe throws a
StripeCardErrorduringPaymentIntent.create()HTTP Status: 402
Error message: The message from Stripe (e.g., "Your card was declined.")
payment_failed
payment_failedThe payment was processed but did not succeed, or an unexpected error occurred during payment processing.
When:
paymentIntent.status !== 'succeeded', or any non-card Stripe errorHTTP Status: 402
Error message: Includes the PaymentIntent status or the error message
invalid_payment
invalid_paymentThe payment header could not be decoded — it's not valid base64 or not valid JSON.
When:
decodeHeader()throws during parsing of thepaymentheaderHTTP Status: 402
Error message: "Malformed payment header"
top_up_below_minimum
top_up_below_minimumThe client specified a topUpAmount that is below the route's minTopUp.
When:
payload.topUpAmount < minTopUpHTTP Status: 402
Error message: "Top-up amount {amount} is below the minimum of {minTopUp}"
TypeScript Type
Error Response Format
All payment errors are returned as a PaymentResponse JSON body:
The Stripe402Error class in @stripe402/core can be used to create typed errors:
Last updated