updated code
This commit is contained in:
@@ -53,13 +53,6 @@ public class OtpClient {
|
||||
try {
|
||||
logger.info("Initiating OTP send process for mobile: {}", mobile);
|
||||
|
||||
logger.info("eKYC Mobile URL: {}", ekycMobileUrl);
|
||||
logger.info("API Key: {}", apiKey != null && !apiKey.isEmpty());
|
||||
logger.info("Secret Key: {}", secretKey != null && !secretKey.isEmpty());
|
||||
logger.info("Send URL: {}", sendUrl);
|
||||
logger.info("Verify URL: {}", verifyUrl);
|
||||
logger.info("Mobile Number: {}", mobile);
|
||||
|
||||
// If explicit eKYC config present, use that flow
|
||||
if (ekycMobileUrl != null && !ekycMobileUrl.isEmpty()) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@@ -145,28 +138,20 @@ public class OtpClient {
|
||||
|
||||
if (response.getStatusCode() == HttpStatus.OK) {
|
||||
String respBody = response.getBody();
|
||||
|
||||
if (respBody != null) {
|
||||
// try to parse JSON and look for common verification keys
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
Map respMap = mapper.readValue(respBody, Map.class);
|
||||
if (respMap.containsKey("verified")) {
|
||||
return Boolean.TRUE.equals(respMap.get("verified"));
|
||||
}
|
||||
if (respMap.containsKey("success")) {
|
||||
return Boolean.TRUE.equals(respMap.get("success"));
|
||||
}
|
||||
if (respMap.containsKey("status") && "OK".equalsIgnoreCase(String.valueOf(respMap.get("status")))) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("Unable to parse verification response body to JSON: {}", e.getMessage());
|
||||
// fall through to treat 200 as success
|
||||
Map respMap = mapper.readValue(respBody, Map.class);
|
||||
|
||||
// Check correct key of your service
|
||||
if (respMap.containsKey("status")) {
|
||||
return Boolean.TRUE.equals(respMap.get("status"));
|
||||
}
|
||||
}
|
||||
// fallback: treat HTTP 200 as successful verification
|
||||
return true;
|
||||
} else {
|
||||
|
||||
return false; // default fallback
|
||||
}
|
||||
else {
|
||||
logger.warn("OTP verification endpoint returned non-OK status: {}", response.getStatusCode());
|
||||
return false;
|
||||
}
|
||||
@@ -183,4 +168,6 @@ public class OtpClient {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user