import React from "react"; import { useNavigate } from "react-router-dom"; import { Elements } from "@stripe/react-stripe-js"; import { Stripe, loadStripe } from "@stripe/stripe-js"; import "./premium-bundle-screen.css"; import routes from "@/routes"; import HeaderLogo from "@/components/palmistry/header-logo/header-logo"; import { useApi } from "@/api"; import { useAuth } from "@/auth"; import CheckoutForm from "@/components/PaymentPage/methods/CheckoutForm"; import { ResponseGet } from "@/api/resources/SinglePayment"; import Loader, { LoaderColor } from "@/components/Loader"; import {useSelector} from "react-redux"; import {selectors} from "@/store"; import {addCurrency} from "@/locales"; const currentProductKey = "premium.bundle.aura"; const returnUrl = window.location.host; export default function PremiumBundleScreen() { const navigate = useNavigate(); const { token, user } = useAuth(); const api = useApi(); const [stripePromise, setStripePromise] = React.useState | null>(null); const [product, setProduct] = React.useState(); const [isSuccess] = React.useState(false); const [clientSecret, setClientSecret] = React.useState(null); const [stripePublicKey, setStripePublicKey] = React.useState(""); const [isLoading, setIsLoading] = React.useState(false); const currency = useSelector(selectors.selectCurrency); React.useEffect(() => { (async () => { const products = await api.getSinglePaymentProducts({ token }); const product = products.find( (product) => product.key === currentProductKey ); if (product) { setProduct(product); } })(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); React.useEffect(() => { if (!stripePublicKey) return; setStripePromise(loadStripe(stripePublicKey)); }, [stripePublicKey]); const buy = async () => { if (!user?.id || !product) return; const { _id, key } = product; try { setIsLoading(true); const response = await api.createSinglePayment({ token: token, data: { user: { id: user.id, email: user.email, name: user.username || "", sign: user.profile?.sign?.sign || "", age: user.profile.age?.years || 0, }, partner: { sign: "", age: 0, }, paymentInfo: { productId: _id, key, }, return_url: returnUrl, }, }); if ( ("paymentIntent" in response && response.paymentIntent.status === "paid") || ("payment" in response && response.payment.status === "paid") || ("invoiceId" in response && response.invoiceId === "paid") ) { goHome(); } else if ("paymentIntent" in response) { setClientSecret(response.paymentIntent.data.client_secret); setStripePublicKey(response.paymentIntent.data.public_key); } } catch (error) { console.log("Error: ", error); } finally { setIsLoading(false); } }; const goHome = () => { navigate(routes.client.home()); }; return (
Get extra insights with our Premium Bundle Exclusive offer: recommended for get more insights about what future holds for you.
What your Premium Bundle will include:

Guide to Modern Astrology

Annual Forecast for 2024

One-time price of {addCurrency(19, currency)}!

Original price is {addCurrency(45, currency)}. Save 58%!

These plans are yours to keep even if you decide Hint isn’t right for you.

{stripePromise && clientSecret && (
{isSuccess && (
Payment success
)}
)}
); }