update payment flow

This commit is contained in:
Jelaletdin12
2026-09-25 21:39:40 +05:00
parent 9e2a2606c9
commit 8dc61d7786
2 changed files with 83 additions and 17 deletions

View File

@@ -30,6 +30,9 @@ const MONTHS = [
/** Digits with optional decimal part (max 2 digits). Accepts "." or ",". */
const AMOUNT_PATTERN = /^\d*([.,]\d{0,2})?$/;
// Shared channel name — must match the callback page exactly.
const PAYMENT_CHANNEL_NAME = "visa-master-payment";
// ─── Helpers ──────────────────────────────────────────────────────────────────
function currentMonthValue(): string {
@@ -308,6 +311,26 @@ export function PayDialog({ id, open, onOpenChange }: PayDialogProps) {
stopWatchingBankPage();
}, [id, stableId]);
// Listens for the callback tab/popup broadcasting the final result. This is
// the primary sync path: it's instant and doesn't depend on the popup still
// being open or the URL-watch polling above succeeding.
useEffect(() => {
if (typeof BroadcastChannel === "undefined") return;
const channel = new BroadcastChannel(PAYMENT_CHANNEL_NAME);
channel.onmessage = (event) => {
const msg = event.data as { type?: string; paymentId?: number; paid?: boolean; message?: string } | undefined;
if (!msg || msg.type !== "PAYMENT_RESULT") return;
if (!paymentInit?.paymentId || msg.paymentId !== paymentInit.paymentId) return;
setPaymentResult({ paid: !!msg.paid, data: msg.message ?? "" });
stopWatchingBankPage();
popupRef.current?.close();
};
return () => channel.close();
}, [paymentInit?.paymentId]);
// Block every close path (ESC, overlay click, X button) while the payment request is in flight.
function handleOpenChange(next: boolean) {
if (isPaying || isChecking) return;