import { useState, useEffect } from "react"; import moment from "moment-jalaali"; import ArrowLeftB from "@/components/icons/ArrowLeftB"; import { Button, MenuItem, Select, FormControl, InputLabel } from "@mui/material"; import ButtonFixed from "./ButtonFixed"; import { request } from "@/services/response"; const APPOINTMENT_AMOUNT_RIALS = 150000; const PAYMENT_TTL = 900; const banks = [ { id: "mellat", title: "بانک ملت" }, { id: "sep", title: "سامان (سپ)" }, ]; function Paying({ setStep, appointmentId, expiresAt, doctor, data, isForAnother, selectedSlot }) { const [selectedBank, setSelectedBank] = useState("mellat"); const [loading, setLoading] = useState(false); const [testMode, setTestMode] = useState(null); const computeLeft = () => expiresAt ? Math.max(0, Math.floor((expiresAt * 1000 - Date.now()) / 1000)) : PAYMENT_TTL; const [timeLeft, setTimeLeft] = useState(computeLeft); useEffect(() => { const timer = setInterval(() => setTimeLeft(computeLeft()), 1000); return () => clearInterval(timer); }, [expiresAt]); useEffect(() => { request .getPaymentConfig() .then((res) => setTestMode(Boolean(res?.data?.test_mode))) .catch(() => setTestMode(false)); }, []); const formatTime = (seconds) => { const m = Math.floor(seconds / 60); const s = seconds % 60; return `${m}:${s.toString().padStart(2, "0")}`; }; const toman = (APPOINTMENT_AMOUNT_RIALS / 10).toLocaleString("fa-IR"); const patientName = isForAnother ? [data?.name?.value, data?.family?.value].filter(Boolean).join(" ").trim() : data?.name?.value; const expired = timeLeft === 0; const progress = Math.max(0, Math.min(100, (timeLeft / PAYMENT_TTL) * 100)); const handlePayment = async () => { if (!appointmentId) return; setLoading(true); try { const res = await request.postAppointmentPayment({ appointment_uuid: appointmentId, gateway: testMode ? "mellat" : selectedBank, frontend_address: `${window.location.origin}/payment/result`, }); const redirectUrl = res?.data?.redirect_url; if (redirectUrl) { window.location.href = redirectUrl; } else { setStep((prev) => prev + 1); } } catch (error) { console.error("Payment error:", error); setLoading(false); } }; return (
تأیید و پرداخت
{/* ── خلاصه نوبت ── */}درگاه پرداخت آزمایشی
در این حالت پرداخت واقعی انجام نمیشود و نوبت بهصورت آزمایشی تأیید میگردد.
مهلت پرداخت تمام شد و نوبت آزاد شد. لطفاً دوباره زمان نوبت را انتخاب کنید.