'use client'; import { Suspense, useEffect, useState } from 'react'; import { useSearchParams, useRouter } from 'next/navigation'; import Link from 'next/link'; function SuccessContent() { const params = useSearchParams(); const router = useRouter(); const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading'); const [errorMsg, setErrorMsg] = useState(''); const [productName, setProductName] = useState(''); useEffect(() => { const paymentKey = params.get('paymentKey'); const orderId = params.get('orderId'); const amount = Number(params.get('amount')); const returnUrl = params.get('returnUrl'); if (!paymentKey || !orderId || !amount) { setStatus('error'); setErrorMsg('잘못된 접근입니다.'); return; } fetch('/api/payment/confirm', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ paymentKey, orderId, amount }), }) .then((res) => res.json()) .then((data) => { if (data.success) { setProductName(data.data?.orderName ?? ''); setStatus('success'); if (returnUrl) { router.replace(returnUrl); } } else { setStatus('error'); setErrorMsg(data.error || '결제 승인에 실패했습니다.'); } }) .catch(() => { setStatus('error'); setErrorMsg('서버 오류가 발생했습니다. 결제 내역을 확인해주세요.'); }); }, []); if (status === 'loading') { return (

결제를 확인하는 중...

); } if (status === 'error') { return (

결제 처리 실패

{errorMsg}

결제 내역 확인 홈으로 →
); } return (
결제 완료

결제가 완료되었습니다!

{productName && (

{productName}

)}

마이페이지에서 결제 내역과 서비스 이용 현황을 확인하세요.

결제 내역 확인 → 홈으로
); } export default function PaymentSuccessPage() { return (
쟁승메이드 결제
}>
); }