feat: enhance payment flow with dynamic URL handling and improved error messaging
This commit is contained in:
@@ -61,15 +61,17 @@ function Paying({ setStep, appointmentId, expiresAt, doctor, data, isForAnother,
|
||||
gateway: testMode ? "mellat" : selectedBank,
|
||||
frontend_address: `${window.location.origin}/payment/result`,
|
||||
});
|
||||
// به بکاند میرویم؛ آنجا صلاحیت تأیید و به درگاه بانک منتقل میشود.
|
||||
const payUrl = res?.data?.pay_url || res?.data?.redirect_url;
|
||||
// فقط به بکاند میرویم؛ بکاند صلاحیت را تأیید و به درگاه بانک منتقل میکند.
|
||||
// کلاینت هرگز مستقیم به بانک ریکوست نمیزند.
|
||||
const payUrl = res?.data?.pay_url;
|
||||
if (payUrl) {
|
||||
window.location.href = payUrl;
|
||||
} else {
|
||||
setStep((prev) => prev + 1);
|
||||
return;
|
||||
}
|
||||
throw new Error("pay_url missing");
|
||||
} catch (error) {
|
||||
console.error("Payment error:", error);
|
||||
alert("خطا در شروع پرداخت. لطفاً دوباره تلاش کنید.");
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user