Stripe impossible to redirectToCheckout

Viewed 17

I tried to install both stripes packages (stripe & loadStripe), and looked at all the tutorials, but nothing seems to work for me.

with the old stripes package it says that redirectToCheckout is not a function :

import axios from 'axios';
import Stripe from 'stripe';
const stripe = new Stripe(
'pk_test_*****************************'
);

export const bookTour = async (tourId) => {
  try {
    const session = await axios(`
        http://127.0.0.1:3000/api/v1/bookings/checkout-session/${tourId}`);
    const sessionId = await session.data.session.id;
     await stripe.redirectToCheckout({
     sessionId,
    });
  } catch (err) {
    console.log(err);
  }
};

and with the new package that ain't even able to reach the catch to throw the error :

import axios from 'axios';

import { loadStripe } from '@stripe/stripe-js/pure';

export const bookTour = async (tourId) => {
  try {
    const session = await axios(`
        http://127.0.0.1:3000/api/v1/bookings/checkout-session/${tourId}`);
    const sessionId = await session.data.session.id;
    if (sessionId) {
      const stripe = await loadStripe(
        'pk_test_**************************'
      );
      stripe.redirectToCheckout({ sessionId });
    }
  } catch (err) {
    console.log(err);
  }
};
 
0 Answers
Related