import { LinearProgress, Typography } from "@mui/material"; import { useEffect, useRef, useState } from "react"; import { useDispatch } from "react-redux"; import { Grid } from "../../../../components/grid/Grid"; import { SPACING } from "../../../../data/spacing"; import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl"; import { slaughterPaymentRefIdService } from "../../services/salughter-payment-refid"; import { provincePaymentRefIdService, provincePaymentRefIdWagesService, } from "../../../province/services/province-payment-refId"; export const SlaughterPayFeesGateway = ({ amount, user_key, amountWithTax, isZarinPal, isPayment, isPaymentData, backend, }) => { const dispatch = useDispatch(); const formRef = useRef(); const [refId, setRefId] = useState(); const [authority, setAuthority] = useState(); const handleSubmit = () => { formRef.current.submit(); }; useEffect(() => { if (isZarinPal) { dispatch( provincePaymentRefIdService({ role: getRoleFromUrl(), total_amount: parseInt(amount), }) ).then((r) => { // setAuthority(r.payload.data?.authority); setAuthority(r.payload.data?.token); }); } else if (isPayment) { dispatch( provincePaymentRefIdWagesService({ data: isPaymentData, backend }) ).then((r) => { // setAuthority(r.payload.data?.authority); setAuthority(r.payload.data?.token); }); } else { dispatch( slaughterPaymentRefIdService({ role: getRoleFromUrl(), kill_house_key: user_key, payment_type: "auto", amount: parseInt(amount), amount_with_tax: parseInt(amountWithTax), }) ).then((r) => { setRefId(r.payload.data.refId); }); } }, []); useEffect(() => { if (refId) { handleSubmit(); } }, [refId]); useEffect(() => { if (authority) { // window.location.href = `https://www.zarinpal.com/pg/StartPay/${authority}`; // window.location.href = `https://sep.shaparak.ir/OnlinePG/SendToken?token=${authority}`; handleSubmit(); } }, [authority]); return ( در حال انتقال به درگاه پرداخت...
{/*
*/}
); };