I am trying to implement Stripe checkout for a website. Unfortunately, the Stripe docs are very incomplete. I have:
import React from 'react';
import { loadStripe } from '@stripe/stripe-js';
const stripe = loadStripe('pk_test_key');
const handleClick = async (event) => {
stripe.redirectToCheckout({
lineItems: [
{price: 'price_something', quantity: 1},
],
mode: 'subscription',
successUrl: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
cancelUrl: 'https://example.com/cancel',
}).then(function(result){
alert(result);
});
};
export default function Stripe(){
return (
<button role="link" onClick={handleClick}>
Checkout
</button>
);
}
I click the button and I get an error: Unhandled Rejection (TypeError): stripe.redirectToCheckout is not a function
My key is correct one but I cannot find any information in their docs or anywhere else to solve this. Thanks!