You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

use-stripe.js 775B

123456789101112131415161718192021222324252627282930
  1. import { loadStripe } from '@stripe/stripe-js';
  2. export const useStripe = async ({ lineItems, userInfo }) => {
  3. let stripePromise = null;
  4. const getStripe = () => {
  5. if (!stripePromise) {
  6. stripePromise = loadStripe(process.env.NEXT_PUBLIC_API_KEY);
  7. }
  8. return stripePromise;
  9. };
  10. const stripe = await getStripe();
  11. await stripe.redirectToCheckout({
  12. mode: 'payment',
  13. customer_email: userInfo.email,
  14. metadata: {
  15. name: userInfo.fullName,
  16. address: userInfo.address,
  17. addressLine2: userInfo.address2,
  18. city: userInfo.city,
  19. country: userInfo.country,
  20. postcode: userInfo.postcode,
  21. },
  22. lineItems,
  23. successUrl: `${window.location.origin}/review`,
  24. cancelUrl: `${window.location.origin}/cart`,
  25. });
  26. };