import React, { useState, useEffect } from "react"; import { loadStripe } from "@stripe/stripe-js"; import { EmbeddedCheckoutProvider, EmbeddedCheckout, } from "@stripe/react-stripe-js"; import { Navigate } from "react-router-dom"; const API_URL = import.meta.env.VITE_API_URL; // Initialize Stripe once const stripePromise = loadStripe(import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY); export const Return: React.FC = () => { const [status, setStatus] = useState(null); const [customerEmail, setCustomerEmail] = useState(""); useEffect(() => { const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const sessionId = urlParams.get("session_id"); if (sessionId) { console.log("1") fetch(`/api/session-status?session_id=${sessionId}`) .then((res) => res.json()) .then((data) => { console.log("Response Data:", data); setStatus(data.status); setCustomerEmail(data.customer_email); }); } }, []); if (status === "open") { return ; } if (status === "complete") { return (

We appreciate your business! A confirmation email will be sent to{" "} {customerEmail}. If you have any questions, please email{" "} orders@example.com.

); } return null; }; // Main CheckoutForm component interface CheckoutFormProps { streamerID: number; onClose: () => void; } const CheckoutForm: React.FC = ({ onClose, streamerID }) => { const fetchClientSecret = () => { return fetch(`/api/create-checkout-session?streamer_id=${streamerID}`, { method: "POST", }) .then((res) => res.json()) .then((data) => data.clientSecret); }; const options = { fetchClientSecret }; return ( <>
); }; export default CheckoutForm;