Merge pull request 'issue 6 : fix payment-cancel-handling' (#16) from fix/issue-6-payment-cancel-handling into main

Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-store-ui/pulls/16
This commit is contained in:
Amit Salunke 2026-10-06 12:18:44 +00:00
commit c2cc4202a7
1 changed files with 22 additions and 0 deletions

View File

@ -638,6 +638,9 @@ export default function App() {
}
}
let isPaymentCancelled = false;
let isPaymentCompleted = false;
const rzpOptions = {
key: razorpayKeyId,
amount: Math.round(grand_total * 100),
@ -651,7 +654,25 @@ export default function App() {
email: loggedInUser?.email || '',
contact: loggedInUser?.phone_number || loggedInUser?.phone || ''
},
modal: {
confirm_close: true,
escape: true,
backdropclose: false,
ondismiss: function () {
if (!isPaymentCompleted) {
isPaymentCancelled = true;
setCheckoutLoading(false);
console.log('Razorpay payment modal dismissed / cancelled by user.');
}
}
},
handler: async function (response: any) {
if (isPaymentCancelled) {
console.warn('Payment was cancelled by the user. Verification ignored.');
setCheckoutLoading(false);
return;
}
isPaymentCompleted = true;
setCheckoutLoading(true);
try {
const verifyRes = await axios.post(`${API_BASE}/api/checkout/verify`, {
@ -709,6 +730,7 @@ export default function App() {
const razorpayInstance = new (window as any).Razorpay(rzpOptions);
razorpayInstance.on('payment.failed', function (resp: any) {
setCheckoutLoading(false);
alert(`Payment failed! Reason: ${resp.error.description}`);
});
razorpayInstance.open();