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 [isInfoOpen, setIsInfoOpen] = useState(false);
|
||||
const [needsShahkarVerification, setNeedsShahkarVerification] = useState(false);
|
||||
const [nationalCode, setNationalCode] = useState("");
|
||||
const payablePrice = toNumber(
|
||||
price === 0 ? data?.data?.result?.price || 0 : price
|
||||
);
|
||||
@@ -99,6 +101,8 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
setFieldValue("count", 1);
|
||||
setFieldValue("discount", "");
|
||||
setPrice(0);
|
||||
setNeedsShahkarVerification(false);
|
||||
setNationalCode("");
|
||||
}
|
||||
}, [isOpen, setFieldValue]);
|
||||
const mutation = useMutation({
|
||||
@@ -190,10 +194,23 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(formik.values);
|
||||
toast.promise(mutation.mutateAsync({ ...formik.values, status: "buy" }), {
|
||||
loading: "درحال انتقال به درگاه پرداخت...",
|
||||
if (needsShahkarVerification && nationalCode.trim().length !== 10) {
|
||||
toast.error("لطفا کد ملی ۱۰ رقمی را بهدرستی وارد کنید");
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
...formik.values,
|
||||
status: "buy",
|
||||
...(needsShahkarVerification ? { nationalCode: nationalCode.trim() } : {}),
|
||||
};
|
||||
|
||||
toast.promise(mutation.mutateAsync(payload), {
|
||||
loading: needsShahkarVerification
|
||||
? "درحال احراز هویت شاهکار..."
|
||||
: "درحال انتقال به درگاه پرداخت...",
|
||||
success: (res: AxiosResponse) => {
|
||||
setNeedsShahkarVerification(false);
|
||||
window.location.href = res?.data?.result?.payment?.action;
|
||||
return `${res.data.alert}`;
|
||||
},
|
||||
@@ -226,16 +243,26 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
requiresAdvancedVerificationFromApi ||
|
||||
(err.response?.status === 422 &&
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
if (err.response?.status === 500) {
|
||||
dispatch(setIsPaymentGateway(false));
|
||||
navigate("/noactive-payment");
|
||||
}
|
||||
|
||||
|
||||
return errorMessage;
|
||||
},
|
||||
});
|
||||
@@ -331,6 +358,24 @@ const ModalBuy = ({ isOpen, setIsOpen, configId }: ModalBuyProps) => {
|
||||
{advancedVerificationMessage}
|
||||
</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 ? (
|
||||
<>
|
||||
<Alert type="info" extra="mt-5">
|
||||
|
||||
Reference in New Issue
Block a user