feat: enhance payment flow with dynamic URL handling and improved error messaging

This commit is contained in:
hamed
2026-07-02 15:36:09 +03:30
parent 9e67ce4872
commit e83a666adb
4 changed files with 130 additions and 25 deletions
+6 -4
View File
@@ -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);
}
};