import { useState, useEffect } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { t } from "@/utils"; import RazorpayPayment from "./RazorpayPayment"; import PayStackPayment from "./PayStackPayment"; import FlutterwavePayment from "./FlutterwavePayment"; import PhonepePayment from "./PhonepePayment"; import StripePayment from "./StripePayment"; import StripeLogo from "../../../public/assets/ic_stripe.png"; import { FaAngleRight } from "react-icons/fa"; import PaymentModalLoading from "./PaymentModalLoading"; import { toast } from "sonner"; import BankTransferPayment from "./BankTransferPayment"; import CustomImage from "@/components/Common/CustomImage"; import PaypalPayment from "./PaypalPayment"; const PaymentModal = ({ showPaymentModal, setShowPaymentModal, selectedPackage, packageSettings, isLoading, setToggleApiAfterPaymentSuccess }) => { const [showStripePayment, setShowStripePayment] = useState(false); const isBankTransferActive = Number(packageSettings?.bankTransfer?.status) === 1; const PaymentModalClose = () => { setShowPaymentModal(false); setShowStripePayment(false); }; const handleMessage = (event) => { if (event.origin === process.env.NEXT_PUBLIC_API_URL) { const { status } = event.data; if (status === "success") { toast.success(t("paymentSuccess")); setToggleApiAfterPaymentSuccess((prev) => !prev) } else if (status === "cancel") { toast.error(t("paymentCancelled")); } else { toast.error(t("paymentFailed")); } PaymentModalClose(); } }; useEffect(() => { window.addEventListener("message", handleMessage); return () => { window.removeEventListener("message", handleMessage); }; }, [handleMessage]); return (