From 5751638f7b6b916178a9690ad3739df11a7bb261 Mon Sep 17 00:00:00 2001 From: erio Date: Sun, 1 Mar 2026 18:15:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20handle=20cancel=20when=20order=20already?= =?UTF-8?q?=20paid=20=E2=80=94=20check=20status=20immediately?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When cancel API returns error (order already PAID/COMPLETED), immediately re-poll the order status instead of silently doing nothing. Also check terminal status before attempting cancel to avoid unnecessary API call. --- src/components/PaymentQRCode.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/PaymentQRCode.tsx b/src/components/PaymentQRCode.tsx index bce2a7c..931c7cd 100644 --- a/src/components/PaymentQRCode.tsx +++ b/src/components/PaymentQRCode.tsx @@ -138,6 +138,13 @@ export default function PaymentQRCode({ const res = await fetch(`/api/orders/${orderId}`); if (!res.ok) return; const data = await res.json(); + + // If the order already reached a terminal status, handle it immediately + if (TERMINAL_STATUSES.has(data.status)) { + onStatusChange(data.status); + return; + } + const cancelRes = await fetch(`/api/orders/${orderId}/cancel`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -145,6 +152,9 @@ export default function PaymentQRCode({ }); if (cancelRes.ok) { onStatusChange('CANCELLED'); + } else { + // Cancel failed (e.g. order was paid between the two requests) — re-check status + await pollStatus(); } } catch { // ignore