14 min read

Stripe Error Codes Reference

Every failing call to a Stripe endpoint returns an error body carrying one of the shared error codes.

Error Response Format

{
  "ok": false,
  "status": 403,
  "code": "InvalidPayload",
  "message": "Invalid access key",
  "route": "/stripe/purchases"
}
Field Type Description
ok boolean Always false in an error body.
status number The HTTP status, repeated in the body.
code string Name of the error code (see below), or "Error" for a failure raised without one.
message string Human-readable description of what failed.
source string Message of the error that caused the failure (a Stripe rejection, for instance); omitted when there is none.
route string The route that failed, without the /v3 prefix.

source is worth logging: it carries the underlying reason when the failure wrapped one. sentry and stack are diagnostic only — sentry is the id of the Sentry event captured for a production failure (its id is also appended to message as (#id)), and stack is present outside production. Don't branch on either.

code carries the code's name. The same codes also have numbers (6778001, 7691001, …) in the ErrorNumber enum; the number is the form the receipt-validation response (/v1/validate) returns.

Error Codes

This is the whole ErrorCode / ErrorNumber set, with the statuses the API pairs each code with.

Code Number HTTP status Meaning
InvalidPayload 6778001 400, 403 The request is invalid or incomplete, or a credential it carries doesn't apply.
ConnectionFailed 6778002 — An external server (Apple, Google, Microsoft) is unreachable. Not returned by the Stripe endpoints.
PurchaseExpired 6778003 — The subscription is expired. Not returned by the Stripe endpoints.
PurchaseConsumed 6778004 — The consumable was already consumed. Not returned by the Stripe endpoints.
InternalError 6778005 500 Something prevented the server from processing the request.
NeedMoreData 6778006 — More data is required to complete the request. Not returned by the Stripe endpoints.
Unknown 6778007 — Unexpected error. Not returned by the Stripe endpoints.
AppNotFound 7691001 404 The app named by the Basic auth credentials doesn't exist.
Conflict 7691002 — The operation conflicts with another one. Not returned by the Stripe endpoints.
Forbidden 7691003 403 The credentials don't allow this request.
DatabaseError 7691004 500 The database behind the endpoint failed.
ResourceNotFound 7691005 400, 404 A resource the request refers to doesn't exist.

Errors Returned by Each Endpoint

Endpoint Status Code Raised when
any 400 InvalidPayload Invalid credentials — the request carries no Basic auth credentials (or they are malformed).
any 403 Forbidden Invalid credentials (apiKey missing) — the password half of the Basic auth credentials is empty.
any 404 AppNotFound The app named by the Basic auth credentials doesn't exist.
any 400 InvalidPayload appName and apiKey do not match — the key doesn't belong to that app.
GET /v3/stripe/prices 400 ResourceNotFound Stripe secret key not configured.
GET /v3/stripe/prices Stripe's own status InternalError The Stripe API call failed; message is Stripe's.
GET /v3/stripe/purchases 400 ResourceNotFound Stripe secret key not configured.
GET /v3/stripe/purchases 400 InvalidPayload accessToken is required and cannot be empty, id is required and cannot be empty.
GET /v3/stripe/purchases 403 InvalidPayload Invalid access key — the access token isn't valid for this app.
GET /v3/stripe/purchases 400 InvalidPayload Incomplete access key or Customer ID not found — neither the token nor its checkout session resolves to a Stripe customer.
POST /v3/stripe/checkout 400 ResourceNotFound Stripe secret key not configured.
POST /v3/stripe/checkout 400 InvalidPayload offerId is required and cannot be empty, successUrl is required and cannot be empty, cancelUrl is required and cannot be empty, Invalid offerId format: <offerId>. Expected 'stripe:<product_id>#<price_id>' or 'stripe:<price_id>'.
POST /v3/stripe/portal 400 ResourceNotFound Stripe secret key not configured.
POST /v3/stripe/portal 400 InvalidPayload accessToken is required, Customer not found.
POST /v3/stripe/portal 403 InvalidPayload Invalid access key.
POST /v3/stripe/change-plan 400 ResourceNotFound Stripe secret key not configured.
POST /v3/stripe/change-plan 400 InvalidPayload Subscription not found, No subscription found to update.
POST /v3/stripe/change-plan 403 InvalidPayload Invalid access key.
POST /v3/stripe/subscriptions/adopt 400 ResourceNotFound Stripe secret key not configured for this application.
POST /v3/stripe/subscriptions/adopt 400 InvalidPayload Missing or invalid stripeSubscriptionId., Missing applicationUsername.
POST /v3/stripe/subscriptions/adopt 404 ResourceNotFound The Stripe subscription doesn't exist.
POST /v3/stripe/subscriptions/adopt 500 InternalError Stripe failed while reading the subscription or writing its metadata.
POST /v3/webhook/stripe 400 ResourceNotFound Stripe secret key not configured.
POST /v3/webhook/stripe 400 InvalidPayload No Stripe signature found, Invalid webhook signature.

Purchase refreshes started from GET /v3/stripe/purchases report their own failures the same way, with InvalidPayload (bad receipt token or unresolvable Stripe id), ResourceNotFound (Stripe secret key not configured) or InternalError (Stripe unreachable).

Handling Errors

Client-side with iaptic-js

Failed calls reject with a plain Error, and the library exposes neither status nor code — branch on the call you made, not on a code. getPurchases(), redirectToCustomerPortal() and changePlan() propagate the API's message; order() and getProducts() do not, because they never read the error body — they reject with the library's own fixed strings, such as 'Failed to create checkout session'. Call POST /v3/stripe/checkout directly when you need the server's message.

try {
  await iaptic.order({
    offerId: 'stripe:prod_xyz#price_xyz',
    applicationUsername: 'user123',
    successUrl: 'https://example.com/#success',
    cancelUrl: 'https://example.com/#cancel'
  });
} catch (error) {
  // order() never reads the error body, so this is the library's own
  // 'Failed to create checkout session', not the server's message.
  console.error('Checkout failed:', error.message);
}

Server-side

Calls made directly against the REST API get the status, code and message fields, so they can be told apart:

const response = await fetch('https://validator.iaptic.com/v3/stripe/change-plan', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Basic ${btoa(`${appName}:${secretKey}`)}`
  },
  body: JSON.stringify({ accessToken, purchaseId, offerId })
});

if (!response.ok) {
  const { status, code, message } = await response.json();
  if (code === 'InvalidPayload' && status === 403) {
    // The access token is no longer valid for this purchase:
    // ask the customer to identify again.
  }
  throw new Error(`Stripe change-plan failed (${status} ${code}): ${message}`);
}

A few rules of thumb:

  • A 403 InvalidPayload (Invalid access key) means the stored access token is stale or belongs to another app: drop it and have the customer identify themselves again.
  • A 400 ResourceNotFound (Stripe secret key not configured) is a configuration problem on the app, not a request problem — surface it to the operator, don't retry.
  • A 500 InternalError, and an InternalError carrying Stripe's status, are server-side failures: safe to retry with a backoff.
  • sentry and stack are for support tickets. Read status, code and message.