diff --git a/src/app/(investment)/invest/[id]/checkoutPage.tsx b/src/app/(investment)/invest/[id]/checkoutPage.tsx index d930ca7..e682adf 100644 --- a/src/app/(investment)/invest/[id]/checkoutPage.tsx +++ b/src/app/(investment)/invest/[id]/checkoutPage.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useEffect, useState } from "react"; -import { useStripe, useElements, CardElement } from "@stripe/react-stripe-js"; +import { useStripe, useElements, CardNumberElement, CardCvcElement, CardExpiryElement } from "@stripe/react-stripe-js"; import convertToSubcurrency from "@/lib/convertToSubcurrency"; import { Dialog, @@ -15,7 +15,8 @@ import { } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { createSupabaseClient } from "@/lib/supabase/clientComponentClient"; -import { useRouter } from "next/navigation"; +import Link from "next/link"; +import toast from "react-hot-toast"; const CheckoutPage = ({ amount, @@ -34,8 +35,8 @@ const CheckoutPage = ({ const [clientSecret, setClientSecret] = useState(""); const [loading, setLoading] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); + const [isSuccessDialogOpen, setIsSuccessDialogOpen] = useState(false); // New success dialog state const isAcceptTerm = isAcceptTermAndService(); - const router = useRouter(); useEffect(() => { fetch("/api/create-payment-intent", { @@ -68,7 +69,7 @@ const CheckoutPage = ({ await stripe .confirmCardPayment(clientSecret, { payment_method: { - card: elements.getElement(CardElement)!, + card: elements.getElement(CardNumberElement)!, }, }) .then(async (result) => { @@ -86,12 +87,15 @@ const CheckoutPage = ({ ]); if (error) { + toast.error("Unexpected error with server"); console.error("Supabase Insert Error:", error.message); } else { console.log("Insert successful:", data); - router.push(`http://www.localhost:3000/payment-success?amount=${amount}`); + toast.success("Invest successfully"); + setIsSuccessDialogOpen(true); } } catch (err) { + toast.error("Unexpected error with server"); console.error("Unexpected error during Supabase insert:", err); } } @@ -116,7 +120,70 @@ const CheckoutPage = ({ return (
{errorMessage}
} + + {/* Success Dialog */} +