"use client" import { Suspense, useEffect, useState } from "react" import { useSearchParams } from "next/navigation" import { Check, X, Loader2 } from "lucide-react" import { Card, CardContent } from "@/components/ui/card" import { Button } from "@/components/ui/button" import Link from "next/link" interface PledgeInfo { reference: string amountPence: number rail: string donorName: string | null eventName: string status: string } function SuccessContent() { const searchParams = useSearchParams() const pledgeId = searchParams.get("pledge_id") const rail = searchParams.get("rail") || "card" const cancelled = searchParams.get("cancelled") === "true" const [pledge, setPledge] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { if (!pledgeId) { setLoading(false); return } fetch(`/api/pledges/${pledgeId}`) .then((r) => r.json()) .then((data) => { if (data.reference) setPledge(data) }) .catch(() => {}) .finally(() => setLoading(false)) }, [pledgeId]) if (loading) { return (

Confirming your payment...

) } if (cancelled) { return (

Payment Cancelled

Your payment was not completed. Your pledge has been saved — you can return to complete it anytime.

{pledge && (
Reference {pledge.reference}
Amount £{(pledge.amountPence / 100).toFixed(2)}
)}
) } const railLabels: Record = { card: "Card Payment", gocardless: "Direct Debit", fpx: "FPX Online Banking", bank: "Bank Transfer", } const nextStepMessages: Record = { card: "Your card payment has been processed. You'll receive a confirmation email shortly.", gocardless: "Your Direct Debit mandate has been set up. The payment will be collected automatically in 3-5 working days.", fpx: "Your FPX payment has been received and verified.", bank: "Please complete the bank transfer using the reference provided.", } return (

{rail === "gocardless" ? "Mandate Set Up!" : "Payment Successful!"}

Thank you for your generous donation {pledge?.eventName && <> to {pledge.eventName}}

{pledge && (
Amount £{(pledge.amountPence / 100).toFixed(2)}
Method {railLabels[rail] || rail}
Reference {pledge.reference}
{pledge.donorName && (
Donor {pledge.donorName}
)}
)}

What happens next?

{nextStepMessages[rail] || nextStepMessages.card}

Need help? Contact the charity directly.{pledge && <> Ref: {pledge.reference}}

) } export default function SuccessPage() { return (

Loading...

}> ) }