improved logs

This commit is contained in:
Lincpay Tech
2025-11-10 10:05:43 +05:30
parent af7cdaf5d7
commit 43baedfecd
53 changed files with 662 additions and 572 deletions
@@ -1,8 +1,9 @@
package com.billpaymentservice.bbps.serviceImpl;
import java.time.LocalDateTime;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -39,7 +40,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
public class AgentServiceImpl implements AgentService {
@Value("${agent.data.url}")
@@ -51,7 +51,7 @@ public class AgentServiceImpl implements AgentService {
private final BharatConnectMasterRepository beneficiaryDetailsRepository;
private final BillMasterRepository billMasterRepository;
private final BillInitateRepository billIntiateRepository;
private static final Logger LOGGER = LoggerFactory.getLogger(AgentServiceImpl.class);
public AgentServiceImpl(RestClient restClient, HttpService httpService, Helper helper,
BharatConnectMasterRepository beneficiaryDetailsRepository,InboundTraceLogRepository inboundTraceLogRepository,
OutboundTraceLogRepository outboundTraceLogRepository, BillMasterRepository billMasterRepository,BillInitateRepository billIntiateRepository) {
@@ -64,13 +64,13 @@ public class AgentServiceImpl implements AgentService {
}
@Override
public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) {
LOGGER.info("Initiating bill fetch for request ID: {} and MID", fetchBillRequest.getReqId(), fetchBillRequest.getMid());
String apiName = "InitiateBillFetch";
String txnId = helper.generateTxnId(15);
String requestId = fetchBillRequest.getReqId();
String url = agentDtaUrl + BBPSConstant.BILL_FETCH_INTI;
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_INTI;
helper.validateMerchant(fetchBillRequest.getMid());
@@ -87,71 +87,74 @@ public class AgentServiceImpl implements AgentService {
// ✅ Create inbound & outbound logs
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, fetchBillRequest.getMid(), "POST", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "POST", requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, "POST", requestJson);
LOGGER.debug("Outbound log created successfully for txnId: {} and reqId: {}", txnId, requestId);
try {
Map<String, String> responseMap = httpService.postRequest(url, requestJson, headers);
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.postRequest(fullUrl, requestJson, headers);
String responseData = responseMap.get("data");
log.info("📦 Bill Fetch API Response: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
LOGGER.debug("Response received from BBPS: {}", responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
if (!dataMap.containsKey("genericResponse")) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
throw new CustomException(
String.valueOf(dataMap.get("message")),
String.valueOf(dataMap.get("status")),
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
String.valueOf(dataMap.get("remarks"))
);
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
LOGGER.warn("Invalid response received for txnId: {}", txnId);
throw new CustomException(
String.valueOf(dataMap.get("message")),
String.valueOf(dataMap.get("status")),
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
String.valueOf(dataMap.get("remarks"))
);
}
BillMaster billMaster = new BillMaster();
billMaster.setBillId((String) dataMap.get("billId"));
billMaster.setReqId(fetchBillRequest.getReqId());
billMaster.setTxnId(txnId);
billMasterRepository.save(billMaster);
LOGGER.info("BillMaster saved for billId: {}", billMaster.getBillId());
FetchBillResponse fetchBillResponse = objectMapper.convertValue(dataMap, FetchBillResponse.class);
GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus());
//save intitate bill here
BillInitiate billInitiate = new BillInitiate();
billInitiate.setBillId((String) dataMap.get("billId"));
billInitiate.setReqId(fetchBillRequest.getReqId());
billInitiate.setTxnId(txnId);
billIntiateRepository.save(billInitiate);
LOGGER.info("BillInitiate entry saved for billId: {}", billInitiate.getBillId());
BillFetchByBillIdRequest billFetchByBillIdRequest = new BillFetchByBillIdRequest();
billFetchByBillIdRequest.setBillId(fetchBillResponse.getBillId());
billFetchByBillIdRequest.setMid(fetchBillRequest.getMid());
billFetchByBillIdRequest.setReqId(requestId);
LOGGER.info("Waiting for 2 seconds before fetching bill by ID...");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // restore interrupted flag
log.warn("Thread interrupted during delay: {}", e.getMessage());
Thread.currentThread().interrupt();
LOGGER.warn("Thread interrupted during delay: {}", e.getMessage());
}
LOGGER.info("Calling internal method Fetching bill by ID: {}", billFetchByBillIdRequest.getBillId());
return fetchBillById(billFetchByBillIdRequest, inboundLog);
} catch (JsonProcessingException e) {
log.error("❌ JSON Parsing Error: {}", e.getMessage());
LOGGER.error("JSON Parsing Error: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
}
public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest, InboundTraceLog inboundLog) {
LOGGER.info("Fetching bill by BILLID for request ID={} and MID={}", billFetchByBillIdRequest.getReqId(), billFetchByBillIdRequest.getMid());
String apiName = "FetchBillById";
String txnId = helper.generateTxnId(15);
String reqId = billFetchByBillIdRequest.getReqId();
String billId = billFetchByBillIdRequest.getBillId();
String url = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + "1ced7566-1add-4e01-9ed6-04cd67ac9684";
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + "1ced7566-1add-4e01-9ed6-04cd67ac9684";
helper.validateMerchant(billFetchByBillIdRequest.getMid());
@@ -163,239 +166,252 @@ public class AgentServiceImpl implements AgentService {
headers.setContentType(MediaType.APPLICATION_JSON);
ObjectMapper objectMapper = new ObjectMapper();
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, url, "GET", null);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl);
try {
Map<String, String> responseMap = httpService.getRequest(url, headers);
String responseData = responseMap.get("data");
log.info("📦 Bill FetchById Response: {}", responseData);
try {
LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get("data");
LOGGER.info("Bill FetchById Response: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
if (!dataMap.containsKey("genericResponse")) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
throw new CustomException(
String.valueOf(dataMap.get("message")),
String.valueOf(dataMap.get("status")),
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
String.valueOf(dataMap.get("remarks"))
);
}
BillDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillDataResponse.class);
GeneralResp generalResp = responseWrapper.getGenericResponse();
String status = generalResp.getStatus();
log.info("📡 Current Bill Status: {}", status);
// ✅ Check for "INPROGRESS" or pending state
// ✅ Final successful response
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
helper.saveOrUpdateBillerData(responseWrapper,billFetchByBillIdRequest);
return new ResponseModel(
generalResp.getMessage(),
generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()),
responseWrapper
if (!dataMap.containsKey("genericResponse")) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
LOGGER.warn("Invalid response structure for txnId: {}", txnId);
throw new CustomException(
String.valueOf(dataMap.get("message")),
String.valueOf(dataMap.get("status")),
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
String.valueOf(dataMap.get("remarks"))
);
} catch (JsonProcessingException e) {
log.error("Error parsing BillById JSON: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
BillDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillDataResponse.class);
GeneralResp generalResp = responseWrapper.getGenericResponse();
String status = generalResp.getStatus();
LOGGER.info("Current Bill Status: {}", status);
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
helper.saveOrUpdateBillerData(responseWrapper,billFetchByBillIdRequest);
LOGGER.info("Bill data saved successfully for billId: {}", billId);
return new ResponseModel(
generalResp.getMessage(),
generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()),
responseWrapper
);
} catch (JsonProcessingException e) {
LOGGER.error("Error parsing BillById JSON: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest) {
String apiName = "FetchBillById";
String txnId = helper.generateTxnId(15);
String reqId = billFetchByBillIdRequest.getReqId();
String billId = billFetchByBillIdRequest.getBillId();
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + "1ced7566-1add-4e01-9ed6-04cd67ac9684";
String apiName = "FetchBillById";
String txnId = helper.generateTxnId(15);
String reqId = billFetchByBillIdRequest.getReqId();
String billId = billFetchByBillIdRequest.getBillId();
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + "1ced7566-1add-4e01-9ed6-04cd67ac9684";
try {
helper.validateMerchant(billFetchByBillIdRequest.getMid());
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
HttpHeaders headers = new HttpHeaders();
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
headers.set("agentId", headersData.getAgentId());
headers.set("tenantId", headersData.getTenantId());
headers.setContentType(MediaType.APPLICATION_JSON);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get("data");
log.info("data is :{}", responseData);
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
if (!dataMap.containsKey("genericResponse")) {
throw new CustomException(String.valueOf(dataMap.get("message")), // message
String.valueOf(dataMap.get("status")), // status
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
String.valueOf(dataMap.get("remarks")));
}
BillDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillDataResponse.class);
GeneralResp generalResp = responseWrapper.getGenericResponse();
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
helper.saveOrUpdateBillerData(responseWrapper,billFetchByBillIdRequest);
return responseModel;
LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId);
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
ResponseModel responseModel = new ResponseModel();
try {
helper.validateMerchant(fetchBillValidateRequest.getMid());
helper.validateMerchant(billFetchByBillIdRequest.getMid());
LOGGER.debug("Merchant validated successfully for MID={}", billFetchByBillIdRequest.getMid());
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
if (headersData == null) {
responseModel = new ResponseModel("Tenant Id Is Null", "Not Found", BBPSConstant.BADREQUEST, headersData);
return responseModel;
}
HttpHeaders headers = new HttpHeaders();
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
headers.set("agentId", headersData.getAgentId());
headers.set("tenantId", headersData.getTenantId());
headers.setContentType(MediaType.APPLICATION_JSON);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = objectMapper.writeValueAsString(fetchBillValidateRequest);
String url = agentDtaUrl + BBPSConstant.BILLER_VALIDATE_URL;
Map<String, String> responseMap = httpService.postRequest(url, json, headers);
LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
String responseData = responseMap.get("data");
LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData);
log.info("📦 Bill Fetch API Response: {}", responseData);
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {});
if (responseData == null || responseData.isEmpty()) {
throw new CustomException("Empty response from BBPS server");
}
// ✅ Convert JSON string → Map
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
// ✅ Validate generalResp
if (!dataMap.containsKey("genericResponse")) {
throw new CustomException("Invalid response structure from BBPS");
LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData);
throw new CustomException(
String.valueOf(dataMap.get("message")), // message
String.valueOf(dataMap.get("status")), // status
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode
String.valueOf(dataMap.get("remarks"))
);
}
// ✅ Convert to your custom DTO
FetchBillValidatestResponse fetchBillResponse = objectMapper.convertValue(dataMap, FetchBillValidatestResponse.class);
GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
// ✅ Build final ResponseModel
responseModel = new ResponseModel(
generalResponse.getMessage(),
generalResponse.getStatus(),
Integer.parseInt(generalResponse.getStatusCode()),
fetchBillResponse
BillDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillDataResponse.class);
GeneralResp generalResp = responseWrapper.getGenericResponse();
ResponseModel responseModel = new ResponseModel(
generalResp.getMessage(),
generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()),
responseWrapper
);
} catch (CustomException ex) {
log.warn("Merchant validation failed: {}", ex.getMessage());
return ex.getResponseModel(); // Directly return ResponseModel from exception
} catch (Exception e) {
log.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
responseModel.setStatus("500");
responseModel.setMessage("Exception occurred");
responseModel.setData(e.getMessage());
}
helper.saveOrUpdateBillerData(responseWrapper, billFetchByBillIdRequest);
LOGGER.info("Bill data saved successfully for billId={} | Status={}", billId, generalResp.getStatus());
return responseModel;
return responseModel;
} catch (JsonProcessingException e) {
LOGGER.error("Error parsing responseData JSON for billId={} : {}", billId, e.getMessage(), e);
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ResponseModel initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
// TODO Auto-generated method stub
return null;
}
@Override
public ResponseModel initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) {
ResponseModel responseModel = new ResponseModel();
try {
helper.validateMerchant(billRequest.getMid());
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
if (headersData == null) {
responseModel = new ResponseModel("Tenant Id Is Null", "Not Found", BBPSConstant.BADREQUEST, headersData);
return responseModel;
}
HttpHeaders headers = new HttpHeaders();
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
headers.set("agentId", headersData.getAgentId());
headers.set("tenantId", headersData.getTenantId());
headers.setContentType(MediaType.APPLICATION_JSON);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = objectMapper.writeValueAsString(billRequest);
String url = agentDtaUrl + BBPSConstant.BILL_ID_URL + billRequest.getBillId();
log.info("Full URL: {}", url);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
// ✅ Call the API using httpService
Map<String, String> responseMap = httpService.getRequest(url, headers);
String responseData = responseMap.get("data");
log.info("📦 Bill Fetch API Response: {}", responseData);
if (responseData == null || responseData.isEmpty()) {
throw new CustomException("Empty response from BBPS server");
}
// ✅ Convert JSON string → Map
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
// ✅ Validate generalResp
if (!dataMap.containsKey("genericResponse")) {
throw new CustomException("Invalid response structure from BBPS");
}
// ✅ Convert to your custom DTO
BillDataResponse fetchBillResponse = objectMapper.convertValue(dataMap, BillDataResponse.class);
GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
// ✅ Build final ResponseModel
responseModel = new ResponseModel(
generalResponse.getRemarks(),
generalResponse.getStatus(),
Integer.parseInt(generalResponse.getStatusCode()),
fetchBillResponse
);
} catch (CustomException ex) {
log.warn("Merchant validation failed: {}", ex.getMessage());
return ex.getResponseModel(); // Directly return ResponseModel from exception
} catch (Exception e) {
log.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
responseModel.setStatus("500");
responseModel.setMessage("Exception occurred");
responseModel.setData(e.getMessage());
}
return responseModel;
// TODO Auto-generated method stub
return null;
}
/*
* @Override public ResponseModel
* initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
*
* ResponseModel responseModel = new ResponseModel(); try {
*
* helper.validateMerchant(fetchBillValidateRequest.getMid());
*
* BharatConnectMaster headersData =
* beneficiaryDetailsRepository.findByOrgId("ORG001");
*
* if (headersData == null) { responseModel = new
* ResponseModel("Tenant Id Is Null", "Not Found", BBPSConstant.BADREQUEST,
* headersData); return responseModel; }
*
* HttpHeaders headers = new HttpHeaders(); headers.set("x-digiledge-key",
* headersData.getXDigiledgeKey()); headers.set("agentId",
* headersData.getAgentId()); headers.set("tenantId",
* headersData.getTenantId());
* headers.setContentType(MediaType.APPLICATION_JSON);
*
* ObjectMapper objectMapper = new ObjectMapper();
* objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String
* json = objectMapper.writeValueAsString(fetchBillValidateRequest); String url
* = agentDtaUrl + BBPSConstant.BILLER_VALIDATE_URL;
*
* Map<String, String> responseMap = httpService.postRequest(url, json,
* headers); String responseData = responseMap.get("data");
*
* log.info("📦 Bill Fetch API Response: {}", responseData);
*
* if (responseData == null || responseData.isEmpty()) { throw new
* CustomException("Empty response from BBPS server"); }
*
* // ✅ Convert JSON string → Map Map<String, Object> dataMap =
* objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>()
* {});
*
* // ✅ Validate generalResp if (!dataMap.containsKey("genericResponse")) {
* throw new CustomException("Invalid response structure from BBPS"); }
*
* // ✅ Convert to your custom DTO FetchBillValidatestResponse fetchBillResponse
* = objectMapper.convertValue(dataMap, FetchBillValidatestResponse.class);
* GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
*
* // ✅ Build final ResponseModel responseModel = new ResponseModel(
* generalResponse.getMessage(), generalResponse.getStatus(),
* Integer.parseInt(generalResponse.getStatusCode()), fetchBillResponse );
*
* } catch (CustomException ex) { log.warn("Merchant validation failed: {}",
* ex.getMessage()); return ex.getResponseModel(); // Directly return
* ResponseModel from exception } catch (Exception e) {
* log.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
* responseModel.setStatus("500");
* responseModel.setMessage("Exception occurred");
* responseModel.setData(e.getMessage()); }
*
* return responseModel; }
*
* @Override public ResponseModel
* initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) {
*
* ResponseModel responseModel = new ResponseModel(); try {
* helper.validateMerchant(billRequest.getMid());
*
* BharatConnectMaster headersData =
* beneficiaryDetailsRepository.findByOrgId("ORG001");
*
* if (headersData == null) { responseModel = new
* ResponseModel("Tenant Id Is Null", "Not Found", BBPSConstant.BADREQUEST,
* headersData); return responseModel; }
*
* HttpHeaders headers = new HttpHeaders(); headers.set("x-digiledge-key",
* headersData.getXDigiledgeKey()); headers.set("agentId",
* headersData.getAgentId()); headers.set("tenantId",
* headersData.getTenantId());
* headers.setContentType(MediaType.APPLICATION_JSON);
*
* ObjectMapper objectMapper = new ObjectMapper();
* objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String
* json = objectMapper.writeValueAsString(billRequest); String url = agentDtaUrl
* + BBPSConstant.BILL_ID_URL + billRequest.getBillId();
*
* log.info("Full URL: {}", url);
* objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
*
* // ✅ Call the API using httpService Map<String, String> responseMap =
* httpService.getRequest(url, headers); String responseData =
* responseMap.get("data");
*
* log.info("📦 Bill Fetch API Response: {}", responseData);
*
* if (responseData == null || responseData.isEmpty()) { throw new
* CustomException("Empty response from BBPS server"); }
*
* // ✅ Convert JSON string → Map Map<String, Object> dataMap =
* objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>()
* {});
*
* // ✅ Validate generalResp if (!dataMap.containsKey("genericResponse")) {
* throw new CustomException("Invalid response structure from BBPS"); }
*
* // ✅ Convert to your custom DTO BillDataResponse fetchBillResponse =
* objectMapper.convertValue(dataMap, BillDataResponse.class); GeneralResp
* generalResponse = fetchBillResponse.getGenericResponse();
*
* // ✅ Build final ResponseModel responseModel = new ResponseModel(
* generalResponse.getRemarks(), generalResponse.getStatus(),
* Integer.parseInt(generalResponse.getStatusCode()), fetchBillResponse );
*
* } catch (CustomException ex) { log.warn("Merchant validation failed: {}",
* ex.getMessage()); return ex.getResponseModel(); // Directly return
* ResponseModel from exception } catch (Exception e) {
* log.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
* responseModel.setStatus("500");
* responseModel.setMessage("Exception occurred");
* responseModel.setData(e.getMessage()); }
*
* return responseModel; }
*/
/* POLLING METHOD
* public ResponseModel fetchBillById(BillFetchByBillIdRequest