feat: refactor payment handling to use direct backend redirect instead of API call
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user