Skip to content

Commit c18266c

Browse files
fix calling loadStripe on the server
1 parent 8ca8bba commit c18266c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const stripePromise = Promise.resolve().then(() => {
5151
let hasCalledLoadStripe = false;
5252
export const loadStripe = (...args) => {
5353
hasCalledLoadStripe = true;
54-
return stripePromise.then((Stripe) => Stripe(...args));
54+
return stripePromise.then((maybeStripe) =>
55+
maybeStripe ? maybeStripe(...args) : null
56+
);
5557
};
5658

5759
const STRIPE_NOT_LOADED_ERROR_TEXT = `Stripe.js has not yet loaded. Instead of calling \`Stripe\` directly, try using the \`loadStripe\` utility from this package.
@@ -74,7 +76,7 @@ const hasUserIncludedScript = () =>
7476
document.querySelector(`script[src="${V3_URL}"]`) && !hasInjectedScript;
7577

7678
export const Stripe = (...args) => {
77-
if (window.Stripe) {
79+
if (window && window.Stripe) {
7880
return window.Stripe(...args);
7981
}
8082

0 commit comments

Comments
 (0)