@stripe/stripe-js
Advanced tools
Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
@@ -51,4 +51,4 @@ var V3_URL = 'https://js.stripe.com/v3'; | ||
hasCalledLoadStripe = true; | ||
return stripePromise.then(function (Stripe) { | ||
return Stripe.apply(void 0, args); | ||
return stripePromise.then(function (maybeStripe) { | ||
return maybeStripe ? maybeStripe.apply(void 0, args) : null; | ||
}); | ||
@@ -64,3 +64,3 @@ }; | ||
var Stripe = function Stripe() { | ||
if (window.Stripe) { | ||
if (window && window.Stripe) { | ||
var _window; | ||
@@ -67,0 +67,0 @@ |
@@ -55,4 +55,4 @@ 'use strict'; | ||
hasCalledLoadStripe = true; | ||
return stripePromise.then(function (Stripe) { | ||
return Stripe.apply(void 0, args); | ||
return stripePromise.then(function (maybeStripe) { | ||
return maybeStripe ? maybeStripe.apply(void 0, args) : null; | ||
}); | ||
@@ -68,3 +68,3 @@ }; | ||
var Stripe = function Stripe() { | ||
if (window.Stripe) { | ||
if (window && window.Stripe) { | ||
var _window; | ||
@@ -71,0 +71,0 @@ |
{ | ||
"name": "@stripe/stripe-js", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "Stripe.js loading utility", | ||
@@ -5,0 +5,0 @@ "main": "dist/stripe.js", |
@@ -1,16 +0,17 @@ | ||
# ES Module for Stripe.js | ||
# Stripe.js ES Module | ||
Import and use [Stripe.js](https://stripe.com/docs/stripe-js) as an ES module. | ||
Use [Stripe.js](https://stripe.com/docs/stripe-js) as an ES module. | ||
**Note**: For compliance reasons, Stripe.js must be loaded directly from | ||
`https://js.stripe.com`, and cannot be included in a bundle or hosted yourself. | ||
This package wraps the global `Stripe` function provided by the Stripe.js | ||
script as an ES module. | ||
[![npm version](https://img.shields.io/npm/v/@stripe/stripe-js.svg?style=flat-square)](https://www.npmjs.com/package/@stripe/stripe-js) | ||
Stripe.js cannot be bundled with your code; it must be served from | ||
**https//js</span>.<span>stripe</span>.<span>com/v3**. This module wraps the | ||
global `Stripe` function provided by the Stripe.js script. If needed, it will | ||
inject the script for you and provide a loading wrapper. | ||
## Usage | ||
### `Stripe()` | ||
### `Stripe` | ||
To use the exported `Stripe()` function, first include the Stripe.js script on | ||
To use the exported `Stripe` function, first include the Stripe.js script on | ||
each page of your site. | ||
@@ -22,7 +23,3 @@ | ||
Then import and use Stripe.js as you would any other module. For more | ||
information on how to use Stripe.js, please refer to the | ||
[Stripe.js API reference](https://stripe.com/docs/js) or learn to | ||
[accept a payment](https://stripe.com/docs/payments/accept-a-payment) with | ||
Stripe. | ||
Then import and use Stripe.js as you would any other module. | ||
@@ -35,17 +32,15 @@ ```js | ||
We‘ve placed a random API key in the code. Replace it with your | ||
[actual publishable API keys](https://dashboard.stripe.com/account/apikeys) to | ||
test this code through your Stripe account. | ||
We’ve placed a random API key in this example. Replace it with your [actual | ||
publishable API keys](https://dashboard.stripe.com/account/apikeys) to test | ||
this code through your Stripe account. | ||
<br /> | ||
For more information on how to use Stripe.js, please refer to the [Stripe.js | ||
API reference](https://stripe.com/docs/js) or learn to [accept | ||
a payment](https://stripe.com/docs/payments/accept-a-payment) with Stripe. | ||
### `loadStripe()` | ||
### `loadStripe` | ||
Use this function if you do not want to mess around with adding `<script>` tags, | ||
or want to speed up the initial load time on your site. It will inject the | ||
Stripe.js script tag for you and wait for it to load. For more information on | ||
how to use Stripe.js once it loads, please refer to the | ||
[Stripe.js API reference](https://stripe.com/docs/js) or learn to | ||
[accept a payment](https://stripe.com/docs/payments/accept-a-payment) with | ||
Stripe. | ||
This function returns a `Promise` that resolves with a newly created `Stripe` | ||
object once Stripe.js has loaded. If necessary, it will load Stripe.js for you | ||
by inserting the Stripe.js script tag. | ||
@@ -58,17 +53,19 @@ ```js | ||
We‘ve placed a random API key in the code. Replace it with your | ||
[actual publishable API keys](https://dashboard.stripe.com/account/apikeys) to | ||
test this code through your Stripe account. | ||
We’ve placed a random API key in this example. Replace it with your [actual | ||
publishable API keys](https://dashboard.stripe.com/account/apikeys) to test | ||
this code through your Stripe account. | ||
<br /> | ||
For more information on how to use Stripe.js once it loads, please refer to the | ||
[Stripe.js API reference](https://stripe.com/docs/js) or learn to [accept | ||
a payment](https://stripe.com/docs/payments/accept-a-payment) with Stripe. | ||
## Ensuring Stripe.js is available everywhere | ||
To best leverage Stripe’s advanced fraud functionality, ensure that Stripe.js is | ||
loaded on every page, not just the checkout page. This allows Stripe to detect | ||
anomalous behavior that may be indicative of fraud as customers browse your | ||
website. | ||
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 anomalous behavior that may be indicative of fraud as customers browse | ||
your website. | ||
If you are adding the `<script>` tag manually, make sure you do so on every | ||
page. If you are relying on the script injection that this module provides, and | ||
page. If you are relying on the script insertion that this module provides, and | ||
you utilize code splitting or only include your JavaScript app on your checkout | ||
@@ -82,3 +79,3 @@ page, you will need to take extra steps to ensure Stripe.js is available | ||
throughout your site (e.g. your root module). This will make sure the Stripe.js | ||
script tag is injected right away. | ||
script tag is inserted immediately upon page load. | ||
@@ -91,5 +88,5 @@ ```js | ||
Manually add the Stripe.js script tag to the `<head>` of each page on your site. | ||
If you use `loadStripe`, it will use this script tag rather tha injecting a new | ||
one. | ||
Manually add the Stripe.js script tag to the `<head>` of each page on your | ||
site. If you use `loadStripe`, it will use this script tag rather than | ||
inserting a new one. | ||
@@ -101,4 +98,2 @@ ```html | ||
<br /> | ||
## Stripe.js Documentation | ||
@@ -112,3 +107,3 @@ | ||
If you would like to contribute to React Stripe.js, please make sure to read our | ||
[contributor guidelines](CONTRIBUTING.md). | ||
If you would like to contribute to React Stripe.js, please make sure to read | ||
our [contributor guidelines](CONTRIBUTING.md). |
@@ -54,3 +54,5 @@ const V3_URL = 'https://js.stripe.com/v3'; | ||
hasCalledLoadStripe = true; | ||
return stripePromise.then((Stripe) => Stripe(...args)); | ||
return stripePromise.then((maybeStripe) => | ||
maybeStripe ? maybeStripe(...args) : null | ||
); | ||
}; | ||
@@ -78,3 +80,3 @@ | ||
export const Stripe = (...args) => { | ||
if (window.Stripe) { | ||
if (window && window.Stripe) { | ||
return window.Stripe(...args); | ||
@@ -81,0 +83,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18848
309
103