feat: handle new Shahkar identity verification step during purchase
When the backend responds with requires_shahkar_verification (for purchases between the 100M and 200M thresholds), show an inline national-code input instead of failing outright, and resubmit the buy request with nationalCode once the user fills it in. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -45,6 +45,8 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
});
|
});
|
||||||
const [price, setPrice] = useState(0);
|
const [price, setPrice] = useState(0);
|
||||||
const [isInfoOpen, setIsInfoOpen] = useState(false);
|
const [isInfoOpen, setIsInfoOpen] = useState(false);
|
||||||
|
const [needsShahkarVerification, setNeedsShahkarVerification] = useState(false);
|
||||||
|
const [nationalCode, setNationalCode] = useState("");
|
||||||
const payablePrice = toNumber(
|
const payablePrice = toNumber(
|
||||||
price === 0 ? data?.data?.result?.price || 0 : price
|
price === 0 ? data?.data?.result?.price || 0 : price
|
||||||
);
|
);
|
||||||
@@ -99,6 +101,8 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
setFieldValue("count", 1);
|
setFieldValue("count", 1);
|
||||||
setFieldValue("discount", "");
|
setFieldValue("discount", "");
|
||||||
setPrice(0);
|
setPrice(0);
|
||||||
|
setNeedsShahkarVerification(false);
|
||||||
|
setNationalCode("");
|
||||||
}
|
}
|
||||||
}, [isOpen, setFieldValue]);
|
}, [isOpen, setFieldValue]);
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
@@ -190,10 +194,23 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(formik.values);
|
if (needsShahkarVerification && nationalCode.trim().length !== 10) {
|
||||||
toast.promise(mutation.mutateAsync({ ...formik.values, status: "buy" }), {
|
toast.error("لطفا کد ملی ۱۰ رقمی را بهدرستی وارد کنید");
|
||||||
loading: "درحال انتقال به درگاه پرداخت...",
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
...formik.values,
|
||||||
|
status: "buy",
|
||||||
|
...(needsShahkarVerification ? { nationalCode: nationalCode.trim() } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
toast.promise(mutation.mutateAsync(payload), {
|
||||||
|
loading: needsShahkarVerification
|
||||||
|
? "درحال احراز هویت شاهکار..."
|
||||||
|
: "درحال انتقال به درگاه پرداخت...",
|
||||||
success: (res: AxiosResponse) => {
|
success: (res: AxiosResponse) => {
|
||||||
|
setNeedsShahkarVerification(false);
|
||||||
window.location.href = res?.data?.result?.payment?.action;
|
window.location.href = res?.data?.result?.payment?.action;
|
||||||
return `${res.data.alert}`;
|
return `${res.data.alert}`;
|
||||||
},
|
},
|
||||||
@@ -226,16 +243,26 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
requiresAdvancedVerificationFromApi ||
|
requiresAdvancedVerificationFromApi ||
|
||||||
(err.response?.status === 422 &&
|
(err.response?.status === 422 &&
|
||||||
errorMessage.includes("احراز هویت پیشرفته"));
|
errorMessage.includes("احراز هویت پیشرفته"));
|
||||||
|
|
||||||
if (isAdvancedVerificationError) {
|
const requiresShahkarVerificationFromApi =
|
||||||
|
isResponseObject &&
|
||||||
|
"requires_shahkar_verification" in responseData &&
|
||||||
|
Boolean(
|
||||||
|
(responseData as { requires_shahkar_verification?: boolean })
|
||||||
|
.requires_shahkar_verification
|
||||||
|
);
|
||||||
|
|
||||||
|
if (requiresShahkarVerificationFromApi) {
|
||||||
|
setNeedsShahkarVerification(true);
|
||||||
|
} else if (isAdvancedVerificationError) {
|
||||||
goToAdvancedVerification();
|
goToAdvancedVerification();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err.response?.status === 500) {
|
if (err.response?.status === 500) {
|
||||||
dispatch(setIsPaymentGateway(false));
|
dispatch(setIsPaymentGateway(false));
|
||||||
navigate("/noactive-payment");
|
navigate("/noactive-payment");
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -331,6 +358,24 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
|||||||
{advancedVerificationMessage}
|
{advancedVerificationMessage}
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
{needsShahkarVerification && (
|
||||||
|
<div className="w-full flex flex-col gap-2">
|
||||||
|
<Alert type="warning" extra="!mb-0 text-start">
|
||||||
|
برای خریدهای با مبلغ بالا، احراز هویت شاهکار (تطبیق شماره
|
||||||
|
موبایل حساب شما با کد ملی) الزامی است. لطفا کد ملی خود را
|
||||||
|
وارد کنید.
|
||||||
|
</Alert>
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
extra="max-md:!p-1 md:!p-2"
|
||||||
|
placeholder="کد ملی"
|
||||||
|
value={nationalCode}
|
||||||
|
onChange={(e) =>
|
||||||
|
setNationalCode(e.target.value.replace(/[^0-9]/g, ""))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{data?.data?.result?.max_config === 0 ? (
|
{data?.data?.result?.max_config === 0 ? (
|
||||||
<>
|
<>
|
||||||
<Alert type="info" extra="mt-5">
|
<Alert type="info" extra="mt-5">
|
||||||
|
|||||||
Reference in New Issue
Block a user