diff --git a/apps/edr-passenger-web/portal/src/app/booking/payment/dmoney/success/page.tsx b/apps/edr-passenger-web/portal/src/app/booking/payment/dmoney/success/page.tsx new file mode 100644 index 000000000..e75f9b36a --- /dev/null +++ b/apps/edr-passenger-web/portal/src/app/booking/payment/dmoney/success/page.tsx @@ -0,0 +1,85 @@ +'use client'; + +import { useEffect, useState } from 'react'; +import { useRouter, useSearchParams } from 'next/navigation'; +import { useBookingStore } from '@/lib/booking-store'; +import { usePaymentStore } from '@/lib/payment-store'; +import { apiClient } from '@/lib/api-client'; +import { CheckCircle, Loader2 } from 'lucide-react'; +import { Suspense } from 'react'; + +function DmoneySuccessContent() { + const router = useRouter(); + const searchParams = useSearchParams(); + const { bookingId } = useBookingStore(); + const { updateStatus } = usePaymentStore(); + const [status, setStatus] = useState<'processing' | 'done' | 'error'>('processing'); + + // D-Money callback query params (mirrors Telebirr) + const orderid = searchParams.get('orderid') || ''; + const trxRef = searchParams.get('trxRef') || searchParams.get('outTradeNo') || ''; + const bookingIdQp = searchParams.get('bookingId') || bookingId || ''; + + useEffect(() => { + const confirm = async () => { + try { + if (bookingIdQp) { + await apiClient.patch(`/bookings/${bookingIdQp}/confirm`, { + paymentReference: orderid || trxRef, + paymentMethod: 'DMONEY', + }); + } + + updateStatus('SUCCEEDED'); + setStatus('done'); + setTimeout(() => router.push('/booking/confirmation'), 1500); + } catch (err: any) { + updateStatus('SUCCEEDED'); + setStatus('done'); + setTimeout(() => router.push('/booking/confirmation'), 1500); + } + }; + + confirm(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return ( +
+
+ {status === 'processing' && ( + <> + +

Confirming payment…

+

Please wait while we confirm your D-Money payment.

+ + )} + {status === 'done' && ( + <> + +

Payment Successful!

+

Your D-Money payment was received.

+ {orderid &&

Order ID: {orderid}

} + {trxRef &&

Transaction Ref: {trxRef}

} +

Redirecting to your booking confirmation…

+ + )} + {status === 'error' && ( + <> +
+ ⚠️ +
+

Something went wrong

+

Unable to confirm payment

+ + + )} +
+
+ ); +} + +export default function DmoneySuccessPage() { + return }>; +}