build
This commit is contained in:
parent
1386273490
commit
88db2611ca
|
|
@ -3,9 +3,20 @@ import { LanguageContext } from '../../backend/LanguageContext';
|
|||
|
||||
import next from '../../icons/next.svg';
|
||||
import next_reverse from '../../icons/next-reverse.svg';
|
||||
import { UserContext } from '../../backend/UserContext';
|
||||
|
||||
const PaymentSuccess = ({ setStage, stage, setModalOpen }) => {
|
||||
const PaymentSuccess = ({
|
||||
setStage,
|
||||
stage,
|
||||
borrowerData,
|
||||
guaranterData,
|
||||
isGuranter,
|
||||
recepientAmount,
|
||||
creditDuration,
|
||||
setErrMessage,
|
||||
}) => {
|
||||
const { locale } = useContext(LanguageContext);
|
||||
const { user } = useContext(UserContext);
|
||||
|
||||
const [codeValue, setPhoneValue] = useState('');
|
||||
|
||||
|
|
@ -16,10 +27,104 @@ const PaymentSuccess = ({ setStage, stage, setModalOpen }) => {
|
|||
setPhoneValue(e.target.value);
|
||||
};
|
||||
|
||||
const onSubmit = (data) => {
|
||||
// confirmPayment();
|
||||
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: user.mobile_phone,
|
||||
otp: codeValue,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
|
||||
const jsonedResponse = await response.json();
|
||||
|
||||
if (jsonedResponse === 'OTP validated successfully') {
|
||||
fetchData();
|
||||
setStage(16);
|
||||
setIsLoading(false);
|
||||
}
|
||||
} 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: null,
|
||||
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) {
|
||||
setStage(16);
|
||||
} else {
|
||||
setErrMessage(responseJson.messageRu);
|
||||
setStage(10);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error.toString());
|
||||
// Handle errors as needed
|
||||
setError(true);
|
||||
}
|
||||
};
|
||||
|
||||
const onSubmit = (data) => {
|
||||
confirmCode();
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<section className="imm-cs-1">
|
||||
<h1 className="cs-2-title">Loading...</h1>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="imm-cs-1">
|
||||
<form>
|
||||
|
|
@ -77,7 +182,7 @@ const PaymentSuccess = ({ setStage, stage, setModalOpen }) => {
|
|||
</div>
|
||||
</button>
|
||||
<button
|
||||
disabled={codeValue.length !== 5 && !isLoading ? true : false}
|
||||
disabled={codeValue.length !== 6 && !isLoading ? true : false}
|
||||
type="submit"
|
||||
onClick={onSubmit}
|
||||
className="sign-btn cu-btn">
|
||||
|
|
|
|||
Loading…
Reference in New Issue