stripe-archive / react-stripe-elements

Moved to stripe/react-stripe-js.
https://github.com/stripe/react-stripe-js
MIT License
3.03k stars 319 forks source link

loadStripe does not seem to work #550

Closed zactham closed 3 years ago

zactham commented 3 years ago

The function itself works fine, but it never makes it past the await on stripPromise.


import { loadStripe } from '@stripe/stripe-js';
// Make sure to call `loadStripe` outside of a component’s render to avoid
// recreating the `Stripe` object on every render.
const stripePromise = loadStripe('key');

const purchaseClick = async (event) => 
    {

        // Get Stripe.js instance
        const stripe = await stripePromise;
        console.log("stripe promise")

        // Call your backend to create the Checkout Session
        const response = await fetch('/create-checkout-session', { method: 'POST' });

        const session = await response.json();

        // When the customer clicks on the button, redirect them to Checkout.
        const result = await stripe.redirectToCheckout(
        {
            sessionId: session.id,
        });

        if (result.error) 
        {
            // If `redirectToCheckout` fails due to a browser or network
            // error, display the localized error message to your customer
            // using `result.error.message`.
        }
    };