Skip to content

Commit 449ea1c

Browse files
Edit README
1 parent 05f81d8 commit 449ea1c

File tree

1 file changed

+38
-43
lines changed

1 file changed

+38
-43
lines changed

README.md

+38-43
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,70 @@
1-
# ES Module for Stripe.js
1+
# Stripe.js ES Module
22

3-
Import and use [Stripe.js](https://stripe.com/docs/stripe-js) as an ES module.
4-
[![npm version](https://img.shields.io/npm/v/@stripe/stripe-js.svg?style=flat-square)](https://www.npmjs.com/package/@stripe/stripe-js)
3+
Use [Stripe.js](https://stripe.com/docs/stripe-js) as an ES module.
4+
5+
**Note**: For compliance reasons, Stripe.js must be loaded directly from
6+
`https://js.stripe.com`, and cannot be included in a bundle or hosted yourself.
7+
This package wraps the global `Stripe` function provided by the Stripe.js
8+
script as an ES module.
59

6-
Stripe.js cannot be bundled with your code; it must be served from
7-
**https//js</span>.<span>stripe</span>.<span>com/v3**. This module wraps the
8-
global `Stripe` function provided by the Stripe.js script. If needed, it will
9-
inject the script for you and provide a loading wrapper.
10+
[![npm version](https://img.shields.io/npm/v/@stripe/stripe-js.svg?style=flat-square)](https://www.npmjs.com/package/@stripe/stripe-js)
1011

1112
## Usage
1213

13-
### `Stripe()`
14+
### `Stripe`
1415

15-
To use the exported `Stripe()` function, first include the Stripe.js script on
16+
To use the exported `Stripe` function, first include the Stripe.js script on
1617
each page of your site.
1718

1819
```html
1920
<script src="https://js.stripe.com/v3/"></script>
2021
```
2122

22-
Then import and use Stripe.js as you would any other module. For more
23-
information on how to use Stripe.js, please refer to the
24-
[Stripe.js API reference](https://stripe.com/docs/js) or learn to
25-
[accept a payment](https://stripe.com/docs/payments/accept-a-payment) with
26-
Stripe.
23+
Then import and use Stripe.js as you would any other module.
2724

2825
```js
2926
import {Stripe} from '@stripe/stripe-js';
3027

3128
const stripe = Stripe('pk_test_TYooMQauvdEDq54NiTphI7jx');
3229
```
3330

34-
Weve placed a random API key in the code. Replace it with your
35-
[actual publishable API keys](https://dashboard.stripe.com/account/apikeys) to
36-
test this code through your Stripe account.
31+
Weve placed a random API key in this example. Replace it with your [actual
32+
publishable API keys](https://dashboard.stripe.com/account/apikeys) to test
33+
this code through your Stripe account.
3734

38-
<br />
35+
For more information on how to use Stripe.js, please refer to the [Stripe.js
36+
API reference](https://stripe.com/docs/js) or learn to [accept
37+
a payment](https://stripe.com/docs/payments/accept-a-payment) with Stripe.
3938

40-
### `loadStripe()`
39+
### `loadStripe`
4140

42-
Use this function if you do not want to mess around with adding `<script>` tags,
43-
or want to speed up the initial load time on your site. It will inject the
44-
Stripe.js script tag for you and wait for it to load. For more information on
45-
how to use Stripe.js once it loads, please refer to the
46-
[Stripe.js API reference](https://stripe.com/docs/js) or learn to
47-
[accept a payment](https://stripe.com/docs/payments/accept-a-payment) with
48-
Stripe.
41+
This function returns a `Promise` that resolves with a newly created `Stripe`
42+
object once Stripe.js has loaded. If necessary, it will load Stripe.js for you
43+
by inserting the Stripe.js script tag.
4944

5045
```js
5146
import {loadStripe} from '@stripe/stripe-js';
5247

5348
const stripe = await loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx');
5449
```
5550

56-
Weve placed a random API key in the code. Replace it with your
57-
[actual publishable API keys](https://dashboard.stripe.com/account/apikeys) to
58-
test this code through your Stripe account.
51+
Weve placed a random API key in this example. Replace it with your [actual
52+
publishable API keys](https://dashboard.stripe.com/account/apikeys) to test
53+
this code through your Stripe account.
5954

60-
<br />
55+
For more information on how to use Stripe.js once it loads, please refer to the
56+
[Stripe.js API reference](https://stripe.com/docs/js) or learn to [accept
57+
a payment](https://stripe.com/docs/payments/accept-a-payment) with Stripe.
6158

6259
## Ensuring Stripe.js is available everywhere
6360

64-
To best leverage Stripe’s advanced fraud functionality, ensure that Stripe.js is
65-
loaded on every page, not just the checkout page. This allows Stripe to detect
66-
anomalous behavior that may be indicative of fraud as customers browse your
67-
website.
61+
To best leverage Stripe’s advanced fraud functionality, ensure that Stripe.js
62+
is loaded on every page, not just your checkout page. This allows Stripe to
63+
detect anomalous behavior that may be indicative of fraud as customers browse
64+
your website.
6865

6966
If you are adding the `<script>` tag manually, make sure you do so on every
70-
page. If you are relying on the script injection that this module provides, and
67+
page. If you are relying on the script insertion that this module provides, and
7168
you utilize code splitting or only include your JavaScript app on your checkout
7269
page, you will need to take extra steps to ensure Stripe.js is available
7370
everywhere.
@@ -76,25 +73,23 @@ everywhere.
7673

7774
Import `@stripe/stripe-js` as a side effect in code that will be included
7875
throughout your site (e.g. your root module). This will make sure the Stripe.js
79-
script tag is injected right away.
76+
script tag is inserted immediately upon page load.
8077

8178
```js
8279
import '@stripe/stripe-js';
8380
```
8481

8582
### Manually include the script tag
8683

87-
Manually add the Stripe.js script tag to the `<head>` of each page on your site.
88-
If you use `loadStripe`, it will use this script tag rather tha injecting a new
89-
one.
84+
Manually add the Stripe.js script tag to the `<head>` of each page on your
85+
site. If you use `loadStripe`, it will use this script tag rather than
86+
inserting a new one.
9087

9188
```html
9289
<!-- Somewhere in your site's <head> -->
9390
<script src="https://js.stripe.com/v3" async></script>
9491
```
9592

96-
<br />
97-
9893
## Stripe.js Documentation
9994

10095
- [Stripe.js Docs](https://stripe.com/docs/stripe-js)
@@ -103,5 +98,5 @@ one.
10398

10499
### Contributing
105100

106-
If you would like to contribute to React Stripe.js, please make sure to read our
107-
[contributor guidelines](CONTRIBUTING.md).
101+
If you would like to contribute to React Stripe.js, please make sure to read
102+
our [contributor guidelines](CONTRIBUTING.md).

0 commit comments

Comments
 (0)