otp validation before loan create added
This commit is contained in:
parent
155a168b5d
commit
74d4075f8f
|
|
@ -51,94 +51,29 @@ const AcceptStage = ({
|
|||
},
|
||||
});
|
||||
|
||||
const fetchData = async () => {
|
||||
const sendCode = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
const response = await fetch(
|
||||
`https://shahsyotag.halkbank.gov.tm/onlineloancre-services/api/loancre`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
clientRecipient: {
|
||||
idSeria: borrowerData.idSeria,
|
||||
idNo: borrowerData.idNo,
|
||||
accountNo: borrowerData.accountNo,
|
||||
name: borrowerData.name,
|
||||
surname: borrowerData.surname,
|
||||
availableAmount: borrowerData.availableAmount,
|
||||
clientType: 'recipient',
|
||||
signRecipient: borrowerData.signRecipient,
|
||||
},
|
||||
clientGuarantor: isGuranter
|
||||
? {
|
||||
idSeria: guaranterData.idSeria,
|
||||
idNo: guaranterData.idNo,
|
||||
accountNo: guaranterData.accountNo,
|
||||
name: guaranterData.name,
|
||||
surname: guaranterData.surname,
|
||||
availableAmount: guaranterData.availableAmount,
|
||||
clientType: 'guarantor',
|
||||
signGuarantor: guaranterData.signGuarantor,
|
||||
}
|
||||
: null,
|
||||
availableAmount: recepientAmount,
|
||||
creditCardAccountNumber: cardDetails,
|
||||
mrtIsInsuarance: isGuranter ? 0 : 1,
|
||||
termInYears: creditDuration,
|
||||
}),
|
||||
},
|
||||
);
|
||||
const response = await fetch('https://shahsyotag.halkbank.gov.tm/sendOTP', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'aplication/json' },
|
||||
body: JSON.stringify({
|
||||
phone_number: '+99361454210',
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
|
||||
const responseJson = await response.json();
|
||||
|
||||
if (responseJson.errCode === 0) {
|
||||
sendData(responseJson);
|
||||
} else {
|
||||
setErrMessage(responseJson.messageRu);
|
||||
setStage(10);
|
||||
}
|
||||
setStage(9);
|
||||
} catch (error) {
|
||||
console.error(error.toString());
|
||||
// Handle errors as needed
|
||||
setError(true);
|
||||
}
|
||||
};
|
||||
|
||||
const sendData = async (requestBody) => {
|
||||
try {
|
||||
const headers = {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${userToken}`,
|
||||
};
|
||||
const response = await fetch('https://shahsyotag.halkbank.gov.tm/app/api/quick_loans', {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: JSON.stringify(requestBody.sign),
|
||||
});
|
||||
|
||||
const jsonedResponse = await response.json();
|
||||
setAcceptedMessage(jsonedResponse.message);
|
||||
|
||||
setIsLoading(false);
|
||||
|
||||
setStage(11);
|
||||
} catch (error) {
|
||||
console.error(error.toString());
|
||||
setError(true);
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const onSubmit = () => {
|
||||
fetchData();
|
||||
sendCode();
|
||||
setStage(9);
|
||||
};
|
||||
|
||||
if (error) {
|
||||
|
|
@ -258,7 +193,10 @@ const AcceptStage = ({
|
|||
type="submit"
|
||||
className="sign-btn cu-btn"
|
||||
disabled={cardDetails.length !== 23 && !isLoading ? true : false}
|
||||
onClick={onSubmit}>
|
||||
onClick={() => {
|
||||
onSubmit();
|
||||
setStage(9);
|
||||
}}>
|
||||
<div>
|
||||
<h3>
|
||||
{locale === 'TKM'
|
||||
|
|
|
|||
|
|
@ -16,14 +16,21 @@ const schema = z.object({
|
|||
});
|
||||
|
||||
const PhoneAccept = ({
|
||||
setStage,
|
||||
paymentDetails,
|
||||
borrowerData,
|
||||
submitCardDetails,
|
||||
paymentDetails,
|
||||
paymentLink,
|
||||
setStage,
|
||||
isGuranter,
|
||||
guaranterData,
|
||||
recepientAmount,
|
||||
cardDetails,
|
||||
creditDuration,
|
||||
setAcceptedMessage,
|
||||
}) => {
|
||||
const { locale } = useContext(LanguageContext);
|
||||
const { user } = useContext(UserContext);
|
||||
const userToken = localStorage.getItem('userToken');
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState(false);
|
||||
|
|
@ -33,6 +40,8 @@ const PhoneAccept = ({
|
|||
|
||||
const [codeValue, setPhoneValue] = useState('');
|
||||
|
||||
const [errMesage, setErrMessage] = useState();
|
||||
|
||||
const handleCodeChange = (e) => {
|
||||
setPhoneValue(e.target.value);
|
||||
};
|
||||
|
|
@ -41,8 +50,6 @@ const PhoneAccept = ({
|
|||
resolver: zodResolver(schema),
|
||||
});
|
||||
|
||||
console.log(paymentDetails);
|
||||
|
||||
const confirmPayment = async () => {
|
||||
try {
|
||||
const headers = {
|
||||
|
|
@ -70,10 +77,13 @@ const PhoneAccept = ({
|
|||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
|
||||
if (jsonedResponse.status === 'ok' && jsonedResponse.finalurl.includes('status=1')) {
|
||||
if (jsonedResponse.status === 'ok' && jsonedResponse['final-url'].includes('status=1')) {
|
||||
setInvalidData(false);
|
||||
checkPayment();
|
||||
} else if (jsonedResponse.status === 'wrong-otp') {
|
||||
} else if (
|
||||
jsonedResponse.status === 'wrong-otp' ||
|
||||
!jsonedResponse['final-url'].includes('status=1')
|
||||
) {
|
||||
setTryAgain(true);
|
||||
} else {
|
||||
setInvalidData(true);
|
||||
|
|
@ -117,8 +127,6 @@ const PhoneAccept = ({
|
|||
|
||||
const jsonedResponse = await response.json();
|
||||
|
||||
console.log(jsonedResponse);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
|
|
@ -129,8 +137,121 @@ const PhoneAccept = ({
|
|||
}
|
||||
};
|
||||
|
||||
const confirmCode = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const response = await fetch('https://shahsyotag.halkbank.gov.tm/validateOTP', {
|
||||
headers: { 'Content-Type': 'aplication/json' },
|
||||
method: 'POST',
|
||||
|
||||
body: JSON.stringify({
|
||||
phone_number: '+99361454210',
|
||||
otp: codeValue,
|
||||
}),
|
||||
});
|
||||
|
||||
const jsonedResponse = await response.json();
|
||||
|
||||
if (jsonedResponse === 'OTP validated successfully') {
|
||||
fetchData();
|
||||
} else {
|
||||
setErrMessage(true);
|
||||
}
|
||||
} catch (error) {}
|
||||
};
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://shahsyotag.halkbank.gov.tm/onlineloancre-services/api/loancre`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
clientRecipient: {
|
||||
idSeria: borrowerData.idSeria,
|
||||
idNo: borrowerData.idNo,
|
||||
accountNo: borrowerData.accountNo,
|
||||
name: borrowerData.name,
|
||||
surname: borrowerData.surname,
|
||||
availableAmount: borrowerData.availableAmount,
|
||||
clientType: 'recipient',
|
||||
signRecipient: borrowerData.signRecipient,
|
||||
},
|
||||
clientGuarantor: isGuranter
|
||||
? {
|
||||
idSeria: guaranterData.idSeria,
|
||||
idNo: guaranterData.idNo,
|
||||
accountNo: guaranterData.accountNo,
|
||||
name: guaranterData.name,
|
||||
surname: guaranterData.surname,
|
||||
availableAmount: guaranterData.availableAmount,
|
||||
clientType: 'guarantor',
|
||||
signGuarantor: guaranterData.signGuarantor,
|
||||
}
|
||||
: null,
|
||||
availableAmount: recepientAmount,
|
||||
creditCardAccountNumber: cardDetails,
|
||||
mrtIsInsuarance: isGuranter ? 0 : 1,
|
||||
termInYears: creditDuration,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
|
||||
const responseJson = await response.json();
|
||||
|
||||
if (responseJson.errCode === 0) {
|
||||
sendData(responseJson);
|
||||
} else {
|
||||
setErrMessage(responseJson.messageRu);
|
||||
setStage(10);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error.toString());
|
||||
// Handle errors as needed
|
||||
setError(true);
|
||||
}
|
||||
};
|
||||
|
||||
const sendData = async (requestBody) => {
|
||||
try {
|
||||
const headers = {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${userToken}`,
|
||||
};
|
||||
const response = await fetch('https://shahsyotag.halkbank.gov.tm/app/api/quick_loans', {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: JSON.stringify(requestBody.sign),
|
||||
});
|
||||
|
||||
const jsonedResponse = await response.json();
|
||||
if (!cardDetails) {
|
||||
}
|
||||
|
||||
setAcceptedMessage(jsonedResponse.message);
|
||||
setIsLoading(false);
|
||||
|
||||
setStage(11);
|
||||
} catch (error) {
|
||||
console.error(error.toString());
|
||||
setError(true);
|
||||
}
|
||||
};
|
||||
|
||||
const onSubmit = (data) => {
|
||||
confirmPayment();
|
||||
if (cardDetails) {
|
||||
confirmCode();
|
||||
} else {
|
||||
confirmPayment();
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
|
|
@ -141,29 +262,29 @@ const PhoneAccept = ({
|
|||
);
|
||||
}
|
||||
|
||||
// if (error) {
|
||||
// return (
|
||||
// <section className="imm-cs-1">
|
||||
// <h1 className="cs-2-title">Error...</h1>
|
||||
// <button type="button" className="sign-btn reg-btn" onClick={() => setStage(8)}>
|
||||
// <div>
|
||||
// <div className="btn-img">
|
||||
// <img src={next_reverse} alt="logout" />
|
||||
// </div>
|
||||
// <h3>
|
||||
// {locale === 'TKM'
|
||||
// ? 'Yza'
|
||||
// : locale === 'РУС'
|
||||
// ? 'Назад'
|
||||
// : locale === 'ENG'
|
||||
// ? 'Back'
|
||||
// : 'Yza'}
|
||||
// </h3>
|
||||
// </div>
|
||||
// </button>
|
||||
// </section>
|
||||
// );
|
||||
// }
|
||||
if (errMesage) {
|
||||
return (
|
||||
<section className="imm-cs-1">
|
||||
<h1 className="cs-2-title">Error...</h1>
|
||||
<button type="button" className="sign-btn reg-btn" onClick={() => setStage(8)}>
|
||||
<div>
|
||||
<div className="btn-img">
|
||||
<img src={next_reverse} alt="logout" />
|
||||
</div>
|
||||
<h3>
|
||||
{locale === 'TKM'
|
||||
? 'Yza'
|
||||
: locale === 'РУС'
|
||||
? 'Назад'
|
||||
: locale === 'ENG'
|
||||
? 'Back'
|
||||
: 'Yza'}
|
||||
</h3>
|
||||
</div>
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="imm-cs-1">
|
||||
|
|
@ -176,7 +297,7 @@ const PhoneAccept = ({
|
|||
: locale === 'ENG'
|
||||
? 'Loan calculator'
|
||||
: 'Karzyň kalkulýatory'}
|
||||
{submitCardDetails['three-d-secure-number']}
|
||||
{cardDetails ? '+99361454210' : submitCardDetails['three-d-secure-number']}
|
||||
</h2>
|
||||
<div className="imm-credit-form-wrapper">
|
||||
<div className="input-block">
|
||||
|
|
@ -207,7 +328,10 @@ const PhoneAccept = ({
|
|||
</section>
|
||||
)}
|
||||
<div className="cu-bottom cd-2-title">
|
||||
<button type="button" className="sign-btn reg-btn" onClick={() => setStage(13)}>
|
||||
<button
|
||||
type="submit"
|
||||
className="sign-btn reg-btn"
|
||||
onClick={() => (cardDetails ? setStage(8) : setStage(13))}>
|
||||
<div>
|
||||
<div className="btn-img">
|
||||
<img src={next_reverse} alt="logout" />
|
||||
|
|
@ -224,7 +348,15 @@ const PhoneAccept = ({
|
|||
</div>
|
||||
</button>
|
||||
<button
|
||||
disabled={codeValue.length !== 5 && !isLoading ? true : false}
|
||||
disabled={
|
||||
cardDetails
|
||||
? codeValue.length !== 6 && !isLoading
|
||||
? true
|
||||
: false
|
||||
: codeValue.length !== 5 && !isLoading
|
||||
? true
|
||||
: false
|
||||
}
|
||||
type="submit"
|
||||
onClick={onSubmit}
|
||||
className="sign-btn cu-btn">
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ const ImmediateCreditModal = ({
|
|||
const [paymentDetails, setPaymentDetails] = useState();
|
||||
const [submitCardDetails, setSumbitCardDetails] = useState();
|
||||
|
||||
console.log(stage);
|
||||
|
||||
return (
|
||||
<section className={modalOpen ? 'modal credit-modal active' : 'modal credit-modal'}>
|
||||
<div className="modal-container">
|
||||
|
|
@ -339,7 +341,6 @@ const ImmediateCreditModal = ({
|
|||
guaranterData={guaranterData}
|
||||
isGuranter={isGuranter}
|
||||
setErrMessage={setErrMessage}
|
||||
setAcceptedMessage={setAcceptedMessage}
|
||||
setUserDataRes={setUserDataRes}
|
||||
userDataRes={userDataRes}
|
||||
/>
|
||||
|
|
@ -351,6 +352,7 @@ const ImmediateCreditModal = ({
|
|||
cardDetails={cardDetails}
|
||||
recepientAmount={recepientAmount}
|
||||
creditDuration={creditDuration}
|
||||
setAcceptedMessage={setAcceptedMessage}
|
||||
/>
|
||||
) : stage === 10 ? (
|
||||
<NotAUser setStage={setStage} stage={stage} errMessage={errMessage} />
|
||||
|
|
|
|||
Loading…
Reference in New Issue