feat: refactor payment handling to use direct backend redirect instead of API call

This commit is contained in:
hamed
2026-07-02 17:08:52 +03:30
parent e83a666adb
commit e6b55c6bad
4 changed files with 116 additions and 39 deletions
+8 -16
View File
@@ -14,24 +14,16 @@ export default function PaymentDetailsPage() {
const [error, setError] = useState(null);
const [paying, setPaying] = useState(false);
const handleRetryPayment = async () => {
const handleRetryPayment = () => {
if (!payment?.appointment_uuid) return;
setPaying(true);
try {
const res = await request.postAppointmentPayment({
appointment_uuid: payment.appointment_uuid,
gateway: payment.gateway || "mellat",
frontend_address: `${window.location.origin}/payment/result`,
});
const payUrl = res?.data?.pay_url;
if (payUrl) {
window.location.href = payUrl;
} else {
setPaying(false);
}
} catch {
setPaying(false);
}
// بدون XHR: ریدایرکت خالص به entry واحد پرداخت در بک‌اند.
const apiBase = process.env.NEXT_PUBLIC_API_URL;
const gateway = payment.gateway || "mellat";
const ret = encodeURIComponent(`${window.location.origin}/payment/result`);
window.location.href =
`${apiBase}/api/v1/payment/order/${payment.appointment_uuid}` +
`?gateway=${encodeURIComponent(gateway)}&return=${ret}`;
};
useEffect(() => {