refactor: api integrate for NEFT,RTGS.IMPS and account statement

This commit is contained in:
2025-08-27 11:35:15 +05:30
parent 671ea780b3
commit eda57aae71
9 changed files with 137 additions and 80 deletions

View File

@@ -12,37 +12,6 @@ interface accountData {
stAvailableBalance: string;
custname: string;
}
const MockBeneficiaryData =
[
{
'stBankName': 'Kangra Central Co-operative Bank',
'stBenAccountNo': '50077736845',
'stBenName': 'RAJAT MAHARANA',
},
{
'stBankName': 'Kangra Central Co-operative Bank',
'stBenAccountNo': '50077742351',
'stBenName': 'RAJAT MAHARANA',
},
{
'stBankName': 'Kangra Central Co-operative Bank',
'stBenAccountNo': '20002076570',
'stBenName': 'Mr. PUSHKAR . SHARMA',
},
{
'stBankName': 'State Bank of India',
'stBenAccountNo': '50077742361',
'stIFSC': 'SBIN0004567',
'stBenName': 'Sachin Sharma',
},
{
'stBankName': 'ICICI',
'stBenAccountNo': '90088842361',
'stIFSC': 'ICICI0004567',
'stBenName': 'Eshika Paul',
},
]
export default function SendToBeneficiaryOthers() {
const router = useRouter();
const [authorized, setAuthorized] = useState<boolean | null>(null);
@@ -70,6 +39,24 @@ export default function SendToBeneficiaryOthers() {
setGenerateOtp(value);
return value;
}
const getAmountError = () => {
if (!amount || !selectedAccount) return null;
const amt = Number(amount);
const balance = Number(selectedAccount.stAvailableBalance);
if (paymentMode === "IMPS") {
if (amt > 200000) return "IMPS limit is ₹2,00,000";
if (amt > balance) return "Amount exceeds available balance";
}
if (paymentMode === "RTGS") {
if (amt < 200000) return "RTGS requires minimum ₹2,00,000";
if (amt > balance) return "Amount exceeds available balance";
}
if (paymentMode === "NEFT") {
if (amt > balance) return "Amount exceeds available balance";
}
if (amt <= 0) return "Amount cannot be less than or equal to zero";
return null;
};
const FetchBeneficiaryDetails = async () => {
try {
@@ -129,7 +116,6 @@ export default function SendToBeneficiaryOthers() {
}
}
}
const FetchAccountDetails = async () => {
try {
const token = localStorage.getItem("access_token");
@@ -191,7 +177,14 @@ export default function SendToBeneficiaryOthers() {
});
return;
}
if (getAmountError()) {
notifications.show({
title: "Invalid amount",
message: getAmountError()!,
color: "red",
});
return;
}
if (!showOtpField && !showTxnPassword && !showConfirmModel) {
setConfirmModel(true);
setIsVisibilityLocked(true);
@@ -231,8 +224,16 @@ export default function SendToBeneficiaryOthers() {
try {
setIsSubmitting(true);
const token = localStorage.getItem("access_token");
// Need to change the API
const res = await fetch("/api/payment/transfer", {
const remitter_name = localStorage.getItem("remitter_name");
let url = "";
if (paymentMode === "NEFT")
url = "/api/payment/neft";
if (paymentMode === "RTGS")
url = "/api/payment/rtgs"
if (paymentMode === "IMPS")
url = "/api/payment/imps";
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -241,17 +242,18 @@ export default function SendToBeneficiaryOthers() {
body: JSON.stringify({
fromAccount: selectedAccNo,
toAccount: beneficiaryAcc,
// toAccountType: beneficiaryType,
ifscCode: beneficiaryIFSC,
amount: amount,
narration: remarks,
tpassword: txnPassword,
beneficiaryName: beneficiaryName,
remitterName: remitter_name,
tpassword: txnPassword
}),
});
const result = await res.json();
if (res.ok) {
notifications.show({
title: "Success",
message: "Transaction successful",
message: result?.utr ? `Transaction successful - UTR =${result.utr}` : "Transaction successful",
color: "green",
});
setShowTxnPassword(false);
@@ -259,13 +261,15 @@ export default function SendToBeneficiaryOthers() {
setShowOtpField(false);
setOtp("");
setBeneficiaryName('');
} else {
}
else {
notifications.show({
title: "Error",
message: result?.error || "Transaction failed",
color: "red",
});
}
} catch {
notifications.show({
title: "Error",
@@ -327,8 +331,8 @@ export default function SendToBeneficiaryOthers() {
</Modal>
{/* main content */}
<div style={{ maxHeight: "320px", overflowY: "auto" }}>
<Stack gap="xs">
<Group grow>
<Stack gap={5} justify="flex-start">
<Group grow gap='xs' >
<Select
label="Select Debit Account Number"
placeholder="Choose account number"
@@ -355,13 +359,6 @@ export default function SendToBeneficiaryOthers() {
readOnly
withAsterisk
/>
</Group>
<Group justify="space-between" >
<Text size="xs" c="green" style={{ visibility: selectedAccount ? "visible" : "hidden" }}>Available Balance :
{selectedAccount ? selectedAccount.stAvailableBalance : 0}
</Text>
</Group>
<Group grow>
<TextInput
label="Beneficiary IFSC Code"
value={beneficiaryIFSC ? beneficiaryIFSC : ""}
@@ -369,6 +366,13 @@ export default function SendToBeneficiaryOthers() {
readOnly
withAsterisk
/>
</Group>
<Group gap='xs' >
<Text size="xs" c="green" style={{ visibility: selectedAccount ? "visible" : "hidden" }}>Available Balance :
{selectedAccount ? selectedAccount.stAvailableBalance : 0}
</Text>
</Group>
<Group grow gap='xs'>
<Radio.Group
name="payment-mode"
label="Select Payment Method"
@@ -377,21 +381,29 @@ export default function SendToBeneficiaryOthers() {
withAsterisk
readOnly={isVisibilityLocked}
>
<Group>
<Group gap="xs">
<Radio value="IMPS" label="IMPS" />
<Radio value="RTGS" label="RTGS" />
<Radio value="NEFT" label="NEFT" />
</Group>
<Text size="xs" c="red">
{paymentMode === "IMPS" && "IMPS is available 24X7. Limit: up to ₹2,00,000. Money is transfer instantly. "}
{paymentMode === "RTGS" && "RTGS is for ₹2,00,000 and above. Available during banking hours."}
{paymentMode === "NEFT" && "NEFT is available 24x7. Can be used for any amount but not instant."}
</Text>
</Radio.Group>
<TextInput
label="Amount"
type="number"
value={amount}
onChange={(e) => setAmount(e.currentTarget.value)}
error={
selectedAccount && Number(amount) > Number(selectedAccount.stAvailableBalance) ?
"Amount exceeds available balance" : false}
onChange={(e) => {
let input = e.currentTarget.value;
if (/^\d*\.?\d{0,2}$/.test(input))
setAmount(input);
}}
error={getAmountError()}
leftSection="₹"
withAsterisk
readOnly={showOtpField}
/>
@@ -400,7 +412,12 @@ export default function SendToBeneficiaryOthers() {
label="Remarks"
placeholder="Enter remarks"
value={remarks}
onChange={(e) => setRemarks(e.currentTarget.value)}
onChange={(e) => {
let input = e.currentTarget.value;
input = input.replace(/[^a-zA-Z0-9 ]/g, "");
setRemarks(input)
}}
maxLength={50}
withAsterisk
readOnly={showOtpField}
/>
@@ -428,7 +445,6 @@ export default function SendToBeneficiaryOthers() {
/>
)}
</Group>
<Group justify="flex-start">
<Button
variant="filled"
@@ -440,7 +456,7 @@ export default function SendToBeneficiaryOthers() {
</Button>
</Group>
</Stack>
</div>
</div >
</>
);
}