feat : add beneficiary api for inside bank

This commit is contained in:
2025-11-18 15:42:19 +05:30
parent c2c87f8c71
commit e3c9458ace

View File

@@ -145,20 +145,18 @@ export default function AddBeneficiaryOthers() {
});
return;
}
const trimmedIfsc = ifsccode.trim().toUpperCase();
const isValidIfscCode = (code: string) => {
return /^[A-Z]{4}0[0-9]{6}$/.test(code);
};
if (!isValidIfscCode(trimmedIfsc)) {
notifications.show({
title: "Invalid IFSC Code",
message: "Must be 11 characters: 4 uppercase letters, 0, then 6 digits (e.g., HDFC0123456)",
color: "red",
});
return;
}
// const isValidIfscCode = (code: string) => {
// return /^[A-Z]{4}0[0-9]{6}$/.test(code);
// };
// if (!isValidIfscCode(trimmedIfsc)) {
// notifications.show({
// title: "Invalid IFSC Code",
// message: "Must be 11 characters: 4 uppercase letters, 0, then 6 digits (e.g., HDFC0123456)",
// color: "red",
// });
// return;
// }
if (accountNo.length < 10 || accountNo.length > 17) {
notifications.show({
@@ -185,7 +183,11 @@ export default function AddBeneficiaryOthers() {
try {
setLoading(true);
const token = localStorage.getItem("access_token");
const response = await fetch(`/api/beneficiary/validate/outside-bank?accountNo=${accountNo}&ifscCode=${ifsccode}&remitterName=""`,
let response;
// IF IFSC starts with "KACE" (within bank)
if (ifsccode.startsWith("KACE")) {
response = await fetch(
`/api/beneficiary/validate/within-bank?accountNumber=${accountNo}`,
{
method: "GET",
headers: {
@@ -195,13 +197,32 @@ export default function AddBeneficiaryOthers() {
},
}
);
}
// ELSE: other banks → keep your old API
else {
response = await fetch(
`/api/beneficiary/validate/outside-bank?accountNo=${accountNo}&ifscCode=${ifsccode}&remitterName=""`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
"X-Login-Type": "IB",
Authorization: `Bearer ${token}`,
},
}
);
}
const data = await response.json();
if (response.ok && data?.name) {
setBeneficiaryName(data.name);
setValidationStatus("success");
setIsVisibilityLocked(true);
setOtpSent(true);
const otp = await handleSendOtp();
await handleSendOtp();
notifications.show({
withBorder: true,
color: "green",