Loading wrapper for Stripe.js
This package allows Stripe.js to be imported as a CommonJS module or ES module.
Note: To be
PCI compliant,
you must load Stripe.js directly from https://js.stripe.com. You cannot
include it in a bundle or host it yourself. This package wraps the global
Stripe function provided by the Stripe.js script as an ES module.
Calling loadStripe always loads the latest version of Stripe.js, regardless of
which version of @stripe/stripe-js you use. Updates for this package only
impact tooling around the loadStripe helper itself and the TypeScript type
definitions provided for Stripe.js. Updates do not affect runtime availability
of features of Stripe.js.
Use npm to install the Stripe.js module:
npm install @stripe/stripe-js
Each @stripe/stripe-js version is pinned to a specific
Stripe.js version. The
pinned versions are as follows:
| @stripe/stripe-js | Stripe.js |
|---|---|
| = 3.1. |
Some methods in Stripe.js accept and return objects from the
Stripe API. The type declarations in
@stripe/stripe-js for these objects in will always track the
latest version of the Stripe API. If
you would like to use these types but are using an older version of the Stripe
API, we recommend
updating to the latest version,
or ignoring and overriding the type definitions as necessary.
Note that we may release new minor and patch versions of
@stripe/stripe-js with small but backwards-incompatible fixes to the type
declarations. These changes will not affect Stripe.js itself.
To best leverage Stripe’s advanced fraud functionality, ensure that Stripe.js is loaded on every page, not just your checkout page. This allows Stripe to detect suspicious behavior that may be indicative of fraud as customers browse your website.
By default, this module will insert a `
### Importing `loadStripe` without side effects
If you would like to use `loadStripe` in your application, but defer loading the
Stripe.js script until `loadStripe` is first called, use the alternative
`@stripe/stripe-js/pure` import module:
```js
// CommonJS module import
const {loadStripe} = require('@stripe/stripe-js/pure');
// ES module import
import {loadStripe} from '@stripe/stripe-js/pure';
// Stripe.js will not be loaded until `loadStripe` is called
const stripe = await loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx');
If you would like to
disable advanced fraud detection
altogether, use loadStripe.setLoadParameters:
// CommonJS module import
const {loadStripe} = require('@stripe/stripe-js/pure');
// ES module import
import {loadStripe} from '@stripe/stripe-js/pure';
loadStripe.setLoadParameters({advancedFraudSignals: false});
const stripe = await loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx');
The loadStripe.setLoadParameters function is only available when importing
loadStripe from @stripe/stripe-js/pure.
This project is maintained by Stripe and does not accept external pull requests. If you have feedback or ideas, please open an issue.
No open issues yet, or sync has not completed.