Introducing the Chargebee CLI

Why do I see an 'Access-Control-Allow-Origin' error during checkout?

Problem Statement

You see Access-Control-Allow-Origin, CORS, preflight, or a generic network error in the browser when a customer uses Chargebee.js in-app checkout or loads the Chargebee JS API, and you need to know what it means and what to do next.

  • The error appears when the request goes from the Chargebee.js origin to your Chargebee site domain (a cross-origin request).
  • Checkout fails intermittently with CORS or network messages around Pay or Submit.
  • You recently switched keys or are testing with high request volume (for example, automation or many parallel sessions).

Solution

Cross-origin traffic is expected for in-app checkout: Chargebee.js loads your hosted checkout, and the browser enforces Cross-Origin Resource Sharing (CORS). The console message can come from more than one cause—work through these in order.

  1. Full-access API key in client-side code
    Using a full-access API key in browser code can trigger CORS errors. Use a publishable key only for browser API calls that its permissions support. Move API calls that require a full-access key to your server; for checkout through the Hosted Pages API, generate the hosted page on your server and return it to Chargebee.js as described in Checkout integration. Changing your browser code alone does not retire an exposed key: create the keys you need, update every application that was using the exposed key (including non-browser integrations), then delete the exposed key in Chargebee. Your site must keep at least one full-access key—see API keys. If any key might be a Chargebee product integration key, read Chargebee product integration keys before you disable or delete it.

  2. Edge rate limiting (HTTP 429) can look like a CORS failure
    Checkout traffic can be rate limited at the network edge when volume from one client location is very high (for example, rapid resubmits, many tabs, or sustained automated testing on a test site). Open your browser’s developer tools, select Network, and inspect the failed checkout request and any associated OPTIONS preflight request. If the response has HTTP 429 (Too Many Requests), rate limiting is involved. A 429 response without CORS headers can also appear as a CORS, preflight, or network error. A CORS message alone does not confirm rate limiting. If you cannot determine the response status, contact Chargebee Support with the failed request details. For background, see Hosted Checkout.

    Wait one to two minutes, then retry once; avoid tight retry loops. If you need a higher limit for legitimate testing or traffic, contact Chargebee Support. Site API rate limits and JS API rate limits are documented separately—support can confirm what applies to your site.

  3. Something else
    If neither (1) nor (2) matches, contact Chargebee Support with the console text and, if possible, the failed request URL and HTTP status.

A card declined or invalid card message means the payment request reached Chargebee. Treat that separately from network or CORS messages, which can fail before the payment step completes.

Additional Information

For background on CORS headers and preflight, see What is CORS?.