diff --git a/app/(defaults)/payment/cancel/page.tsx b/app/(defaults)/payment/cancel/page.tsx new file mode 100644 index 0000000..63fb6a2 --- /dev/null +++ b/app/(defaults)/payment/cancel/page.tsx @@ -0,0 +1,25 @@ +"use client"; + +// import { Metadata } from "next"; +import React, { useEffect } from "react"; +import { useRouter } from "next/navigation"; + +// export const metadata: Metadata = { +// title: "CrawlerX", +// }; + +const PaymentCancel = () => { + const router = useRouter(); + + useEffect(() => { + const token = localStorage.getItem("token"); + if (!token) { + // If no token, redirect to login page + router.push("/login"); + } + }, [router]); + + return
Payment Cancel
; +}; + +export default PaymentCancel; diff --git a/app/(defaults)/payment/success/page.tsx b/app/(defaults)/payment/success/page.tsx new file mode 100644 index 0000000..c6795a0 --- /dev/null +++ b/app/(defaults)/payment/success/page.tsx @@ -0,0 +1,25 @@ +"use client"; + +// import { Metadata } from "next"; +import React, { useEffect } from "react"; +import { useRouter } from "next/navigation"; + +// export const metadata: Metadata = { +// title: "CrawlerX", +// }; + +const PaymentSuccess = () => { + const router = useRouter(); + + useEffect(() => { + const token = localStorage.getItem("token"); + if (!token) { + // If no token, redirect to login page + router.push("/login"); + } + }, [router]); + + return
Payment Success
; +}; + +export default PaymentSuccess; diff --git a/components/pricing-table/components-pricing-table-toggle.tsx b/components/pricing-table/components-pricing-table-toggle.tsx index 014ec25..38a8f9d 100644 --- a/components/pricing-table/components-pricing-table-toggle.tsx +++ b/components/pricing-table/components-pricing-table-toggle.tsx @@ -14,11 +14,11 @@ interface Plan { planId: string; } -// ⚡ Lazy load Stripe to avoid undefined.match errors +// ⚡ Lazy load Stripe let stripePromise: Promise | null = null; const getStripe = () => { if (!stripePromise) { - const key = process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY; + const key = "pk_test_51SB8SnIFk8fh986Gfv0gq9ggpjTO2RiSyIK9VHaonLdLMSOmJf51dGAu8yzwsRKrKwtvauchhD1cJ5Q8dTzMSZ5E00oSdbYBXO"; if (!key) throw new Error('Stripe publishable key is not defined!'); stripePromise = loadStripe(key); } @@ -27,6 +27,7 @@ const getStripe = () => { const ComponentsPricingTableToggle: React.FC = () => { const [yearlyPrice, setYearlyPrice] = useState(false); + const [email, setEmail] = useState(''); const plans: Plan[] = [ { @@ -61,17 +62,24 @@ const ComponentsPricingTableToggle: React.FC = () => { // 🔹 Stripe Checkout handler const handleBuyNow = async (plan: Plan) => { + // if (!email) { + // alert("Please enter your email before checkout"); + // return; + // } + try { const stripe = await getStripe(); if (!stripe) return; + const amount = yearlyPrice ? plan.yearly : plan.monthly; + // 🔹 Call backend API to create Checkout Session const { data } = await axios.post( - 'https://api.crawlerx.co/api/payment/create-intent', + 'https://api.crawlerx.co/api/payment/create-checkout-session', { + email:"alaguraj0361@gmail.com", + amount, planId: plan.planId, - price: yearlyPrice ? plan.yearly : plan.monthly, - billing: yearlyPrice ? 'yearly' : 'monthly', } ); @@ -83,6 +91,7 @@ const ComponentsPricingTableToggle: React.FC = () => { // 🔹 Redirect to Stripe Checkout const { error } = await stripe.redirectToCheckout({ sessionId: data.sessionId }); if (error) console.error('Stripe redirect error:', error.message); + } catch (err: any) { console.error('Error creating checkout session:', err.response?.data || err.message); } @@ -91,7 +100,19 @@ const ComponentsPricingTableToggle: React.FC = () => { return (
- {/* Toggle */} + + {/* Email Input */} +
+ setEmail(e.target.value)} + className="border rounded p-2 w-80" + /> +
+ + {/* Toggle Monthly / Yearly */}
Monthly - + Yearly 20% Off