diff --git a/src/app/(main)/funds_transfer/add_beneficiary/addBeneficiaryOthers.tsx b/src/app/(main)/funds_transfer/add_beneficiary/addBeneficiaryOthers.tsx index 02afe0d..9f75d19 100644 --- a/src/app/(main)/funds_transfer/add_beneficiary/addBeneficiaryOthers.tsx +++ b/src/app/(main)/funds_transfer/add_beneficiary/addBeneficiaryOthers.tsx @@ -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,23 +183,46 @@ 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=""`, - { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-Login-Type": "IB", - Authorization: `Bearer ${token}`, - }, - } - ); + 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: { + "Content-Type": "application/json", + "X-Login-Type": "IB", + Authorization: `Bearer ${token}`, + }, + } + ); + } + // 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",