fix: cancel order handles already-paid case
This commit is contained in:
@@ -138,6 +138,13 @@ export default function PaymentQRCode({
|
|||||||
const res = await fetch(`/api/orders/${orderId}`);
|
const res = await fetch(`/api/orders/${orderId}`);
|
||||||
if (!res.ok) return;
|
if (!res.ok) return;
|
||||||
const data = await res.json();
|
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`, {
|
const cancelRes = await fetch(`/api/orders/${orderId}/cancel`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -145,6 +152,9 @@ export default function PaymentQRCode({
|
|||||||
});
|
});
|
||||||
if (cancelRes.ok) {
|
if (cancelRes.ok) {
|
||||||
onStatusChange('CANCELLED');
|
onStatusChange('CANCELLED');
|
||||||
|
} else {
|
||||||
|
// Cancel failed (e.g. order was paid between the two requests) — re-check status
|
||||||
|
await pollStatus();
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user