removed heades section from impl and added it in helper
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// java
|
||||
package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -10,7 +11,6 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest;
|
||||
@@ -59,11 +59,15 @@ public class AgentServiceImpl implements AgentService {
|
||||
private final BillInitateRepository billIntiateRepository;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AgentServiceImpl.class);
|
||||
|
||||
// Reusable ObjectMapper instance
|
||||
private final ObjectMapper objectMapper = new ObjectMapper()
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
|
||||
public AgentServiceImpl(RestClient restClient, HttpService httpService, Helper helper,
|
||||
BharatConnectMasterRepository beneficiaryDetailsRepository,
|
||||
InboundTraceLogRepository inboundTraceLogRepository, OutboundTraceLogRepository outboundTraceLogRepository,
|
||||
BillMasterRepository billMasterRepository, BillInitateRepository billIntiateRepository,
|
||||
BillerMapperHelper mapperHelper) {
|
||||
BharatConnectMasterRepository beneficiaryDetailsRepository,
|
||||
InboundTraceLogRepository inboundTraceLogRepository, OutboundTraceLogRepository outboundTraceLogRepository,
|
||||
BillMasterRepository billMasterRepository, BillInitateRepository billIntiateRepository,
|
||||
BillerMapperHelper mapperHelper) {
|
||||
this.restClient = restClient;
|
||||
this.httpService = httpService;
|
||||
this.helper = helper;
|
||||
@@ -84,21 +88,11 @@ public class AgentServiceImpl implements AgentService {
|
||||
fetchBillRequest.setClientReqId(txnId);
|
||||
helper.validateMerchant(fetchBillRequest.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);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
FetchBillForwardRequest forwardReq = helper.fetchBillForwardRequestMap(fetchBillRequest);
|
||||
|
||||
String forwardJson = helper.convertObjectToJson(forwardReq);
|
||||
String requestJson = helper.convertObjectToJson(fetchBillRequest);
|
||||
|
||||
// ✅ Create inbound & outbound logs
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, fetchBillRequest.getMid(),
|
||||
"POST", requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, "POST",
|
||||
@@ -107,7 +101,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling external API: {}", fullUrl);
|
||||
Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, headers);
|
||||
Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001")));
|
||||
String responseData = responseMap.get("data");
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
@@ -133,7 +127,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
FetchBillResponse fetchBillResponse = objectMapper.convertValue(dataMap, FetchBillResponse.class);
|
||||
GeneralResp generalResponse = fetchBillResponse.getGenericResponse();
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus());
|
||||
|
||||
BillInitiate billInitiate = new BillInitiate();
|
||||
billInitiate.setBillId((String) dataMap.get("billId"));
|
||||
@@ -171,20 +165,13 @@ public class AgentServiceImpl implements AgentService {
|
||||
String billId = billFetchByBillIdRequest.getBillId();
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + billFetchByBillIdRequest.getBillId();
|
||||
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);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
|
||||
LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl);
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling external API: {}", fullUrl);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001")));
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Bill FetchById Response: {}", responseData);
|
||||
|
||||
@@ -231,7 +218,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId);
|
||||
|
||||
// create inbound log (GET -> no request body)
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName,
|
||||
billFetchByBillIdRequest.getMid(), "GET", null);
|
||||
|
||||
@@ -239,24 +225,14 @@ public class AgentServiceImpl implements AgentService {
|
||||
helper.validateMerchant(billFetchByBillIdRequest.getMid());
|
||||
LOGGER.debug("Merchant validated successfully for MID={}", 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);
|
||||
|
||||
// create outbound log
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
|
||||
LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001")));
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData);
|
||||
|
||||
// update outbound log with response
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
@@ -264,19 +240,17 @@ public class AgentServiceImpl implements AgentService {
|
||||
if (!dataMap.containsKey("genericResponse")) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
||||
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
|
||||
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();
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
// update inbound log success and persist bill data
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest, txnId);
|
||||
LOGGER.info("Bill data saved successfully for billId={} | Status={}", billId, generalResp.getStatus());
|
||||
@@ -290,8 +264,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseModel initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) {
|
||||
LOGGER.info("Initiating bill Validate for request ID: {} and MID:{} and billerId:{}", fetchBillValidateRequest.getReqId(),
|
||||
@@ -304,15 +276,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
fetchBillValidateRequest.setClientReqId(txnId);
|
||||
helper.validateMerchant(fetchBillValidateRequest.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);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
FetchBillValidatestForwardRequest forwardReq = helper
|
||||
.fetchBillValidatestForwardRequest(fetchBillValidateRequest);
|
||||
|
||||
@@ -320,7 +283,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
String requestJson = helper.convertObjectToJson(fetchBillValidateRequest);
|
||||
|
||||
// ✅ Create inbound & outbound logs
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, fetchBillValidateRequest.getMid(),
|
||||
"POST", requestJson);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "POST", forwardJson);
|
||||
@@ -328,7 +290,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling external API: {}", fullUrl);
|
||||
Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, headers);
|
||||
Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001")));
|
||||
String responseData = responseMap.get("data");
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
@@ -353,7 +315,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
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());
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus());
|
||||
|
||||
BillInitiate billInitiate = new BillInitiate();
|
||||
billInitiate.setBillId((String) dataMap.get("billId"));
|
||||
@@ -380,7 +342,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ResponseModel BillvaidateByBillId(BillFetchByBillIdRequest billRequest, InboundTraceLog inboundLog) {
|
||||
@@ -392,24 +353,15 @@ public class AgentServiceImpl implements AgentService {
|
||||
String reqId = billRequest.getReqId();
|
||||
String billId = billRequest.getBillId();
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_ID_URL + billRequest.getBillId();
|
||||
;
|
||||
|
||||
helper.validateMerchant(billRequest.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);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
|
||||
LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl);
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling external API: {}", fullUrl);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001")));
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Bill FetchById Response: {}", responseData);
|
||||
|
||||
@@ -422,8 +374,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
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")),
|
||||
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")));
|
||||
}
|
||||
@@ -451,7 +402,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseModel initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) {
|
||||
String apiName = "FetchBillById";
|
||||
@@ -462,32 +412,21 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId);
|
||||
|
||||
// create inbound log (GET -> no request body)
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billRequest.getMid(), "GET", null);
|
||||
|
||||
try {
|
||||
helper.validateMerchant(billRequest.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);
|
||||
|
||||
// create outbound log
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null);
|
||||
LOGGER.info("Calling external BBPS API for ValidateByBillId, URL={}", fullUrl);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001")));
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData);
|
||||
|
||||
// update outbound log with response
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Object>>(){});
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Object>>(){});
|
||||
|
||||
if (!dataMap.containsKey("genericResponse")) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
||||
@@ -501,7 +440,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
FetchBillValidateResponse responseWrapper = objectMapper.convertValue(dataMap, FetchBillValidateResponse.class);
|
||||
GeneralResp generalResp = responseWrapper.getGenericResponse();
|
||||
|
||||
// update inbound log and save validation data
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
helper.saveBillValidation(responseWrapper, billRequest);
|
||||
LOGGER.info("Bill validation saved successfully for billId: {}", billId);
|
||||
@@ -515,10 +453,8 @@ public class AgentServiceImpl implements AgentService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================================== Bill fetch and Bill Validate by Client Req Id==================================//
|
||||
|
||||
//... remaining methods unchanged except where headers/objectMapper were previously created (they now use buildHeaders() and the class-level objectMapper)
|
||||
|
||||
@Override
|
||||
public ResponseModel fetchBillValidateByClientReqId(BillValidateByClientIdRequest billValidateByClientIdRequest) {
|
||||
|
||||
@@ -536,16 +472,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
helper.validateMerchant(billValidateByClientIdRequest.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);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 🔵 Create Inbound + Outbound Logs
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName,
|
||||
billValidateByClientIdRequest.getMid(), "GET", null);
|
||||
|
||||
@@ -553,7 +479,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling BBPS API FetchBillValidateByClientReqId, URL={}", fullUrl);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001")));
|
||||
String responseData = responseMap.get("data");
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
@@ -601,16 +527,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
helper.validateMerchant(billFetchByClientIdRequest.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);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 🔵 Create inbound + outbound logs
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billFetchByClientIdRequest.getMid(),
|
||||
"GET", null);
|
||||
|
||||
@@ -618,7 +534,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling BBPS API FetchBillByClientReqId, URL={}", fullUrl);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001")));
|
||||
String responseData = responseMap.get("data");
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
@@ -647,238 +563,30 @@ public class AgentServiceImpl implements AgentService {
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
//================================== End Bill fetch and Bill Validate by Client Req Id==================================//
|
||||
//===================================Callback Methods BillFetch and BillValidate ==================================//
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseModel processBillFetchCallback(BillDataResponse billDataResponse) {
|
||||
|
||||
LOGGER.info("Recived Call Back from billDataResponse: {}", billDataResponse);
|
||||
if(billDataResponse.getGenericResponse().getStatusCode().equals("200")) {
|
||||
|
||||
}
|
||||
if(billDataResponse.getGenericResponse().getStatusCode().equals("200")) { }
|
||||
else {
|
||||
LOGGER.info("Bill Fetch Callback Failed with Status: {}", billDataResponse.getGenericResponse().getStatus());
|
||||
|
||||
}
|
||||
|
||||
return new ResponseModel("CallBack Recieved Successfully",
|
||||
"200",
|
||||
200,
|
||||
"");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel processBillValidateCallback(FetchBillValidateResponse billValidateResponse) {
|
||||
LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", billValidateResponse);
|
||||
if(billValidateResponse.getGenericResponse().getStatusCode().equals("200")) {
|
||||
|
||||
}
|
||||
else {
|
||||
LOGGER.info("Bill Fetch Callback Failed with Status: {}", billValidateResponse.getGenericResponse().getStatus());
|
||||
|
||||
}
|
||||
|
||||
return new ResponseModel("CallBack Recieved Successfully",
|
||||
"200",
|
||||
200,
|
||||
"");
|
||||
|
||||
|
||||
}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
* @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
|
||||
* billFetchByBillIdRequest, InboundTraceLog inboundLog) { 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";
|
||||
*
|
||||
* 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);
|
||||
*
|
||||
* ObjectMapper objectMapper = new ObjectMapper(); OutboundTraceLog outboundLog
|
||||
* = helper.createOutboundLog(txnId, reqId, apiName, url, "GET", null);
|
||||
*
|
||||
* // ✅ Loop setup long startTime = System.currentTimeMillis(); long
|
||||
* maxWaitTimeMs = 40000; // 40 seconds long intervalMs = 5000; // 5 seconds
|
||||
*
|
||||
* while (true) { try { Map<String, String> responseMap =
|
||||
* httpService.getRequest(url, headers); String responseData =
|
||||
* responseMap.get("data"); log.info("📦 Bill FetchById Response: {}",
|
||||
* responseData);
|
||||
*
|
||||
* helper.updateOutboundLogResponse(outboundLog, 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")) ); }
|
||||
*
|
||||
* 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 if ("INPROGRESS".equalsIgnoreCase(status)) { if
|
||||
* (System.currentTimeMillis() - startTime > maxWaitTimeMs) {
|
||||
* helper.updateInboundLogFailure(inboundLog, "Timeout after 40 seconds",
|
||||
* "FAILED"); throw new CustomException("Timeout", "FAILED", 408,
|
||||
* "Bill fetch still in progress"); } Thread.sleep(intervalMs); continue; //
|
||||
* retry again } // ✅ Final successful response
|
||||
* helper.updateInboundLogSuccess(inboundLog, responseData,
|
||||
* generalResp.getStatus()); return new ResponseModel( generalResp.getMessage(),
|
||||
* generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()),
|
||||
* responseWrapper ); } 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"); } catch
|
||||
* (InterruptedException e) { Thread.currentThread().interrupt();
|
||||
* helper.updateInboundLogFailure(inboundLog, e.getMessage(), "INTERRUPTED");
|
||||
* throw new CustomException("Thread interrupted during bill status check"); } }
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseModel processBillValidateCallback(FetchBillValidateResponse billValidateResponse) {
|
||||
LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", billValidateResponse);
|
||||
if(billValidateResponse.getGenericResponse().getStatusCode().equals("200")) { }
|
||||
else {
|
||||
LOGGER.info("Bill Fetch Callback Failed with Status: {}", billValidateResponse.getGenericResponse().getStatus());
|
||||
}
|
||||
return new ResponseModel("CallBack Recieved Successfully",
|
||||
"200",
|
||||
200,
|
||||
"");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user