verifyPanWithEncryptedApi method
Future<bool>
verifyPanWithEncryptedApi(
- BuildContext context, {
- required String mobile,
- String? expectedName,
Implementation
Future<bool> verifyPanWithEncryptedApi(BuildContext context, {
required String mobile,
String? expectedName,
}) async {
final pan = panText.text.trim();
if (pan.isEmpty) {
message = "Please enter your PAN number to continue.";
throw Exception(message);
}
final String nameToSend =
(expectedName != null && expectedName.trim().isNotEmpty)
? expectedName.trim()
: (aadhaarName?.trim().isNotEmpty == true
? aadhaarName!.trim()
: "");
if (kDebugMode) {
print('[PAN-CHECK] nameToSend="$nameToSend" pan="$pan"');
}
final geo = await DeviceUtils.getGeoLocation();
final sessionId = DeviceUtils.generateSessionId().toString();
final platform = DeviceUtils.platformCode().toString();
final mobile10 = normalizeMobile(mobile);
final machineId = await normalizeMachineId();
final dob = normalizeDob(dobText.text.trim());
final params = {
"ApplicationType": EnvConfig.applicationType,
"GeoLocation": geo,
"MachineID": machineId,
"Mobilenumber": mobile10,
"PANNumber": pan,
"Name": nameToSend,
"Fathername": "",
"Dob": dob,
"Platform": platform,
"Purpose": EnvConfig.purpose,
"ReqType": EnvConfig.reqType,
"SessionID": sessionId,
"EntityID": EnvConfig.entityId,
};
final Map<String, dynamic> resp =
await ApiService.postEncrypted(
endpoint: EnvConfig.panVerifyEndpoint,
params: params,
useStaging: EnvConfig.useStaging,
);
String read(Map<String, dynamic> m, List<String> keys) {
for (final k in keys) {
if (m.containsKey(k) && m[k] != null) return m[k].toString();
}
return "";
}
final panStatus =
read(resp, ['PANStatus', 'PanStatus']).trim().toUpperCase();
final dobStatus =
read(resp, ['DobStatus', 'DOBStatus']).trim().toUpperCase();
final nameResp = read(resp, ['Name', 'FullName']);
if (nameResp.isNotEmpty) fullName = nameResp;
if (panStatus == 'E' && dobStatus == 'Y') {
isVerified.value = true;
message = "PAN verified successfully.";
return true;
}
message = read(resp, ['Message', 'Description']);
// changes
PopupAlert().showSnack(context,true, resp["PANDescription"]);
throw Exception(
message ?? "Unable to verify PAN. Please try again.");
}