mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 06:28:12 +00:00
added dmoney redirect
This commit is contained in:
@@ -0,0 +1,60 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useSearchParams, useRouter } from 'next/navigation';
|
||||||
|
import { usePaymentStore } from '@/lib/payment-store';
|
||||||
|
import { consumeManageBookingPaymentReturn } from '@/utils/manage-booking-return';
|
||||||
|
import { useEffect, useState, Suspense } from 'react';
|
||||||
|
import { XCircle, Loader2, ChevronLeft } from 'lucide-react';
|
||||||
|
|
||||||
|
function DmoneyFailureContent() {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const { updateStatus } = usePaymentStore();
|
||||||
|
// A Manage Booking payment (paying for an already-existing booking) has no in-progress
|
||||||
|
// booking-store session to go "back to review" from — send it back to that booking's
|
||||||
|
// detail view instead, where the user can pick a different payment method.
|
||||||
|
const [backTarget, setBackTarget] = useState('/booking/review');
|
||||||
|
|
||||||
|
// D-Money callback query params (mirrors Telebirr)
|
||||||
|
const merchantOrderId = searchParams.get('merchantOrderId') || '';
|
||||||
|
const trxRef = searchParams.get('trxRef') || searchParams.get('outTradeNo') || '';
|
||||||
|
const resultCode = searchParams.get('resultCode') || searchParams.get('code') || '';
|
||||||
|
const resultMsg = searchParams.get('resultMsg') || searchParams.get('message') || 'Payment was not completed.';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const manageBookingRef = consumeManageBookingPaymentReturn();
|
||||||
|
if (manageBookingRef) {
|
||||||
|
setBackTarget(`/booking/detail?ref=${encodeURIComponent(manageBookingRef)}`);
|
||||||
|
}
|
||||||
|
updateStatus('FAILED');
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-gray-50 dark:bg-gray-900 flex items-center justify-center px-4">
|
||||||
|
<div className="bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8 max-w-md w-full text-center">
|
||||||
|
<XCircle className="w-14 h-14 text-red-500 mx-auto mb-4" />
|
||||||
|
<h1 className="text-xl font-bold text-gray-900 dark:text-white mb-2">Payment Failed</h1>
|
||||||
|
<p className="text-sm text-gray-500 dark:text-gray-400 mb-1">{resultMsg}</p>
|
||||||
|
{resultCode && <p className="text-xs text-gray-400 mb-1">Code: {resultCode}</p>}
|
||||||
|
{merchantOrderId && <p className="text-xs text-gray-400 mb-1">Order ID: {merchantOrderId}</p>}
|
||||||
|
{trxRef && <p className="text-xs text-gray-400 mb-4">Ref: {trxRef}</p>}
|
||||||
|
<div className="flex flex-col gap-3 mt-4">
|
||||||
|
<button onClick={() => router.push(backTarget)}
|
||||||
|
className="btn-secondary w-full flex items-center justify-center gap-2">
|
||||||
|
<ChevronLeft className="w-4 h-4" />
|
||||||
|
Back
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DmoneyFailurePage() {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<div className="min-h-screen flex items-center justify-center"><Loader2 className="w-10 h-10 animate-spin text-primary" /></div>}>
|
||||||
|
<DmoneyFailureContent />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user