From 08d5509c1aa03138bd2d70df90b1d941c9bc4e1e Mon Sep 17 00:00:00 2001 From: Lincpay Tech Date: Mon, 24 Nov 2025 13:07:26 +0530 Subject: [PATCH 1/5] added basic strcture for the callbackapi --- .../bbps/controller/AgentController.java | 18 ++++++- .../bbps/service/AgentService.java | 6 +++ .../bbps/service/PaymentService.java | 10 ++-- .../bbps/serviceImpl/AgentServiceImpl.java | 47 ++++++++++++++++++- .../bbps/serviceImpl/PaymentServiceImpl.java | 18 +++++++ 5 files changed, 93 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java b/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java index 1fed6a0..a9edc93 100644 --- a/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java +++ b/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java @@ -9,12 +9,15 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.billpaymentservice.bbps.dto.GeneralResp; import com.billpaymentservice.bbps.dto.ResponseModel; import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest; import com.billpaymentservice.bbps.dto.request.BillFetchByClientIdRequest; import com.billpaymentservice.bbps.dto.request.BillValidateByClientIdRequest; import com.billpaymentservice.bbps.dto.request.FetchBillRequest; import com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest; +import com.billpaymentservice.bbps.dto.response.BillDataResponse; +import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; import com.billpaymentservice.bbps.service.AgentService; @RestController @@ -86,5 +89,18 @@ public class AgentController { ResponseModel response = agentService.fetchBillValidateByClientReqId(billValidateByClientIdRequest); return ResponseEntity.ok(response); } - + + @PostMapping(value="/callback/billFetch", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity handleBillFetchCallback(@RequestBody BillDataResponse billDataResponse) { + ResponseModel genralResp=agentService.processBillFetchCallback(billDataResponse); + // Return a response indicating successful receipt + return ResponseEntity.ok(genralResp); + } + + @PostMapping(value="/callback/billValidate", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity handleBillValidateCallback(@RequestBody FetchBillValidateResponse fetchBillValidateResponse) { + ResponseModel genralResp=agentService.processBillValidateCallback(fetchBillValidateResponse); + // Return a response indicating successful receipt + return ResponseEntity.ok(genralResp); + } } diff --git a/src/main/java/com/billpaymentservice/bbps/service/AgentService.java b/src/main/java/com/billpaymentservice/bbps/service/AgentService.java index 3c5347b..1ebc1ce 100644 --- a/src/main/java/com/billpaymentservice/bbps/service/AgentService.java +++ b/src/main/java/com/billpaymentservice/bbps/service/AgentService.java @@ -6,6 +6,8 @@ import com.billpaymentservice.bbps.dto.request.BillFetchByClientIdRequest; import com.billpaymentservice.bbps.dto.request.BillValidateByClientIdRequest; import com.billpaymentservice.bbps.dto.request.FetchBillRequest; import com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest; +import com.billpaymentservice.bbps.dto.response.BillDataResponse; +import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; public interface AgentService { @@ -21,4 +23,8 @@ public interface AgentService { ResponseModel fetchBillValidateByClientReqId( BillValidateByClientIdRequest billValidateByClientIdRequest); + ResponseModel processBillFetchCallback(BillDataResponse billDataResponse); + + ResponseModel processBillValidateCallback(FetchBillValidateResponse billDataResponse); + } diff --git a/src/main/java/com/billpaymentservice/bbps/service/PaymentService.java b/src/main/java/com/billpaymentservice/bbps/service/PaymentService.java index e724dd6..c932c0f 100644 --- a/src/main/java/com/billpaymentservice/bbps/service/PaymentService.java +++ b/src/main/java/com/billpaymentservice/bbps/service/PaymentService.java @@ -4,13 +4,17 @@ import com.billpaymentservice.bbps.dto.ResponseModel; import com.billpaymentservice.bbps.dto.request.BillPaymentRequest; import com.billpaymentservice.bbps.dto.request.TransactionStatusRequest; import com.billpaymentservice.bbps.dto.request.TrasactionStatusByClientReqIdRequest; +import com.billpaymentservice.bbps.dto.response.TransactionStatusResponse; public interface PaymentService { - public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest); + ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest); - public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest); + ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest); - ResponseModel checkTrasactionStatusByClientReqId(TrasactionStatusByClientReqIdRequest transactionStatusRequest); + ResponseModel checkTrasactionStatusByClientReqId(TrasactionStatusByClientReqIdRequest transactionStatusRequest); + + ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse); + } diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java index 988fc39..6db3df9 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java @@ -368,7 +368,6 @@ public class AgentServiceImpl implements AgentService { billFetchByBillIdRequest.setReqId(reqId); LOGGER.info("Waiting for 2 seconds before fetching bill by ID..."); try { - Thread.sleep(12000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -648,9 +647,53 @@ 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")) { + + } + 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) { * @@ -838,4 +881,4 @@ public class AgentServiceImpl implements AgentService { */ -} + diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java index f0bbb9b..2746039 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java @@ -398,6 +398,24 @@ public class PaymentServiceImpl implements PaymentService { throw new CustomException("Invalid JSON received from API"); } } + + @Override + public ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse) { + + LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", transactionStatusResponse); + if(transactionStatusResponse.getGeneralResp().getStatusCode().equals("200")) { + + } + else { + LOGGER.info("Bill Fetch Callback Failed with Status: {}", transactionStatusResponse.getGeneralResp().getStatus()); + + } + + return new ResponseModel("CallBack Recieved Successfully", + "200", + 200, + ""); + } } /* PollBack logic for the fetchTxnByTxnId API * @Override public ResponseModel fetchTxnByTxnId(BillFetchByBillIdRequest From d8d8bdc3d35f3206c1a71dbd1f8402b526d62dd7 Mon Sep 17 00:00:00 2001 From: Lincpay Tech Date: Mon, 24 Nov 2025 14:54:44 +0530 Subject: [PATCH 2/5] removed heades section from impl and added it in helper --- .../bbps/controller/PaymentController.java | 9 + .../bbps/service/AgentService.java | 2 +- .../bbps/serviceImpl/AgentServiceImpl.java | 374 ++-------- .../bbps/serviceImpl/ComplainServiceImpl.java | 74 +- .../serviceImpl/MasterDataServiceImpl.java | 21 +- .../bbps/serviceImpl/PaymentServiceImpl.java | 688 +++++++----------- .../billpaymentservice/bbps/util/Helper.java | 19 +- 7 files changed, 366 insertions(+), 821 deletions(-) diff --git a/src/main/java/com/billpaymentservice/bbps/controller/PaymentController.java b/src/main/java/com/billpaymentservice/bbps/controller/PaymentController.java index 4632f0b..decc81c 100644 --- a/src/main/java/com/billpaymentservice/bbps/controller/PaymentController.java +++ b/src/main/java/com/billpaymentservice/bbps/controller/PaymentController.java @@ -12,6 +12,8 @@ import com.billpaymentservice.bbps.dto.ResponseModel; import com.billpaymentservice.bbps.dto.request.BillPaymentRequest; import com.billpaymentservice.bbps.dto.request.TransactionStatusRequest; import com.billpaymentservice.bbps.dto.request.TrasactionStatusByClientReqIdRequest; +import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; +import com.billpaymentservice.bbps.dto.response.TransactionStatusResponse; import com.billpaymentservice.bbps.service.PaymentService; @RestController @@ -51,5 +53,12 @@ public class PaymentController { ResponseModel response = paymentService.checkTrasactionStatusByClientReqId(transactionStatusRequest); return ResponseEntity.ok(response); } + + @PostMapping(value="/callback/paymentIntiate", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity handleBillValidateCallback(@RequestBody TransactionStatusResponse transactionStatusResponse) { + ResponseModel genralResp=paymentService.handlePaymentIntiateCallback(transactionStatusResponse); + // Return a response indicating successful receipt + return ResponseEntity.ok(genralResp); + } } diff --git a/src/main/java/com/billpaymentservice/bbps/service/AgentService.java b/src/main/java/com/billpaymentservice/bbps/service/AgentService.java index 1ebc1ce..c3cd078 100644 --- a/src/main/java/com/billpaymentservice/bbps/service/AgentService.java +++ b/src/main/java/com/billpaymentservice/bbps/service/AgentService.java @@ -25,6 +25,6 @@ public interface AgentService { ResponseModel processBillFetchCallback(BillDataResponse billDataResponse); - ResponseModel processBillValidateCallback(FetchBillValidateResponse billDataResponse); + ResponseModel processBillValidateCallback(FetchBillValidateResponse billValidateResponse); } diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java index 6db3df9..9e4f45e 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java @@ -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 responseMap = httpService.postRequest(fullUrl, forwardJson, headers); + Map 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 responseMap = httpService.getRequest(fullUrl, headers); + Map 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 responseMap = httpService.getRequest(fullUrl, headers); + Map 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 dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); @@ -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 responseMap = httpService.postRequest(fullUrl, forwardJson, headers); + Map 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 responseMap = httpService.getRequest(fullUrl, headers); + Map 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 responseMap = httpService.getRequest(fullUrl, headers); + Map 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 dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference>(){}); + Map dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference>(){}); 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 responseMap = httpService.getRequest(fullUrl, headers); + Map 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 responseMap = httpService.getRequest(fullUrl, headers); + Map 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 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 dataMap = - * objectMapper.readValue(responseData, new TypeReference>() - * {}); - * - * // ✅ 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 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 dataMap = - * objectMapper.readValue(responseData, new TypeReference>() - * {}); - * - * // ✅ 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 responseMap = - * httpService.getRequest(url, headers); String responseData = - * responseMap.get("data"); log.info("📦 Bill FetchById Response: {}", - * responseData); - * - * helper.updateOutboundLogResponse(outboundLog, responseData); - * - * Map dataMap = objectMapper.readValue(responseData, new - * TypeReference>() {}); - * - * 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, + ""); + } +} \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java index ce15fc4..1333591 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java @@ -1,3 +1,4 @@ +// language: java package com.billpaymentservice.bbps.serviceImpl; import java.util.List; @@ -19,13 +20,11 @@ import com.billpaymentservice.bbps.dto.request.ComplaintRequestDTO; import com.billpaymentservice.bbps.dto.request.GetTicketLatestStausRequest; import com.billpaymentservice.bbps.dto.request.TxnStatusRequest; import com.billpaymentservice.bbps.dto.request.ViewAllComplaintsTicketsRequest; - import com.billpaymentservice.bbps.dto.request.ViewAllComplaintsRequest; import com.billpaymentservice.bbps.dto.response.ComplaintHistoryStatusResponse; import com.billpaymentservice.bbps.dto.response.ComplaintResponse; import com.billpaymentservice.bbps.dto.response.TicketCheckStatusResponse; import com.billpaymentservice.bbps.dto.response.TxnStatusResponse; - import com.billpaymentservice.bbps.dto.response.ViewAllComplaintsTicketsResponse; import com.billpaymentservice.bbps.dto.response.ViewAllComplaintsResponse; import com.billpaymentservice.bbps.dto.response.ViewComplainByIdResponse; @@ -64,8 +63,9 @@ public class ComplainServiceImpl implements ComplainService { private final ComplainRepository complainRepository; private final ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository; - private final ObjectMapper objectMapper = new ObjectMapper(); - private static final Logger LOGGER = LoggerFactory.getLogger(AgentServiceImpl.class); + // moved to class-level + private final ObjectMapper objectMapper; + private static final Logger LOGGER = LoggerFactory.getLogger(ComplainServiceImpl.class); public ComplainServiceImpl(RestClient restClient, HttpService httpService, Helper helper, BharatConnectMasterRepository beneficiaryDetailsRepository, BillerMapperHelper mapperHelper, @@ -78,6 +78,10 @@ public class ComplainServiceImpl implements ComplainService { this.mapperHelper = mapperHelper; this.complainRepository = complainRepository; this.complaintStatusMasterRepository = complaintStatusMasterRepository; + + // initialize shared ObjectMapper once + this.objectMapper = new ObjectMapper(); + this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Override @@ -99,11 +103,7 @@ public class ComplainServiceImpl implements ComplainService { // Fetch tenant & agent from DB 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); + HttpHeaders headers = helper.buildHeaders(headersData); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, complainRequestDTO.getMid(), "POST", requestJson); @@ -180,11 +180,7 @@ public class ComplainServiceImpl implements ComplainService { 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); + HttpHeaders headers = helper.buildHeaders(headersData); // Convert request to JSON String requestJson = helper.convertObjectToJson(request); @@ -215,11 +211,11 @@ public class ComplainServiceImpl implements ComplainService { int end = responseData.lastIndexOf("}"); if (start != -1 && end != -1) { responseData = responseData.substring(start, end + 1); - LOGGER.info("Extracted Clean JSON: {}", responseData); } + + LOGGER.info("Extracted pure JSON from error: {}", responseData); } - // Convert JSON to Map Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); @@ -231,25 +227,17 @@ public class ComplainServiceImpl implements ComplainService { statusCode, String.valueOf(dataMap.get("remarks"))); } - TicketCheckStatusResponse responseWrapper = objectMapper.convertValue(dataMap, - TicketCheckStatusResponse.class); - - LOGGER.info("Complaint Current Status: {}", responseWrapper.getStatus()); + TicketCheckStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TicketCheckStatusResponse.class); helper.updateInboundLogSuccess(inboundLog, responseData, responseWrapper.getStatus()); - // Save in DB - mapperHelper.saveComplaintStatus(responseWrapper, reqId, txnId); - return new ResponseModel(responseWrapper.getMessage(), responseWrapper.getStatus(), Integer.parseInt(responseWrapper.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { - - LOGGER.error("Error parsing Complaint Status JSON: {}", e.getMessage()); + LOGGER.error("Error parsing JSON in complaint status API: {}", e.getMessage(), e); helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); throw new CustomException("Invalid JSON received from API"); - } } @@ -266,14 +254,8 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.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); + HttpHeaders headers = helper.buildHeaders(headersData); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String requestJson = helper.convertObjectToJson(request); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET", @@ -333,14 +315,8 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.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); + HttpHeaders headers = helper.buildHeaders(headersData); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String requestJson = helper.convertObjectToJson(request); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET", @@ -442,14 +418,8 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.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); + HttpHeaders headers = helper.buildHeaders(headersData); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String requestJson = helper.convertObjectToJson(request); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET", @@ -508,14 +478,8 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.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); + HttpHeaders headers = helper.buildHeaders(headersData); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String requestJson = helper.convertObjectToJson(request); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "POST", @@ -562,4 +526,4 @@ public class ComplainServiceImpl implements ComplainService { } } -} +} \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java index 3244d07..e044769 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java @@ -1,4 +1,3 @@ -// java package com.billpaymentservice.bbps.serviceImpl; import java.util.List; @@ -10,6 +9,8 @@ import org.modelmapper.convention.MatchingStrategies; 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; import org.springframework.stereotype.Service; import com.billpaymentservice.bbps.dto.ContactMaster; @@ -56,6 +57,7 @@ import com.billpaymentservice.bbps.util.BBPSConstant; import com.billpaymentservice.bbps.util.BillerMapperHelper; import com.billpaymentservice.bbps.util.EntityRelationshipUtil; import com.billpaymentservice.bbps.util.Helper; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -76,7 +78,7 @@ public class MasterDataServiceImpl implements MasterDataService { private final Helper helper; private final BillerDataRepository billerDataRespository; private final HttpService httpService; - private final ObjectMapper objectMapper = new ObjectMapper(); + private final ObjectMapper objectMapper; private final InboundTraceLogRepository inboundTraceLogRepository; private final OutboundTraceLogRepository outboundTraceLogRepository; private final CustomParamRepository customParamReposiotory; @@ -98,6 +100,8 @@ public class MasterDataServiceImpl implements MasterDataService { this.mapperHelper = mapperHelper; this.customParamReposiotory = customParamReposiotory; + this.objectMapper = new ObjectMapper(); + this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } @Override @@ -112,7 +116,7 @@ public class MasterDataServiceImpl implements MasterDataService { try { // Merchant Validation helper.validateMerchant(masterRequest.getMid()); - // check Tender Id is present DB + // check Tenant Id is present DB BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); if (headersData == null) { LOGGER.warn("header data not found for the orgID"); @@ -122,10 +126,10 @@ public class MasterDataServiceImpl implements MasterDataService { String fullUrl = masterRegisterUrl + BBPSConstant.MASTER_CATEGORY_URL + headersData.getTenantId(); LOGGER.info("Calling external API: {}", fullUrl); OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); - Map responseMap = httpService.getRequest(fullUrl); + HttpHeaders headers = helper.buildHeaders(headersData); + Map responseMap = httpService.getRequest(fullUrl, headers); String responseData = responseMap.get("data"); - // LOGGER.info("Response Data: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { @@ -290,7 +294,8 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Contact Master Full URL-:" + fullUrl); OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); - Map responseMap = httpService.getRequest(fullUrl); + HttpHeaders headers = helper.buildHeaders(headersData); + Map responseMap = httpService.getRequest(fullUrl, headers); String responseData = responseMap.get("data"); LOGGER.info("Response Data: {}", responseData); @@ -407,8 +412,6 @@ public class MasterDataServiceImpl implements MasterDataService { helper.updateOutboundLogResponse(outboundLog, responseData); try { - ObjectMapper objectMapper = new ObjectMapper(); - Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); @@ -750,8 +753,6 @@ public class MasterDataServiceImpl implements MasterDataService { helper.updateOutboundLogResponse(outboundLog, responseData); try { - ObjectMapper objectMapper = new ObjectMapper(); - Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java index 2746039..7d74dc0 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java @@ -1,3 +1,4 @@ +// PaymentServiceImpl.java package com.billpaymentservice.bbps.serviceImpl; import java.util.Map; @@ -46,496 +47,343 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Service public class PaymentServiceImpl implements PaymentService { - @Value("${payment.data.url}") - private String paymentUrl; + @Value("${payment.data.url}") + private String paymentUrl; - private final BharatConnectMasterRepository beneficiaryDetailsRepository; - private final HttpService httpService; - private final Helper helper; - private final PaymentRepository paymentRepository; - private final InboundTraceLogRepository inboundTraceLogRepository; - private final OutboundTraceLogRepository outboundTraceLogRepository; - private final PaymentIntiateRepository paymentIntiateRepository; - private final TransactionMasterRepository transactionMasterRepository; - private final AgentFundTransferRepository agentFundTransferRepository; + private final BharatConnectMasterRepository beneficiaryDetailsRepository; + private final HttpService httpService; + private final Helper helper; + private final PaymentRepository paymentRepository; + private final InboundTraceLogRepository inboundTraceLogRepository; + private final OutboundTraceLogRepository outboundTraceLogRepository; + private final PaymentIntiateRepository paymentIntiateRepository; + private final TransactionMasterRepository transactionMasterRepository; + private final AgentFundTransferRepository agentFundTransferRepository; - private static final Logger LOGGER = LoggerFactory.getLogger(PaymentServiceImpl.class); + // Shared reusable instances + private final ObjectMapper objectMapper; + private final ModelMapper modelMapper; - public PaymentServiceImpl(BharatConnectMasterRepository beneficiaryDetailsRepository, HttpService httpService, - Helper helper, PaymentRepository paymentRepository, InboundTraceLogRepository inboundTraceLogRepository, - OutboundTraceLogRepository outboundTraceLogRepository, PaymentIntiateRepository paymentIntiateRepository, - TransactionMasterRepository transactionMasterRepository, - AgentFundTransferRepository agentFundTransferRepository) { - this.beneficiaryDetailsRepository = beneficiaryDetailsRepository; - this.httpService = httpService; - this.helper = helper; - this.paymentRepository = paymentRepository; - this.inboundTraceLogRepository = inboundTraceLogRepository; - this.outboundTraceLogRepository = outboundTraceLogRepository; - this.paymentIntiateRepository = paymentIntiateRepository; - this.transactionMasterRepository = transactionMasterRepository; - this.agentFundTransferRepository = agentFundTransferRepository; - } + private static final Logger LOGGER = LoggerFactory.getLogger(PaymentServiceImpl.class); - @Override - public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) { - String apiName = "InitiatePayment"; - String txnId = helper.generateTxnId(15); - String requestId = billPaymentRequest.getReqId(); - String url = paymentUrl + BBPSConstant.PAYMENT_URL; - billPaymentRequest.setClientReqId(txnId); - LOGGER.info("Initiating payment for reqId={} and txnId={}", requestId, txnId); + public PaymentServiceImpl(BharatConnectMasterRepository beneficiaryDetailsRepository, HttpService httpService, + Helper helper, PaymentRepository paymentRepository, InboundTraceLogRepository inboundTraceLogRepository, + OutboundTraceLogRepository outboundTraceLogRepository, PaymentIntiateRepository paymentIntiateRepository, + TransactionMasterRepository transactionMasterRepository, + AgentFundTransferRepository agentFundTransferRepository) { + this.beneficiaryDetailsRepository = beneficiaryDetailsRepository; + this.httpService = httpService; + this.helper = helper; + this.paymentRepository = paymentRepository; + this.inboundTraceLogRepository = inboundTraceLogRepository; + this.outboundTraceLogRepository = outboundTraceLogRepository; + this.paymentIntiateRepository = paymentIntiateRepository; + this.transactionMasterRepository = transactionMasterRepository; + this.agentFundTransferRepository = agentFundTransferRepository; - 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); + this.objectMapper = new ObjectMapper(); + this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - BillPaymentForwardRequest forwardReq = - helper.billPaymentForwardRequest(billPaymentRequest); + this.modelMapper = new ModelMapper(); + this.modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); + } - String forwardjson = helper.convertObjectToJson(forwardReq); + @Override + public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) { + String apiName = "InitiatePayment"; + String txnId = helper.generateTxnId(15); + String requestId = billPaymentRequest.getReqId(); + String url = paymentUrl + BBPSConstant.PAYMENT_URL; + billPaymentRequest.setClientReqId(txnId); + LOGGER.info("Initiating payment for reqId={} and txnId={}", requestId, txnId); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + HttpHeaders headers = helper.buildHeaders(headersData); - String requestJson = helper.convertObjectToJson(billPaymentRequest); + BillPaymentForwardRequest forwardReq = helper.billPaymentForwardRequest(billPaymentRequest); + String forwardjson = helper.convertObjectToJson(forwardReq); + String requestJson = helper.convertObjectToJson(billPaymentRequest); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(), "POST", requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "POST",forwardjson); + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(), "POST", requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "POST", forwardjson); - try { - LOGGER.info("Calling BBPS payment URL: {}", url); - Map responseMap = httpService.postRequest(url, forwardjson, headers); - String responseData = responseMap.get("data"); - LOGGER.info("Payment API Response: {}", responseData); + try { + LOGGER.info("Calling BBPS payment URL: {}", url); + Map responseMap = httpService.postRequest(url, forwardjson, headers); + String responseData = responseMap.get("data"); + LOGGER.info("Payment API Response: {}", responseData); - helper.updateOutboundLogResponse(outboundLog, responseData); + helper.updateOutboundLogResponse(outboundLog, responseData); - if (responseData == null || responseData.isEmpty()) { - helper.updateInboundLogFailure(inboundLog, "Empty response from BBPS", "FAILED"); - LOGGER.warn("Empty response received from BBPS for txnId={}", txnId); - throw new CustomException("Empty response from BBPS server"); - } + if (responseData == null || responseData.isEmpty()) { + helper.updateInboundLogFailure(inboundLog, "Empty response from BBPS", "FAILED"); + LOGGER.warn("Empty response received from BBPS for txnId={}", txnId); + throw new CustomException("Empty response from BBPS server"); + } - Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_STRUCTURE"); - LOGGER.warn("Invalid response structure received for txnId={}", txnId); - throw new CustomException("Invalid response structure from BBPS"); - } + Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); + if (!dataMap.containsKey("genericResponse")) { + helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_STRUCTURE"); + LOGGER.warn("Invalid response structure received for txnId={}", txnId); + throw new CustomException("Invalid response structure from BBPS"); + } - BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class); - GeneralResp generalResponse = billPaymentResponse.getGenericResponse(); + BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class); + GeneralResp generalResponse = billPaymentResponse.getGenericResponse(); - ModelMapper mapper = new ModelMapper(); - mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); - BillPayment entity = mapper.map(billPaymentResponse, BillPayment.class); - paymentRepository.save(entity); - LOGGER.info("BillPayment entity saved successfully for txnId={}", txnId); + BillPayment entity = modelMapper.map(billPaymentResponse, BillPayment.class); + paymentRepository.save(entity); + LOGGER.info("BillPayment entity saved successfully for txnId={}", txnId); - helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus()); - PaymentInitiate paymentInitiate = new PaymentInitiate(); - paymentInitiate.setTxnId(txnId); - paymentInitiate.setReqId(requestId); - paymentInitiate.setBankTxnId(billPaymentResponse.getTxnId()); - paymentInitiate.setStatus(billPaymentResponse.getStatus()); - paymentIntiateRepository.save(paymentInitiate); - LOGGER.info("PaymentInitiate entry saved successfully for txnId={}", txnId); + helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus()); + PaymentInitiate paymentInitiate = new PaymentInitiate(); + paymentInitiate.setTxnId(txnId); + paymentInitiate.setReqId(requestId); + paymentInitiate.setBankTxnId(billPaymentResponse.getTxnId()); + paymentInitiate.setStatus(billPaymentResponse.getStatus()); + paymentIntiateRepository.save(paymentInitiate); + LOGGER.info("PaymentInitiate entry saved successfully for txnId={}", txnId); - TransactionStatusRequest transactionStatusRequest = new TransactionStatusRequest(); - transactionStatusRequest.setTxnId(billPaymentResponse.getTxnId()); - transactionStatusRequest.setReqId(requestId); - - try { - Thread.sleep(9000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage()); - } - LOGGER.info("Checking transaction status for txnId={}", billPaymentResponse.getTxnId()); - return checkTrasactionStatus(transactionStatusRequest, inboundLog); + TransactionStatusRequest transactionStatusRequest = new TransactionStatusRequest(); + transactionStatusRequest.setTxnId(billPaymentResponse.getTxnId()); + transactionStatusRequest.setReqId(requestId); - } catch (JsonProcessingException e) { - LOGGER.error("JSON Parsing Error in initiatePayment: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); - throw new CustomException("Invalid JSON received from API"); - } - } + try { + Thread.sleep(9000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage()); + } + LOGGER.info("Checking transaction status for txnId={}", billPaymentResponse.getTxnId()); + return checkTrasactionStatus(transactionStatusRequest, inboundLog); - public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest, InboundTraceLog inboundLog) { - String apiName = "CheckTransactionStatus"; - String txnId = helper.generateTxnId(15); - String requestId = transactionStatusRequest.getReqId(); - - - String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); + } catch (JsonProcessingException e) { + LOGGER.error("JSON Parsing Error in initiatePayment: {}", e.getMessage(), e); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + throw new CustomException("Invalid JSON received from API"); + } + } - LOGGER.info("Checking transaction status (internal) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); + public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest, InboundTraceLog inboundLog) { + String apiName = "CheckTransactionStatus"; + String txnId = helper.generateTxnId(15); + String requestId = transactionStatusRequest.getReqId(); - 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); + String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); - ObjectMapper objectMapper = new ObjectMapper(); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "GET", null); + LOGGER.info("Checking transaction status (internal) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); - Map responseMap = httpService.getRequest(url, headers); - String responseData = responseMap.get("data"); - LOGGER.info("Transaction status response: {}", responseData); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + HttpHeaders headers = helper.buildHeaders(headersData); - helper.updateOutboundLogResponse(outboundLog, responseData); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "GET", null); - try { - Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); - LOGGER.warn("Invalid transaction status response for txnId={}", transactionStatusRequest.getTxnId()); - 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")) - ); - } + Map responseMap = httpService.getRequest(url, headers); + String responseData = responseMap.get("data"); + LOGGER.info("Transaction status response: {}", responseData); - TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TransactionStatusResponse.class); - GeneralResp generalResp = responseWrapper.getGeneralResp(); - LOGGER.info("Transaction status received: {}", generalResp.getStatus()); + helper.updateOutboundLogResponse(outboundLog, responseData); - ModelMapper mapper = new ModelMapper(); - mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); - TransactionMaster transactionMaster = mapper.map(responseWrapper.getTransactionDAO(), TransactionMaster.class); - transactionMaster.setTxnId(txnId); - transactionMaster.setReqId(transactionStatusRequest.getReqId()); - EntityRelationshipUtil.linkTransactionMasterRelationships(transactionMaster); - transactionMasterRepository.save(transactionMaster); - LOGGER.info("TransactionMaster saved successfully for txnId={}", txnId); + try { + Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); + if (!dataMap.containsKey("generalResp")) { + helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + LOGGER.warn("Invalid transaction status response for txnId={}", transactionStatusRequest.getTxnId()); + 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")) + ); + } - AgentFundTransfer agentFundTransfer = mapper.map(responseWrapper.getAgentFundTransfer(), AgentFundTransfer.class); - agentFundTransfer.setTxnId(txnId); - agentFundTransfer.setReqId(transactionStatusRequest.getReqId()); - agentFundTransfer.setTransactionMasterId(transactionMaster.getBankTxnId()); - agentFundTransferRepository.save(agentFundTransfer); - LOGGER.info("AgentFundTransfer entry saved successfully for txnId={}", txnId); + TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TransactionStatusResponse.class); + GeneralResp generalResp = responseWrapper.getGeneralResp(); + LOGGER.info("Transaction status received: {}", generalResp.getStatus()); - ResponseModel responseModel = new ResponseModel( - generalResp.getMessage(), - generalResp.getStatus(), - Integer.parseInt(generalResp.getStatusCode()), - responseWrapper - ); + TransactionMaster transactionMaster = modelMapper.map(responseWrapper.getTransactionDAO(), TransactionMaster.class); + transactionMaster.setTxnId(txnId); + transactionMaster.setReqId(transactionStatusRequest.getReqId()); + EntityRelationshipUtil.linkTransactionMasterRelationships(transactionMaster); + transactionMasterRepository.save(transactionMaster); + LOGGER.info("TransactionMaster saved successfully for txnId={}", txnId); - helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - return responseModel; + AgentFundTransfer agentFundTransfer = modelMapper.map(responseWrapper.getAgentFundTransfer(), AgentFundTransfer.class); + agentFundTransfer.setTxnId(txnId); + agentFundTransfer.setReqId(transactionStatusRequest.getReqId()); + agentFundTransfer.setTransactionMasterId(transactionMaster.getBankTxnId()); + agentFundTransferRepository.save(agentFundTransfer); + LOGGER.info("AgentFundTransfer entry saved successfully for txnId={}", txnId); - } catch (JsonProcessingException e) { - LOGGER.error("Error parsing transaction status JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); - throw new CustomException("Invalid JSON received from API"); - } - } + ResponseModel responseModel = new ResponseModel( + generalResp.getMessage(), + generalResp.getStatus(), + Integer.parseInt(generalResp.getStatusCode()), + responseWrapper + ); - @Override - public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) { - helper.validateMerchant(transactionStatusRequest.getMid()); - String txnID = helper.generateTxnId(15); - String apiName = "checkTrasactionStatus"; - String requestId = transactionStatusRequest.getReqId(); - String requestJson = helper.convertObjectToJson(transactionStatusRequest); - String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); + helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); + return responseModel; - LOGGER.info("Checking transaction status (public) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); + } catch (JsonProcessingException e) { + LOGGER.error("Error parsing transaction status JSON: {}", e.getMessage(), e); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + throw new CustomException("Invalid JSON received from API"); + } + } - 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); + @Override + public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) { + helper.validateMerchant(transactionStatusRequest.getMid()); + String txnID = helper.generateTxnId(15); + String apiName = "checkTrasactionStatus"; + String requestId = transactionStatusRequest.getReqId(); + String requestJson = helper.convertObjectToJson(transactionStatusRequest); + String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, transactionStatusRequest.getMid(), "POST", requestJson); + LOGGER.info("Checking transaction status (public) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); + + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + HttpHeaders headers = helper.buildHeaders(headersData); + + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, transactionStatusRequest.getMid(), "POST", requestJson); OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, "GET", null); - ObjectMapper objectMapper = new ObjectMapper(); - Map responseMap = httpService.getRequest(url, headers); - String responseData = responseMap.get("data"); - LOGGER.info("Transaction status response data: {}", responseData); - helper.updateOutboundLogResponse(outboundLog, responseData); + Map responseMap = httpService.getRequest(url, headers); + String responseData = responseMap.get("data"); + LOGGER.info("Transaction status response data: {}", responseData); + helper.updateOutboundLogResponse(outboundLog, responseData); - try { - Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - LOGGER.warn("Invalid transaction status response for txnId={} from BBPS", transactionStatusRequest.getTxnId()); - 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")) - ); - } + try { + Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); + if (!dataMap.containsKey("generalResp")) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); + LOGGER.warn("Invalid transaction status response for txnId={} from BBPS", transactionStatusRequest.getTxnId()); + 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")) + ); + } - TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TransactionStatusResponse.class); - GeneralResp generalResp = responseWrapper.getGeneralResp(); + TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TransactionStatusResponse.class); + GeneralResp generalResp = responseWrapper.getGeneralResp(); - String status = generalResp.getStatus(); - LOGGER.info("Current transaction status: {}", status); + String status = generalResp.getStatus(); + LOGGER.info("Current transaction status: {}", status); - ResponseModel responseModel = new ResponseModel( - generalResp.getMessage(), - generalResp.getStatus(), - Integer.parseInt(generalResp.getStatusCode()), - responseWrapper - ); + ResponseModel responseModel = new ResponseModel( + generalResp.getMessage(), + generalResp.getStatus(), + Integer.parseInt(generalResp.getStatusCode()), + responseWrapper + ); - helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - return responseModel; + helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); + return responseModel; - } catch (JsonProcessingException e) { - LOGGER.error("Error parsing responseData JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); - throw new CustomException("Invalid JSON received from API"); - } - } + } catch (JsonProcessingException e) { + LOGGER.error("Error parsing responseData JSON: {}", e.getMessage(), e); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + throw new CustomException("Invalid JSON received from API"); + } + } + @Override + public ResponseModel checkTrasactionStatusByClientReqId(TrasactionStatusByClientReqIdRequest transactionStatusRequest) { + helper.validateMerchant(transactionStatusRequest.getMid()); - @Override - public ResponseModel checkTrasactionStatusByClientReqId(TrasactionStatusByClientReqIdRequest transactionStatusRequest) { + String txnID = helper.generateTxnId(15); + String apiName = "checkTrasactionStatusbyClientReqId"; + String requestId = transactionStatusRequest.getReqId(); + String clientReqId = transactionStatusRequest.getClientReqId(); + String requestJson = helper.convertObjectToJson(transactionStatusRequest); - helper.validateMerchant(transactionStatusRequest.getMid()); + LOGGER.info("Checking transaction status for clientReqId={} and reqId={}", clientReqId, requestId); - String txnID = helper.generateTxnId(15); - String apiName = "checkTrasactionStatusbyClientReqId"; - String requestId = transactionStatusRequest.getReqId(); - String clientReqId = transactionStatusRequest.getClientReqId(); - String requestJson = helper.convertObjectToJson(transactionStatusRequest); + Optional paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId); + if (paymentInitiate.isEmpty()) { + throw new CustomException("No Transaction Found for given Client Req Id"); + } - LOGGER.info("Checking transaction status for clientReqId={} and reqId={}", clientReqId, requestId); + String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_BY_CLIENT_REQ_ID_URL + paymentInitiate.get().getTxnId(); - // Fetch Txn from DB - Optional paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId); - if (paymentInitiate.isEmpty()) { - throw new CustomException("No Transaction Found for given Client Req Id"); - } + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + HttpHeaders headers = helper.buildHeaders(headersData); - String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_BY_CLIENT_REQ_ID_URL + paymentInitiate.get().getTxnId(); + InboundTraceLog inboundLog = helper.createInboundLog( + requestId, txnID, apiName, transactionStatusRequest.getMid(), "POST", requestJson); - // Prepare headers - 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); + OutboundTraceLog outboundLog = helper.createOutboundLog( + txnID, requestId, apiName, url, "GET", null); + try { + LOGGER.info("Calling BBPS Transaction Status API URL={}", url); + Map responseMap = httpService.getRequest(url, headers); - // 🔵 Create Inbound + Outbound Logs - InboundTraceLog inboundLog = helper.createInboundLog( - requestId, txnID, apiName, transactionStatusRequest.getMid(), "POST", requestJson); + String responseData = responseMap.get("data"); + LOGGER.info("Transaction Status Response: {}", responseData); - OutboundTraceLog outboundLog = helper.createOutboundLog( - txnID, requestId, apiName, url, "GET", null); + helper.updateOutboundLogResponse(outboundLog, responseData); - ObjectMapper objectMapper = new ObjectMapper(); + Map dataMap = objectMapper.readValue( + responseData, new TypeReference>() {}); - try { - LOGGER.info("Calling BBPS Transaction Status API URL={}", url); - Map responseMap = httpService.getRequest(url, headers); + if (!dataMap.containsKey("generalResp")) { + helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); - String responseData = responseMap.get("data"); - LOGGER.info("Transaction Status Response: {}", responseData); + LOGGER.warn("Invalid transaction status response for clientReqId={} | Response={}", + clientReqId, responseData); - helper.updateOutboundLogResponse(outboundLog, responseData); + 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")) + ); + } - // Parse response - Map dataMap = objectMapper.readValue( - responseData, new TypeReference>() {}); + TransactionStatusResponse responseWrapper = + objectMapper.convertValue(dataMap, TransactionStatusResponse.class); - // Validate response - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + GeneralResp generalResp = responseWrapper.getGeneralResp(); - LOGGER.warn("Invalid transaction status response for clientReqId={} | Response={}", - clientReqId, responseData); + LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus()); - 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.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - // Convert into proper DTO - TransactionStatusResponse responseWrapper = - objectMapper.convertValue(dataMap, TransactionStatusResponse.class); + return new ResponseModel( + generalResp.getMessage(), + generalResp.getStatus(), + Integer.parseInt(generalResp.getStatusCode()), + responseWrapper + ); - GeneralResp generalResp = responseWrapper.getGeneralResp(); + } catch (JsonProcessingException e) { + LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e); - LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus()); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); - helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); + throw new CustomException("Invalid JSON received from API"); + } + } - return new ResponseModel( - generalResp.getMessage(), - generalResp.getStatus(), - Integer.parseInt(generalResp.getStatusCode()), - responseWrapper - ); + @Override + public ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse) { - } catch (JsonProcessingException e) { - LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e); + LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", transactionStatusResponse); + if (transactionStatusResponse.getGeneralResp().getStatusCode().equals("200")) { - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + } else { + LOGGER.info("Bill Fetch Callback Failed with Status: {}", transactionStatusResponse.getGeneralResp().getStatus()); - throw new CustomException("Invalid JSON received from API"); - } - } + } - @Override - public ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse) { - - LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", transactionStatusResponse); - if(transactionStatusResponse.getGeneralResp().getStatusCode().equals("200")) { - - } - else { - LOGGER.info("Bill Fetch Callback Failed with Status: {}", transactionStatusResponse.getGeneralResp().getStatus()); - - } - - return new ResponseModel("CallBack Recieved Successfully", - "200", - 200, - ""); - } -} - /* PollBack logic for the fetchTxnByTxnId API - * @Override public ResponseModel fetchTxnByTxnId(BillFetchByBillIdRequest - * billFetchByBillIdRequest) { - * - * String billId = billFetchByBillIdRequest.getBillId(); String fullUrl = - * agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID+billId; - * System.out.print(fullUrl); - * - * BeneficiaryDetails - * 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 responseMap = httpService.getRequest(fullUrl,headers); - * String responseData = responseMap.get("data"); log.info("data is :{}", - * responseData); - * - * - * ObjectMapper objectMapper = new ObjectMapper(); - * - * try { Map dataMap = objectMapper.readValue(responseData, new - * TypeReference>() { }); 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); - * - * return responseModel; - * - * } catch (JsonProcessingException e) { - * LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); throw - * new CustomException("Invalid JSON received from API"); } - * - * } - */ - - /* - * public ResponseModel checkTrasactionStatus(TransactionStatusRequest - * transactionStatusRequest,InboundTraceLog inboundLog) { String apiName = - * "CheckTransactionStatus"; String txnId = helper.generateTxnId(15); //our - * genrated txnId String requestId = transactionStatusRequest.getReqId(); String - * url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + - * transactionStatusRequest.getTxnId(); ; - * - * 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, requestId, - * apiName, url, "GET", null); - * - * long startTime = System.currentTimeMillis(); long maxWaitTimeMs = 40000; long - * intervalMs = 5000; - * - * while (true) { Map responseMap = httpService.getRequest(url, - * headers); String responseData = responseMap.get("data"); - * LOGGER.info("Transaction status response: {}", responseData); - * - * helper.updateOutboundLogResponse(outboundLog, responseData); - * - * try { Map dataMap = objectMapper.readValue(responseData, new - * TypeReference>() {}); - * - * if (!dataMap.containsKey("generalResp")) { - * 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")) ); } - * - * TransactionStatusResponse responseWrapper = - * objectMapper.convertValue(dataMap, TransactionStatusResponse.class); - * GeneralResp generalResp = responseWrapper.getGeneralResp(); - * - * String status = generalResp.getStatus(); - * LOGGER.info("Current transaction status: {}", status); - * - * if ("INPROGRESS".equalsIgnoreCase(status)) { if (System.currentTimeMillis() - - * startTime > maxWaitTimeMs) { helper.updateInboundLogFailure(inboundLog, - * "Timeout after 40 seconds", "FAILED"); throw new - * CustomException("Timeout waiting for transaction completion", "FAILED", 408, - * "Transaction still in progress"); } - * - * Thread.sleep(intervalMs); continue; } - * - * ResponseModel responseModel = new ResponseModel( generalResp.getMessage(), - * generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()), - * responseWrapper ); - * - * helper.updateInboundLogSuccess(inboundLog, responseData, - * generalResp.getStatus()); return responseModel; - * - * } catch (JsonProcessingException e) { - * LOGGER.error("Error parsing transaction status 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 transaction check"); } } - * } - * - * - */ \ No newline at end of file + return new ResponseModel("CallBack Recieved Successfully", + "200", + 200, + ""); + } +} \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/util/Helper.java b/src/main/java/com/billpaymentservice/bbps/util/Helper.java index a73ca30..405bde2 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/Helper.java +++ b/src/main/java/com/billpaymentservice/bbps/util/Helper.java @@ -11,6 +11,8 @@ import java.util.stream.Collectors; import org.modelmapper.ModelMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import com.billpaymentservice.bbps.dto.AdditionalInfoBillDTO; @@ -38,6 +40,7 @@ import com.billpaymentservice.bbps.entites.InboundTraceLog; import com.billpaymentservice.bbps.entites.OutboundTraceLog; import com.billpaymentservice.bbps.entites.PaymentChannel; import com.billpaymentservice.bbps.entites.PaymentMode; +import com.billpaymentservice.bbps.entites.BharatConnectMaster; import com.billpaymentservice.bbps.exception.CustomException; import com.billpaymentservice.bbps.repository.BBPSMasterDataRepo; import com.billpaymentservice.bbps.repository.BillMasterRepository; @@ -214,6 +217,19 @@ public class Helper { } /* ---------- End helpers ---------- */ + + // New reusable header builder for BBPS calls + public HttpHeaders buildHeaders(BharatConnectMaster headersData) { + HttpHeaders headers = new HttpHeaders(); + if (headersData != null) { + headers.set("x-digiledge-key", headersData.getXDigiledgeKey()); + headers.set("agentId", headersData.getAgentId()); + headers.set("tenantId", headersData.getTenantId()); + } + headers.setContentType(MediaType.APPLICATION_JSON); + return headers; + } + public void saveOrUpdateBillerData(BillerDetails newEntity) { Optional existingOpt = billerDataRespository.findByBillerId(newEntity.getBillerId()); @@ -233,7 +249,7 @@ public void saveOrUpdateBillData(BillDataResponse responseWrapper, BillMaster billMaster = new BillMaster(); -billMaster.setBillId(billFetchByBillIdRequest.getBillId()); +billMaster.setBillId(responseWrapper.getBillId()); billMaster.setRefId(responseWrapper.getRefId()); billMaster.setBillerId(responseWrapper.getBillerId()); billMaster.setStatus(responseWrapper.getStatus()); @@ -242,7 +258,6 @@ billMaster.setUserId(responseWrapper.getUserId()); billMaster.setReqId(billFetchByBillIdRequest.getReqId()); billMaster.setTxnId(txnId); - // BILLER RESPONSE BillerResponse billerResponse = new BillerResponse(); if (responseWrapper.getBillerResponse() != null) { From c9dfb6f9ba018a751449a13530201270e58d3d48 Mon Sep 17 00:00:00 2001 From: Lincpay Tech Date: Mon, 24 Nov 2025 16:34:55 +0530 Subject: [PATCH 3/5] moved some mapper code from helper to billerMapper --- .../bbps/serviceImpl/AgentServiceImpl.java | 15 +- .../serviceImpl/MasterDataServiceImpl.java | 2 +- .../bbps/serviceImpl/PaymentServiceImpl.java | 9 +- .../bbps/util/BillerMapperHelper.java | 232 +++++++++++++++++- .../billpaymentservice/bbps/util/Helper.java | 206 +--------------- 5 files changed, 247 insertions(+), 217 deletions(-) diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java index 9e4f45e..29bab13 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java @@ -3,7 +3,6 @@ package com.billpaymentservice.bbps.serviceImpl; import java.util.Map; import java.util.Optional; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -88,7 +87,7 @@ public class AgentServiceImpl implements AgentService { fetchBillRequest.setClientReqId(txnId); helper.validateMerchant(fetchBillRequest.getMid()); - FetchBillForwardRequest forwardReq = helper.fetchBillForwardRequestMap(fetchBillRequest); + FetchBillForwardRequest forwardReq = mapperHelper.fetchBillForwardRequestMap(fetchBillRequest); String forwardJson = helper.convertObjectToJson(forwardReq); String requestJson = helper.convertObjectToJson(fetchBillRequest); @@ -127,7 +126,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")); @@ -196,7 +195,7 @@ public class AgentServiceImpl implements AgentService { LOGGER.info("Current Bill Status: {}", status); helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - helper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest, txnId); + mapperHelper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest, txnId); LOGGER.info("Bill data saved successfully for billId: {}", billId); return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), @@ -252,7 +251,7 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - helper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest, txnId); + mapperHelper.saveOrUpdateBillData(responseWrapper, billFetchByBillIdRequest, txnId); LOGGER.info("Bill data saved successfully for billId={} | Status={}", billId, generalResp.getStatus()); return responseModel; @@ -276,7 +275,7 @@ public class AgentServiceImpl implements AgentService { fetchBillValidateRequest.setClientReqId(txnId); helper.validateMerchant(fetchBillValidateRequest.getMid()); - FetchBillValidatestForwardRequest forwardReq = helper + FetchBillValidatestForwardRequest forwardReq = mapperHelper .fetchBillValidatestForwardRequest(fetchBillValidateRequest); String forwardJson = helper.convertObjectToJson(forwardReq); @@ -388,7 +387,7 @@ public class AgentServiceImpl implements AgentService { helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); System.out.println("responseWrapper:" + responseWrapper); - helper.saveBillValidation(responseWrapper, billRequest); + mapperHelper.saveBillValidation(responseWrapper, billRequest); LOGGER.info("Bill data saved successfully for billId: {}", billId); return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), @@ -441,7 +440,7 @@ public class AgentServiceImpl implements AgentService { GeneralResp generalResp = responseWrapper.getGenericResponse(); helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - helper.saveBillValidation(responseWrapper, billRequest); + mapperHelper.saveBillValidation(responseWrapper, billRequest); LOGGER.info("Bill validation saved successfully for billId: {}", billId); return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()), responseWrapper); diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java index e044769..dc84b78 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java @@ -200,7 +200,7 @@ public class MasterDataServiceImpl implements MasterDataService { mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); BillerDetails entity = mapper.map(responseWrapper.getBillerDAO(), BillerDetails.class); EntityRelationshipUtil.linkBillerRelationships(entity);// linking nesting entity foreign key - helper.saveOrUpdateBillerData(entity); + mapperHelper.saveOrUpdateBillerData(entity); ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()), responseWrapper); diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java index 7d74dc0..d54bb22 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java @@ -37,6 +37,7 @@ import com.billpaymentservice.bbps.repository.PaymentRepository; import com.billpaymentservice.bbps.repository.TransactionMasterRepository; import com.billpaymentservice.bbps.service.PaymentService; import com.billpaymentservice.bbps.util.BBPSConstant; +import com.billpaymentservice.bbps.util.BillerMapperHelper; import com.billpaymentservice.bbps.util.EntityRelationshipUtil; import com.billpaymentservice.bbps.util.Helper; import com.fasterxml.jackson.annotation.JsonInclude; @@ -59,7 +60,7 @@ public class PaymentServiceImpl implements PaymentService { private final PaymentIntiateRepository paymentIntiateRepository; private final TransactionMasterRepository transactionMasterRepository; private final AgentFundTransferRepository agentFundTransferRepository; - + private final BillerMapperHelper mapperHelper; // Shared reusable instances private final ObjectMapper objectMapper; private final ModelMapper modelMapper; @@ -70,7 +71,8 @@ public class PaymentServiceImpl implements PaymentService { Helper helper, PaymentRepository paymentRepository, InboundTraceLogRepository inboundTraceLogRepository, OutboundTraceLogRepository outboundTraceLogRepository, PaymentIntiateRepository paymentIntiateRepository, TransactionMasterRepository transactionMasterRepository, - AgentFundTransferRepository agentFundTransferRepository) { + AgentFundTransferRepository agentFundTransferRepository, + BillerMapperHelper mapperHelper) { this.beneficiaryDetailsRepository = beneficiaryDetailsRepository; this.httpService = httpService; this.helper = helper; @@ -80,6 +82,7 @@ public class PaymentServiceImpl implements PaymentService { this.paymentIntiateRepository = paymentIntiateRepository; this.transactionMasterRepository = transactionMasterRepository; this.agentFundTransferRepository = agentFundTransferRepository; + this.mapperHelper = mapperHelper; this.objectMapper = new ObjectMapper(); this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); @@ -100,7 +103,7 @@ public class PaymentServiceImpl implements PaymentService { BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); HttpHeaders headers = helper.buildHeaders(headersData); - BillPaymentForwardRequest forwardReq = helper.billPaymentForwardRequest(billPaymentRequest); + BillPaymentForwardRequest forwardReq = mapperHelper.billPaymentForwardRequest(billPaymentRequest); String forwardjson = helper.convertObjectToJson(forwardReq); String requestJson = helper.convertObjectToJson(billPaymentRequest); diff --git a/src/main/java/com/billpaymentservice/bbps/util/BillerMapperHelper.java b/src/main/java/com/billpaymentservice/bbps/util/BillerMapperHelper.java index 903f2c6..9a63f65 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/BillerMapperHelper.java +++ b/src/main/java/com/billpaymentservice/bbps/util/BillerMapperHelper.java @@ -6,6 +6,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import org.modelmapper.ModelMapper; @@ -14,6 +15,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import com.billpaymentservice.bbps.dto.AdditionalInfoBillDTO; import com.billpaymentservice.bbps.dto.AmountOptionDTO; import com.billpaymentservice.bbps.dto.BillAdditionalInfoDTO; import com.billpaymentservice.bbps.dto.BillCustomerParamsDTO; @@ -21,6 +23,7 @@ import com.billpaymentservice.bbps.dto.BillerIconDTO; import com.billpaymentservice.bbps.dto.CheckClientBillerResponseDTO; import com.billpaymentservice.bbps.dto.ComplaintHistoryDTO; import com.billpaymentservice.bbps.dto.ContactMaster; +import com.billpaymentservice.bbps.dto.CustomerParamDAO; import com.billpaymentservice.bbps.dto.CustomerParamGroupsDTO; import com.billpaymentservice.bbps.dto.Detail; import com.billpaymentservice.bbps.dto.GroupDTO; @@ -28,22 +31,37 @@ import com.billpaymentservice.bbps.dto.MasterCategoryBillerResponse; import com.billpaymentservice.bbps.dto.PlanDTO; import com.billpaymentservice.bbps.dto.TicketDetailsDTO; import com.billpaymentservice.bbps.dto.TicketDispositionsDTO; +import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest; +import com.billpaymentservice.bbps.dto.request.BillPaymentRequest; +import com.billpaymentservice.bbps.dto.request.FetchBillRequest; +import com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest; import com.billpaymentservice.bbps.dto.response.AmountOptionsResponse; +import com.billpaymentservice.bbps.dto.response.BillDataResponse; import com.billpaymentservice.bbps.dto.response.ClientReqIdResponse; import com.billpaymentservice.bbps.dto.response.ComplaintHistoryStatusResponse; +import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; import com.billpaymentservice.bbps.dto.response.PlanResponse; import com.billpaymentservice.bbps.dto.response.TicketCheckStatusResponse; import com.billpaymentservice.bbps.dto.response.ViewAllComplaintsResponse; import com.billpaymentservice.bbps.dto.response.ViewAllComplaintsTicketsResponse; import com.billpaymentservice.bbps.dto.response.ViewComplainByIdResponse; +import com.billpaymentservice.bbps.dto.sentRequest.BillPaymentForwardRequest; +import com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest; +import com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest; +import com.billpaymentservice.bbps.entites.AdditionalInfoBill; +import com.billpaymentservice.bbps.entites.AdditionalInfoBillValidate; import com.billpaymentservice.bbps.entites.AdditionalInfoPlans; import com.billpaymentservice.bbps.entites.AmountOptionByBillerId; import com.billpaymentservice.bbps.entites.AmountOptionDetails; import com.billpaymentservice.bbps.entites.BillAdditionalInfo; import com.billpaymentservice.bbps.entites.BillCustomerParams; +import com.billpaymentservice.bbps.entites.BillMaster; import com.billpaymentservice.bbps.entites.BillTag; +import com.billpaymentservice.bbps.entites.BillValidation; import com.billpaymentservice.bbps.entites.BillerCategoryIcon; import com.billpaymentservice.bbps.entites.BillerCategoryWise; +import com.billpaymentservice.bbps.entites.BillerDetails; +import com.billpaymentservice.bbps.entites.BillerResponse; import com.billpaymentservice.bbps.entites.CategoryResponseList; import com.billpaymentservice.bbps.entites.CheckClientBillerData; import com.billpaymentservice.bbps.entites.CheckClientStatusReqId; @@ -51,6 +69,8 @@ import com.billpaymentservice.bbps.entites.ComplainStatus; import com.billpaymentservice.bbps.entites.ComplaintHistory; import com.billpaymentservice.bbps.entites.ComplaintStatusDetails; import com.billpaymentservice.bbps.entites.ContactMasterData; +import com.billpaymentservice.bbps.entites.CustomerParamBill; +import com.billpaymentservice.bbps.entites.CustomerParamBillValidation; import com.billpaymentservice.bbps.entites.CustomerParamGroupById; import com.billpaymentservice.bbps.entites.GroupParam; import com.billpaymentservice.bbps.entites.Plan; @@ -61,7 +81,11 @@ import com.billpaymentservice.bbps.entites.TicketDispositionDetails; import com.billpaymentservice.bbps.entites.ViewAllComplaintTicketStatusDetails; import com.billpaymentservice.bbps.exception.CustomException; import com.billpaymentservice.bbps.repository.AmountOptionByBillerIdRepository; +import com.billpaymentservice.bbps.repository.BBPSMasterDataRepo; +import com.billpaymentservice.bbps.repository.BillMasterRepository; +import com.billpaymentservice.bbps.repository.BillValidationRepository; import com.billpaymentservice.bbps.repository.BillerCategoryWiseRepository; +import com.billpaymentservice.bbps.repository.BillerDataRepository; import com.billpaymentservice.bbps.repository.CategoryResponseListRepository; import com.billpaymentservice.bbps.repository.CheckClientBillerDataRepository; import com.billpaymentservice.bbps.repository.ClientReqIdRepository; @@ -96,6 +120,10 @@ public class BillerMapperHelper { private final CheckClientBillerDataRepository checkClientBillerDataRepository; private final ViewAllComplainTicketDetailRepository viewAllComplainTicketDetailRepository; private final ContactMasterDataRepository contactMasterDataRepository; + private final BBPSMasterDataRepo bbpsMasterDataRepo; + private final BillerDataRepository billerDataRespository; + private final BillMasterRepository billMasterRepository; + private final BillValidationRepository billValidationRepository; public BillerMapperHelper(BillerCategoryWiseRepository billerRepo, CustomerParamGroupByBillerIdRepository customerParamGroupByBillerIdRepo, @@ -109,7 +137,11 @@ public class BillerMapperHelper { CheckClientBillerDataRepository checkClientBillerDataRepository, TicketDispositionRepository ticketDispositionRepository, ViewAllComplainTicketDetailRepository viewAllComplainTicketDetailRepository, - ContactMasterDataRepository contactMasterDataRepository) { + ContactMasterDataRepository contactMasterDataRepository, + BBPSMasterDataRepo bbpsMasterDataRepo, + BillerDataRepository billerDataRespository, + BillMasterRepository billMasterRepository, + BillValidationRepository billValidationRepository) { this.billerRepo = billerRepo; this.customerParamGroupByBillerIdRepo = customerParamGroupByBillerIdRepo; this.amountOptionByBillerIdRepository = amountOptionByBillerIdRepository; @@ -125,6 +157,10 @@ public class BillerMapperHelper { this.ticketDispositionRepository = ticketDispositionRepository; this.viewAllComplainTicketDetailRepository = viewAllComplainTicketDetailRepository; this.contactMasterDataRepository = contactMasterDataRepository; + this.bbpsMasterDataRepo = bbpsMasterDataRepo; + this.billerDataRespository = billerDataRespository; + this.billMasterRepository = billMasterRepository; + this.billValidationRepository = billValidationRepository; } /** @@ -822,4 +858,198 @@ public class BillerMapperHelper { return "Contact Master Saved Successfully"; } + public void saveOrUpdateBillerData(BillerDetails newEntity) { + + Optional existingOpt = billerDataRespository.findByBillerId(newEntity.getBillerId()); + + if (existingOpt.isPresent()) { + //logic to be written + } + else { + // brand new biller + billerDataRespository.save(newEntity); + } + } + +public void saveOrUpdateBillData(BillDataResponse responseWrapper, + BillFetchByBillIdRequest billFetchByBillIdRequest,String txnId) { + + +BillMaster billMaster = new BillMaster(); + +billMaster.setBillId(responseWrapper.getBillId()); +billMaster.setRefId(responseWrapper.getRefId()); +billMaster.setBillerId(responseWrapper.getBillerId()); +billMaster.setStatus(responseWrapper.getStatus()); +billMaster.setActionType(responseWrapper.getActionType()); +billMaster.setUserId(responseWrapper.getUserId()); +billMaster.setReqId(billFetchByBillIdRequest.getReqId()); +billMaster.setTxnId(txnId); + +// BILLER RESPONSE +BillerResponse billerResponse = new BillerResponse(); +if (responseWrapper.getBillerResponse() != null) { +billerResponse.setBillId(responseWrapper.getBillerResponse().getBillId()); +billerResponse.setAmount(responseWrapper.getBillerResponse().getAmount()); +billerResponse.setBillDate(responseWrapper.getBillerResponse().getBillDate()); +billerResponse.setBillNumber(responseWrapper.getBillerResponse().getBillNumber()); +billerResponse.setBillPeriod(responseWrapper.getBillerResponse().getBillPeriod()); +billerResponse.setCustConvFee(responseWrapper.getBillerResponse().getCustConvFee()); +billerResponse.setCouCustConvFee(responseWrapper.getBillerResponse().getCouCustConvFee()); +billerResponse.setDueDate(responseWrapper.getBillerResponse().getDueDate()); +billerResponse.setCustomerName(responseWrapper.getBillerResponse().getCustomerName()); +billerResponse.setAmountOption(responseWrapper.getBillerResponse().isAmountOption()); +billerResponse.setBillMaster(billMaster); +} +billMaster.setBillerResponse(billerResponse); + + + +// ADDITIONAL INFO +List additionalInfos = new ArrayList<>(); +if (responseWrapper.getAdditionalInfo() != null) { +for (AdditionalInfoBillDTO info : responseWrapper.getAdditionalInfo()) { +AdditionalInfoBill entity = new AdditionalInfoBill(); +entity.setName(info.getName()); +entity.setValue(info.getValue()); +entity.setBillMaster(billMaster); +additionalInfos.add(entity); +} +} +billMaster.setAdditionalInfo(additionalInfos); + + + +// CUSTOMER PARAMS +List customerParams = new ArrayList<>(); +if (responseWrapper.getCustomerParams() != null) { +for (CustomerParamDAO param : responseWrapper.getCustomerParams()) { +CustomerParamBill entity = new CustomerParamBill(); +entity.setName(param.getName()); +entity.setValue(param.getValue() == null ? "" : param.getValue()); +entity.setType(param.getType() == null ? "" : param.getType()); +entity.setBillMaster(billMaster); +customerParams.add(entity); +} +} +billMaster.setCustomerParams(customerParams); + + + +// DATES +billMaster.setCreationDate(responseWrapper.getCreationDate()); +billMaster.setModifiedDate(responseWrapper.getModifiedDate()); +billMaster.setCreatedEpochDate(responseWrapper.getCreatedEpochDate()); +billMaster.setModifiedEpochDate(responseWrapper.getModifiedEpochDate()); + + +billMasterRepository.save(billMaster); +} + + public void saveBillValidation(FetchBillValidateResponse responseWrapper, BillFetchByBillIdRequest billRequest) { + System.out.println("responseWrapper"); + ModelMapper modelMapper = new ModelMapper(); + + try { + LOGGER.info("Saving bill validation data for billId={}", responseWrapper.getBillId()); + + // ✅ Map the main object + BillValidation billEntity = modelMapper.map(responseWrapper, BillValidation.class); + // ✅ Manually handle only the nested relationship part + if (responseWrapper.getCustomerParams() != null) { + List customerParams = responseWrapper.getCustomerParams() + .stream() + .map(param -> { + CustomerParamBillValidation cp = modelMapper.map(param, CustomerParamBillValidation.class); + cp.setBill(billEntity); // maintain relation + return cp; + }) + .collect(Collectors.toList()); + billEntity.setCustomerParams(customerParams); + } + if (responseWrapper.getAdditionalInfo() != null) { + List additionalInfos = responseWrapper.getAdditionalInfo() + .stream() + .map(info -> { + AdditionalInfoBillValidate ai = modelMapper.map(info, AdditionalInfoBillValidate.class); + ai.setBill(billEntity); // maintain relation + return ai; + }) + .collect(Collectors.toList()); + billEntity.setAdditionalInfo(additionalInfos); + + } + // ✅ Save everything (cascade handles child) + + billValidationRepository.save(billEntity); + + LOGGER.info("Bill validation saved successfully for billId={}", billEntity.getBillId()); + } catch (Exception ex) { + LOGGER.error("Error saving BillValidation data: {}", ex.getMessage(), ex); + throw new RuntimeException("Failed to save bill validation data", ex); + } + + +} + + public FetchBillForwardRequest fetchBillForwardRequestMap(FetchBillRequest req) { + + FetchBillForwardRequest forward = new FetchBillForwardRequest(); + + forward.setBillerId(req.getBillerId()); + forward.setBillerName(req.getBillerName()); + forward.setBillerCategory(req.getBillerCategory()); + forward.setClientReqId(req.getClientReqId()); + forward.setMacAdress(req.getMacAdress()); + forward.setCustomerMobNo(req.getCustomerMobNo()); + forward.setRemitterName(req.getRemitterName()); + forward.setPaymentChannel(req.getPaymentChannel()); + forward.setDeviceBlockTags(req.getDeviceBlockTags()); + forward.setCustomerParamsRequest(req.getCustomerParamsRequest()); + forward.setRemitterIdentity(req.getRemitterIdentity()); + + return forward; + } + + public FetchBillValidatestForwardRequest fetchBillValidatestForwardRequest(FetchBillValidatestRequest req) { + + FetchBillValidatestForwardRequest forward = new FetchBillValidatestForwardRequest(); + + forward.setBillerId(req.getBillerId()); + forward.setBillerName(req.getBillerName()); + forward.setBillerCategory(req.getBillerCategory()); + forward.setCustomerMobNo(req.getCustomerMobNo()); + forward.setClientReqId(req.getClientReqId()); + forward.setMacAddress(req.getMacAddress()); + forward.setCustomerParamsRequest(req.getCustomerParamsRequest()); + + return forward; + } + public BillPaymentForwardRequest billPaymentForwardRequest(BillPaymentRequest req) { + + BillPaymentForwardRequest forward = new BillPaymentForwardRequest(); + + forward.setTenantId(req.getTenantId()); + forward.setRefId(req.getRefId()); + forward.setBillId(req.getBillId()); + forward.setAmountOptions(req.isAmountOptions()); + forward.setPaymentMode(req.getPaymentMode()); + forward.setPaymentInformation(req.getPaymentInformation()); + forward.setBillerId(req.getBillerId()); + forward.setBillerName(req.getBillerName()); + forward.setBillerCategory(req.getBillerCategory()); + forward.setMacAdress(req.getMacAdress()); + forward.setCustomerMobNo(req.getCustomerMobNo()); + forward.setTxnAmount(req.getTxnAmount()); + forward.setPaymentRefId(req.getPaymentRefId()); + forward.setClientReqId(req.getClientReqId()); + forward.setPaymentChannel(req.getPaymentChannel()); + + forward.setDeviceBlockTags(req.getDeviceBlockTags()); + forward.setCustomerParamsRequest(req.getCustomerParamsRequest()); + forward.setRemitterIdentity(req.getRemitterIdentity()); + forward.setAmountBreakSet(req.getAmountBreakSet()); + + return forward; + } } diff --git a/src/main/java/com/billpaymentservice/bbps/util/Helper.java b/src/main/java/com/billpaymentservice/bbps/util/Helper.java index 405bde2..edda1a7 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/Helper.java +++ b/src/main/java/com/billpaymentservice/bbps/util/Helper.java @@ -60,23 +60,16 @@ public class Helper { private static final String CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; private static final SecureRandom secureRandom = new SecureRandom(); private final ObjectMapper objectMapper = new ObjectMapper(); - private final BBPSMasterDataRepo bbpsMasterDataRepo; - private final BillerDataRepository billerDataRespository; - private final BillMasterRepository billMasterRepository; - private final BillValidationRepository billValidationRepository; + // Constructor Injection public Helper(BBPSMasterDataRepo bbpsMasterDataRepo, InboundTraceLogRepository inboundTraceLogRepository, OutboundTraceLogRepository outboundTraceLogRepository,BillerDataRepository billerDataRepository, BillMasterRepository billMasterRepository,BillValidationRepository billValidationRepository) { - this.bbpsMasterDataRepo = bbpsMasterDataRepo; this.inboundTraceLogRepository = inboundTraceLogRepository; this.outboundTraceLogRepository = outboundTraceLogRepository; - this.billerDataRespository=billerDataRepository; - this.billMasterRepository=billMasterRepository; - this.billValidationRepository=billValidationRepository; - } + this.bbpsMasterDataRepo = bbpsMasterDataRepo;} /** * Validates whether the merchant exists and is active. @@ -88,7 +81,6 @@ public class Helper { * * */ - public void startPolling(T requestObject, // Request object (any type) Function apiCallFunction, // Function to call API int intervalSeconds, // gap between two polls @@ -230,198 +222,4 @@ public class Helper { return headers; } - public void saveOrUpdateBillerData(BillerDetails newEntity) { - - Optional existingOpt = billerDataRespository.findByBillerId(newEntity.getBillerId()); - - if (existingOpt.isPresent()) { - //logic to be written - } - else { - // brand new biller - billerDataRespository.save(newEntity); - } - } - -public void saveOrUpdateBillData(BillDataResponse responseWrapper, - BillFetchByBillIdRequest billFetchByBillIdRequest,String txnId) { - - -BillMaster billMaster = new BillMaster(); - -billMaster.setBillId(responseWrapper.getBillId()); -billMaster.setRefId(responseWrapper.getRefId()); -billMaster.setBillerId(responseWrapper.getBillerId()); -billMaster.setStatus(responseWrapper.getStatus()); -billMaster.setActionType(responseWrapper.getActionType()); -billMaster.setUserId(responseWrapper.getUserId()); -billMaster.setReqId(billFetchByBillIdRequest.getReqId()); -billMaster.setTxnId(txnId); - -// BILLER RESPONSE -BillerResponse billerResponse = new BillerResponse(); -if (responseWrapper.getBillerResponse() != null) { -billerResponse.setBillId(responseWrapper.getBillerResponse().getBillId()); -billerResponse.setAmount(responseWrapper.getBillerResponse().getAmount()); -billerResponse.setBillDate(responseWrapper.getBillerResponse().getBillDate()); -billerResponse.setBillNumber(responseWrapper.getBillerResponse().getBillNumber()); -billerResponse.setBillPeriod(responseWrapper.getBillerResponse().getBillPeriod()); -billerResponse.setCustConvFee(responseWrapper.getBillerResponse().getCustConvFee()); -billerResponse.setCouCustConvFee(responseWrapper.getBillerResponse().getCouCustConvFee()); -billerResponse.setDueDate(responseWrapper.getBillerResponse().getDueDate()); -billerResponse.setCustomerName(responseWrapper.getBillerResponse().getCustomerName()); -billerResponse.setAmountOption(responseWrapper.getBillerResponse().isAmountOption()); -billerResponse.setBillMaster(billMaster); -} -billMaster.setBillerResponse(billerResponse); - - - -// ADDITIONAL INFO -List additionalInfos = new ArrayList<>(); -if (responseWrapper.getAdditionalInfo() != null) { -for (AdditionalInfoBillDTO info : responseWrapper.getAdditionalInfo()) { -AdditionalInfoBill entity = new AdditionalInfoBill(); -entity.setName(info.getName()); -entity.setValue(info.getValue()); -entity.setBillMaster(billMaster); -additionalInfos.add(entity); -} -} -billMaster.setAdditionalInfo(additionalInfos); - - - -// CUSTOMER PARAMS -List customerParams = new ArrayList<>(); -if (responseWrapper.getCustomerParams() != null) { -for (CustomerParamDAO param : responseWrapper.getCustomerParams()) { -CustomerParamBill entity = new CustomerParamBill(); -entity.setName(param.getName()); -entity.setValue(param.getValue() == null ? "" : param.getValue()); -entity.setType(param.getType() == null ? "" : param.getType()); -entity.setBillMaster(billMaster); -customerParams.add(entity); -} -} -billMaster.setCustomerParams(customerParams); - - - -// DATES -billMaster.setCreationDate(responseWrapper.getCreationDate()); -billMaster.setModifiedDate(responseWrapper.getModifiedDate()); -billMaster.setCreatedEpochDate(responseWrapper.getCreatedEpochDate()); -billMaster.setModifiedEpochDate(responseWrapper.getModifiedEpochDate()); - - -billMasterRepository.save(billMaster); -} - - public void saveBillValidation(FetchBillValidateResponse responseWrapper, BillFetchByBillIdRequest billRequest) { - System.out.println("responseWrapper"); - ModelMapper modelMapper = new ModelMapper(); - - try { - LOGGER.info("Saving bill validation data for billId={}", responseWrapper.getBillId()); - - // ✅ Map the main object - BillValidation billEntity = modelMapper.map(responseWrapper, BillValidation.class); - // ✅ Manually handle only the nested relationship part - if (responseWrapper.getCustomerParams() != null) { - List customerParams = responseWrapper.getCustomerParams() - .stream() - .map(param -> { - CustomerParamBillValidation cp = modelMapper.map(param, CustomerParamBillValidation.class); - cp.setBill(billEntity); // maintain relation - return cp; - }) - .collect(Collectors.toList()); - billEntity.setCustomerParams(customerParams); - } - if (responseWrapper.getAdditionalInfo() != null) { - List additionalInfos = responseWrapper.getAdditionalInfo() - .stream() - .map(info -> { - AdditionalInfoBillValidate ai = modelMapper.map(info, AdditionalInfoBillValidate.class); - ai.setBill(billEntity); // maintain relation - return ai; - }) - .collect(Collectors.toList()); - billEntity.setAdditionalInfo(additionalInfos); - - } - // ✅ Save everything (cascade handles child) - - billValidationRepository.save(billEntity); - - LOGGER.info("Bill validation saved successfully for billId={}", billEntity.getBillId()); - } catch (Exception ex) { - LOGGER.error("Error saving BillValidation data: {}", ex.getMessage(), ex); - throw new RuntimeException("Failed to save bill validation data", ex); - } - - -} - - public FetchBillForwardRequest fetchBillForwardRequestMap(FetchBillRequest req) { - - FetchBillForwardRequest forward = new FetchBillForwardRequest(); - - forward.setBillerId(req.getBillerId()); - forward.setBillerName(req.getBillerName()); - forward.setBillerCategory(req.getBillerCategory()); - forward.setClientReqId(req.getClientReqId()); - forward.setMacAdress(req.getMacAdress()); - forward.setCustomerMobNo(req.getCustomerMobNo()); - forward.setRemitterName(req.getRemitterName()); - forward.setPaymentChannel(req.getPaymentChannel()); - forward.setDeviceBlockTags(req.getDeviceBlockTags()); - forward.setCustomerParamsRequest(req.getCustomerParamsRequest()); - forward.setRemitterIdentity(req.getRemitterIdentity()); - - return forward; - } - - public FetchBillValidatestForwardRequest fetchBillValidatestForwardRequest(FetchBillValidatestRequest req) { - - FetchBillValidatestForwardRequest forward = new FetchBillValidatestForwardRequest(); - - forward.setBillerId(req.getBillerId()); - forward.setBillerName(req.getBillerName()); - forward.setBillerCategory(req.getBillerCategory()); - forward.setCustomerMobNo(req.getCustomerMobNo()); - forward.setClientReqId(req.getClientReqId()); - forward.setMacAddress(req.getMacAddress()); - forward.setCustomerParamsRequest(req.getCustomerParamsRequest()); - - return forward; - } - public BillPaymentForwardRequest billPaymentForwardRequest(BillPaymentRequest req) { - - BillPaymentForwardRequest forward = new BillPaymentForwardRequest(); - - forward.setTenantId(req.getTenantId()); - forward.setRefId(req.getRefId()); - forward.setBillId(req.getBillId()); - forward.setAmountOptions(req.isAmountOptions()); - forward.setPaymentMode(req.getPaymentMode()); - forward.setPaymentInformation(req.getPaymentInformation()); - forward.setBillerId(req.getBillerId()); - forward.setBillerName(req.getBillerName()); - forward.setBillerCategory(req.getBillerCategory()); - forward.setMacAdress(req.getMacAdress()); - forward.setCustomerMobNo(req.getCustomerMobNo()); - forward.setTxnAmount(req.getTxnAmount()); - forward.setPaymentRefId(req.getPaymentRefId()); - forward.setClientReqId(req.getClientReqId()); - forward.setPaymentChannel(req.getPaymentChannel()); - - forward.setDeviceBlockTags(req.getDeviceBlockTags()); - forward.setCustomerParamsRequest(req.getCustomerParamsRequest()); - forward.setRemitterIdentity(req.getRemitterIdentity()); - forward.setAmountBreakSet(req.getAmountBreakSet()); - - return forward; - } } \ No newline at end of file From 435ee0dacf1e90cca5fd43a50ab316d48dafb7cc Mon Sep 17 00:00:00 2001 From: Lincpay Tech Date: Mon, 24 Nov 2025 17:48:54 +0530 Subject: [PATCH 4/5] added constant in bbps constant --- .../bbps/serviceImpl/AgentServiceImpl.java | 135 +++++---- .../bbps/serviceImpl/ComplainServiceImpl.java | 172 +++++------ .../serviceImpl/MasterDataServiceImpl.java | 271 +++++++++--------- .../bbps/serviceImpl/PaymentServiceImpl.java | 1 - .../bbps/util/BBPSConstant.java | 78 ++++- .../bbps/util/EntityRelationshipUtil.java | 3 - .../billpaymentservice/bbps/util/Helper.java | 59 ---- 7 files changed, 368 insertions(+), 351 deletions(-) diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java index 29bab13..5196372 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java @@ -6,8 +6,7 @@ import java.util.Optional; 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; + import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; import com.billpaymentservice.bbps.dto.GeneralResp; @@ -22,7 +21,6 @@ import com.billpaymentservice.bbps.dto.response.FetchBillResponse; import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; import com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest; import com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest; -import com.billpaymentservice.bbps.entites.BharatConnectMaster; import com.billpaymentservice.bbps.entites.BillInitiate; import com.billpaymentservice.bbps.entites.BillMaster; import com.billpaymentservice.bbps.entites.InboundTraceLog; @@ -41,7 +39,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; @Service public class AgentServiceImpl implements AgentService { @@ -80,7 +77,7 @@ public class AgentServiceImpl implements AgentService { public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) { LOGGER.info("Initiating bill fetch for request ID: {} and MID :{} and billerId:{} ", fetchBillRequest.getReqId(), fetchBillRequest.getMid(),fetchBillRequest.getBillerId()); - String apiName = "InitiateBillFetch"; + String apiName = BBPSConstant.API_INITIATE_BILL_FETCH; String txnId = helper.generateTxnId(15); String requestId = fetchBillRequest.getReqId(); String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_INTI; @@ -93,8 +90,8 @@ public class AgentServiceImpl implements AgentService { String requestJson = helper.convertObjectToJson(fetchBillRequest); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, fetchBillRequest.getMid(), - "POST", requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, "POST", + BBPSConstant.HTTP_POST, requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, BBPSConstant.HTTP_POST, forwardJson); LOGGER.debug("Outbound log created successfully for txnId: {} and reqId: {}", txnId, requestId); @@ -107,10 +104,10 @@ public class AgentServiceImpl implements AgentService { LOGGER.debug("Response received from BBPS: {}", responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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"))), @@ -150,7 +147,7 @@ public class AgentServiceImpl implements AgentService { return fetchBillById(billFetchByBillIdRequest, inboundLog); } catch (JsonProcessingException e) { LOGGER.error("JSON Parsing Error: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -158,14 +155,14 @@ public class AgentServiceImpl implements AgentService { 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 apiName = BBPSConstant.API_FETCH_BILL_BY_ID; String txnId = helper.generateTxnId(15); String reqId = billFetchByBillIdRequest.getReqId(); String billId = billFetchByBillIdRequest.getBillId(); String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + billFetchByBillIdRequest.getBillId(); helper.validateMerchant(billFetchByBillIdRequest.getMid()); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl); try { @@ -177,11 +174,11 @@ public class AgentServiceImpl implements AgentService { helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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"))), @@ -202,14 +199,14 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { LOGGER.error("Error parsing BillById JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @Override public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest) { - String apiName = "FetchBillById"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_ID; String txnId = helper.generateTxnId(15); String reqId = billFetchByBillIdRequest.getReqId(); String billId = billFetchByBillIdRequest.getBillId(); @@ -218,13 +215,13 @@ public class AgentServiceImpl implements AgentService { LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, - billFetchByBillIdRequest.getMid(), "GET", null); + billFetchByBillIdRequest.getMid(), BBPSConstant.HTTP_GET, null); try { helper.validateMerchant(billFetchByBillIdRequest.getMid()); LOGGER.debug("Merchant validated successfully for MID={}", billFetchByBillIdRequest.getMid()); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); String responseData = responseMap.get("data"); @@ -237,7 +234,7 @@ public class AgentServiceImpl implements AgentService { }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), @@ -258,7 +255,7 @@ public class AgentServiceImpl implements AgentService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON for billId={} : {}", billId, e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -268,7 +265,7 @@ public class AgentServiceImpl implements AgentService { LOGGER.info("Initiating bill Validate for request ID: {} and MID:{} and billerId:{}", fetchBillValidateRequest.getReqId(), fetchBillValidateRequest.getMid(),fetchBillValidateRequest.getBillerId()); - String apiName = "InitiateBillValidate"; + String apiName = BBPSConstant.API_INITIATE_BILL_VALIDATE; String txnId = helper.generateTxnId(15); String reqId = fetchBillValidateRequest.getReqId(); String fullUrl = agentDtaUrl + BBPSConstant.BILLER_VALIDATE_URL; @@ -283,8 +280,8 @@ public class AgentServiceImpl implements AgentService { String requestJson = helper.convertObjectToJson(fetchBillValidateRequest); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, fetchBillValidateRequest.getMid(), - "POST", requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "POST", forwardJson); + BBPSConstant.HTTP_POST, requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_POST, forwardJson); LOGGER.debug("Outbound log created successfully for txnId: {} and reqId: {}", txnId, reqId); try { @@ -296,10 +293,10 @@ public class AgentServiceImpl implements AgentService { LOGGER.debug("Response received from BBPS: {}", responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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"))), @@ -338,7 +335,7 @@ public class AgentServiceImpl implements AgentService { return BillvaidateByBillId(billFetchByBillIdRequest, inboundLog); } catch (JsonProcessingException e) { LOGGER.error("JSON Parsing Error: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -347,7 +344,7 @@ public class AgentServiceImpl implements AgentService { { LOGGER.info("Validating bill by BILLID for request ID={} and MID={}", billRequest.getReqId(), billRequest.getMid()); - String apiName = "FetchBillById"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_ID; String txnId = helper.generateTxnId(15); String reqId = billRequest.getReqId(); String billId = billRequest.getBillId(); @@ -355,7 +352,7 @@ public class AgentServiceImpl implements AgentService { helper.validateMerchant(billRequest.getMid()); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.debug("Outbound log created successfully for FetchBillById: {}", fullUrl); try { @@ -367,11 +364,11 @@ public class AgentServiceImpl implements AgentService { helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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"))), @@ -394,7 +391,7 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { LOGGER.error("Error parsing BillById JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } @@ -403,7 +400,7 @@ public class AgentServiceImpl implements AgentService { @Override public ResponseModel initiateBillValidateByBillId(BillFetchByBillIdRequest billRequest) { - String apiName = "FetchBillById"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_ID; String txnId = helper.generateTxnId(15); String reqId = billRequest.getReqId(); String billId = billRequest.getBillId(); @@ -411,12 +408,12 @@ public class AgentServiceImpl implements AgentService { LOGGER.info("Initiating {} API for billId={} and reqId={}", apiName, billId, reqId); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billRequest.getMid(), "GET", null); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billRequest.getMid(), BBPSConstant.HTTP_GET, null); try { helper.validateMerchant(billRequest.getMid()); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external BBPS API for ValidateByBillId, URL={}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); @@ -428,7 +425,7 @@ public class AgentServiceImpl implements AgentService { Map dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference>(){}); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), @@ -447,7 +444,7 @@ public class AgentServiceImpl implements AgentService { } catch (com.fasterxml.jackson.core.JsonProcessingException e) { LOGGER.error("Error parsing ValidateByBillId JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -457,14 +454,14 @@ public class AgentServiceImpl implements AgentService { @Override public ResponseModel fetchBillValidateByClientReqId(BillValidateByClientIdRequest billValidateByClientIdRequest) { - String apiName = "FetchBillValidateByClientIdRequest"; + String apiName = BBPSConstant.API_FETCH_BILL_VALIDATE_BY_CLIENT_ID; String txnId = helper.generateTxnId(15); String reqId = billValidateByClientIdRequest.getReqId(); String clientReqId = billValidateByClientIdRequest.getClientReqId(); Optional billInitiate = billIntiateRepository.findByReqId(clientReqId); if (billInitiate.isEmpty()) { - throw new CustomException("No Bill Found for given Client Req Id"); + throw new CustomException(BBPSConstant.NO_BILL_FOUND); } String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_BY_CLIENT_REQ_ID + billInitiate.get().getTxnId(); @@ -472,9 +469,9 @@ public class AgentServiceImpl implements AgentService { helper.validateMerchant(billValidateByClientIdRequest.getMid()); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, - billValidateByClientIdRequest.getMid(), "GET", null); + billValidateByClientIdRequest.getMid(), BBPSConstant.HTTP_GET, null); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); try { LOGGER.info("Calling BBPS API FetchBillValidateByClientReqId, URL={}", fullUrl); @@ -484,11 +481,11 @@ public class AgentServiceImpl implements AgentService { helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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"))); @@ -504,7 +501,7 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -512,14 +509,14 @@ public class AgentServiceImpl implements AgentService { @Override public ResponseModel fetchBillByClientReqId(BillFetchByClientIdRequest billFetchByClientIdRequest) { - String apiName = "FetchBillByClientIdRequest"; + String apiName = BBPSConstant.API_FETCH_BILL_BY_CLIENT_ID; String txnId = helper.generateTxnId(15); String reqId = billFetchByClientIdRequest.getReqId(); String clientReqId = billFetchByClientIdRequest.getClientReqId(); Optional billInitiate = billIntiateRepository.findByReqId(clientReqId); if (billInitiate.isEmpty()) { - throw new CustomException("No Bill Found for given Client Req Id"); + throw new CustomException(BBPSConstant.NO_BILL_FOUND); } String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_BY_CLIENT_REQ_ID + billInitiate.get().getTxnId(); @@ -527,9 +524,9 @@ public class AgentServiceImpl implements AgentService { helper.validateMerchant(billFetchByClientIdRequest.getMid()); InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, billFetchByClientIdRequest.getMid(), - "GET", null); + BBPSConstant.HTTP_GET, null); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); try { LOGGER.info("Calling BBPS API FetchBillByClientReqId, URL={}", fullUrl); @@ -539,11 +536,11 @@ public class AgentServiceImpl implements AgentService { helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, - new TypeReference>() { - }); + new TypeReference>() { + }); if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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"))); @@ -558,7 +555,7 @@ public class AgentServiceImpl implements AgentService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -566,26 +563,28 @@ public class AgentServiceImpl implements AgentService { @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(BBPSConstant.SUCCESS_CODE_STR)) { } else { - LOGGER.info("Bill Fetch Callback Failed with Status: {}", billDataResponse.getGenericResponse().getStatus()); + LOGGER.info("Bill Fetch Callback Failed with Status: {}", billDataResponse.getGenericResponse().getStatus()); } - return new ResponseModel("CallBack Recieved Successfully", - "200", - 200, - ""); + return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS, + BBPSConstant.SUCCESS_CODE_STR, + 200, + "" + ); } @Override public ResponseModel processBillValidateCallback(FetchBillValidateResponse billValidateResponse) { LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", billValidateResponse); - if(billValidateResponse.getGenericResponse().getStatusCode().equals("200")) { } + if(billValidateResponse.getGenericResponse().getStatusCode().equals(BBPSConstant.SUCCESS_CODE_STR)) { } else { - LOGGER.info("Bill Fetch Callback Failed with Status: {}", billValidateResponse.getGenericResponse().getStatus()); + LOGGER.info("Bill Fetch Callback Failed with Status: {}", billValidateResponse.getGenericResponse().getStatus()); } - return new ResponseModel("CallBack Recieved Successfully", - "200", - 200, - ""); + return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS, + BBPSConstant.SUCCESS_CODE_STR, + 200, + "" + ); } } \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java index 1333591..9fa3124 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java @@ -8,7 +8,6 @@ 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; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; @@ -20,13 +19,11 @@ import com.billpaymentservice.bbps.dto.request.ComplaintRequestDTO; import com.billpaymentservice.bbps.dto.request.GetTicketLatestStausRequest; import com.billpaymentservice.bbps.dto.request.TxnStatusRequest; import com.billpaymentservice.bbps.dto.request.ViewAllComplaintsTicketsRequest; -import com.billpaymentservice.bbps.dto.request.ViewAllComplaintsRequest; import com.billpaymentservice.bbps.dto.response.ComplaintHistoryStatusResponse; import com.billpaymentservice.bbps.dto.response.ComplaintResponse; import com.billpaymentservice.bbps.dto.response.TicketCheckStatusResponse; import com.billpaymentservice.bbps.dto.response.TxnStatusResponse; import com.billpaymentservice.bbps.dto.response.ViewAllComplaintsTicketsResponse; -import com.billpaymentservice.bbps.dto.response.ViewAllComplaintsResponse; import com.billpaymentservice.bbps.dto.response.ViewComplainByIdResponse; import com.billpaymentservice.bbps.entites.BharatConnectMaster; import com.billpaymentservice.bbps.entites.ComplaintStatusOptionsMaster; @@ -90,7 +87,7 @@ public class ComplainServiceImpl implements ComplainService { LOGGER.info("Initiating add Complain for request ID: {} and MID {}", complainRequestDTO.getReqId(), complainRequestDTO.getMid()); - String apiName = "ADD_COMPLAIN"; + String apiName = BBPSConstant.API_ADD_COMPLAIN; String txnId = helper.generateTxnId(15); String requestId = complainRequestDTO.getReqId(); String fullUrl = complainDataUrl + BBPSConstant.ADD_COMPLAIN_ENDPOINT; @@ -101,13 +98,13 @@ public class ComplainServiceImpl implements ComplainService { String requestJson = helper.convertObjectToJson(complainRequestDTO); // Fetch tenant & agent from DB - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, complainRequestDTO.getMid(), - "POST", requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, "POST", null); + BBPSConstant.HTTP_POST, requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl, BBPSConstant.HTTP_POST, null); try { // Inject tenantId + agentId into request JSON @@ -121,13 +118,13 @@ public class ComplainServiceImpl implements ComplainService { // IMPORTANT: Send finalJson, not requestJson Map responseMap = httpService.postRequest(fullUrl, finalJson, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Fetched response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); // Handle HttpService error wrapper - if (responseData.startsWith("HttpService Error")) { + if (responseData.startsWith(BBPSConstant.HTTP_SERVICE_ERROR_PREFIX)) { int start = responseData.indexOf("{"); int end = responseData.lastIndexOf("}"); if (start != -1 && end != -1) { @@ -141,12 +138,13 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - int statusCode = Integer.parseInt(String.valueOf(dataMap.get("statusCode"))); + int statusCode = Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))); // Throw exception for non-200 - if (statusCode != 200) { - throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), - statusCode, String.valueOf(dataMap.get("remarks"))); + if (statusCode != BBPSConstant.HTTP_OK_INT) { + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), statusCode, + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } // Convert to response wrapper @@ -160,7 +158,7 @@ public class ComplainServiceImpl implements ComplainService { } catch (JsonProcessingException e) { LOGGER.error("JSON Parsing Error: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -170,7 +168,7 @@ public class ComplainServiceImpl implements ComplainService { LOGGER.info("Fetching Complaint Status for TicketId={} ReqId={}", request.getTicketId(), request.getReqId()); - String apiName = "COMPLAINT_STATUS"; + String apiName = BBPSConstant.API_COMPLAINT_STATUS; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String complaintId = request.getTicketId(); @@ -178,17 +176,17 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); // Convert request to JSON String requestJson = helper.convertObjectToJson(request); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "POST", - requestJson); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), BBPSConstant.HTTP_POST, + requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "POST", complaintId); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_POST, complaintId); try { @@ -201,12 +199,13 @@ public class ComplainServiceImpl implements ComplainService { // LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.postRequest(fullUrl, finalJson, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Complaint Fetch Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); - if (responseData.startsWith("HttpService Error")) { + // Handle HttpService error wrapper + if (responseData.startsWith(BBPSConstant.HTTP_SERVICE_ERROR_PREFIX)) { int start = responseData.indexOf("{"); int end = responseData.lastIndexOf("}"); if (start != -1 && end != -1) { @@ -220,11 +219,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - int statusCode = Integer.parseInt(String.valueOf(dataMap.get("statusCode"))); + int statusCode = Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))); - if (statusCode != 200) { - throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), - statusCode, String.valueOf(dataMap.get("remarks"))); + if (statusCode != BBPSConstant.HTTP_OK_INT) { + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), statusCode, + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } TicketCheckStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TicketCheckStatusResponse.class); @@ -236,7 +236,7 @@ public class ComplainServiceImpl implements ComplainService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing JSON in complaint status API: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -245,7 +245,7 @@ public class ComplainServiceImpl implements ComplainService { public ResponseModel viewComplaintHistory(ComplainStatusRequest request) { LOGGER.info("Fetching View Complaint History Complaint by Complaint Id={}", request.getTicketId(), request.getReqId()); - String apiName = "View_Complaint_History"; + String apiName = BBPSConstant.API_VIEW_COMPLAINT_HISTORY; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String ticketId = request.getTicketId(); @@ -253,20 +253,20 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); String requestJson = helper.convertObjectToJson(request); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET", - requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", ticketId); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), BBPSConstant.HTTP_GET, + requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, ticketId); LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl); try { LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Complaint History Complaint FetchById Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -275,11 +275,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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("")); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), String.valueOf("")); } ComplaintHistoryStatusResponse responseWrapper = objectMapper.convertValue(dataMap, @@ -297,7 +298,7 @@ public class ComplainServiceImpl implements ComplainService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -306,7 +307,7 @@ public class ComplainServiceImpl implements ComplainService { public ResponseModel viewComplaintById(ComplainStatusRequest request) { LOGGER.info("Fetching View Complaint Complaint by Complaint Id={}", request.getTicketId(), request.getReqId()); - String apiName = "View_Complaint_By_ID"; + String apiName = BBPSConstant.API_VIEW_COMPLAINT_BY_ID; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String ticketId = request.getTicketId(); @@ -314,20 +315,20 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); String requestJson = helper.convertObjectToJson(request); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET", - requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", ticketId); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), BBPSConstant.HTTP_GET, + requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, ticketId); LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl); try { LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Complaint History Complaint FetchById Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -336,11 +337,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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("")); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), String.valueOf("")); } ViewComplainByIdResponse responseWrapper = objectMapper.convertValue(dataMap, @@ -358,7 +360,7 @@ public class ComplainServiceImpl implements ComplainService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -368,17 +370,17 @@ public class ComplainServiceImpl implements ComplainService { try { LOGGER.info("Fetch All Master Options - MID: {}", request.getMid()); - String apiName = "View All Options Fetch By Id"; + String apiName = BBPSConstant.API_GET_ALL_MASTER_OPTIONS; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); - String fullUrl = "Data Base Options"; + String fullUrl = BBPSConstant.DB_OPTIONS; String requestJson = helper.convertObjectToJson(request); // Validate merchant helper.validateMerchant(request.getMid()); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET", - requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", null); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), BBPSConstant.HTTP_GET, + requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl); // Fetch data from DB @@ -389,27 +391,29 @@ public class ComplainServiceImpl implements ComplainService { // Check empty or null if (allActiveStatuses == null || allActiveStatuses.isEmpty()) { - helper.updateInboundLogFailure(inboundLog, allActiveStatuses.toString(), "Null Data From DB"); - return new ResponseModel("No Master Fields Found", "failed", 404, null, 0); + helper.updateInboundLogFailure(inboundLog, String.valueOf(allActiveStatuses), BBPSConstant.NULL_DATA_FROM_DB); + return new ResponseModel(BBPSConstant.NO_MASTER_FIELDS_FOUND, BBPSConstant.FAILED_STATUS, + BBPSConstant.HTTP_NOT_FOUND, null, 0); } - helper.updateInboundLogSuccess(inboundLog, allActiveStatuses.toString(), "200"); + helper.updateInboundLogSuccess(inboundLog, String.valueOf(allActiveStatuses), String.valueOf(BBPSConstant.HTTP_OK_INT)); // SUCCESS RESPONSE - return new ResponseModel("All Master Fields Fetch", "SUCCESS", 200, allActiveStatuses, + return new ResponseModel(BBPSConstant.ALL_MASTER_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE, BBPSConstant.HTTP_OK_INT, allActiveStatuses, allActiveStatuses.size()); } catch (Exception e) { LOGGER.error("Error while fetching master options", e); - return new ResponseModel("Something went wrong", "failed", 500, null, 0); + return new ResponseModel(BBPSConstant.SOMETHING_WENT_WRONG, BBPSConstant.FAILED_STATUS, + BBPSConstant.HTTP_INTERNAL_SERVER_ERROR, null, 0); } } public ResponseModel checkTxnStatus(TxnStatusRequest request) { LOGGER.info("Check Txn Status Request by Id={} and ReqId ={}", request.getId(), request.getReqId()); - String apiName = "CheckTxnStatus"; + String apiName = BBPSConstant.API_CHECK_TXN_STATUS; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String ID = request.getId(); @@ -417,20 +421,20 @@ public class ComplainServiceImpl implements ComplainService { helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); String requestJson = helper.convertObjectToJson(request); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "GET", - requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", ID); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), BBPSConstant.HTTP_GET, + requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, ID); LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl); try { LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("checkTxnStatus: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -439,11 +443,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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("")); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), String.valueOf("")); } TxnStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TxnStatusResponse.class); @@ -457,7 +462,7 @@ public class ComplainServiceImpl implements ComplainService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } @@ -468,30 +473,30 @@ public class ComplainServiceImpl implements ComplainService { LOGGER.info("Fetching All Complaint for status Type={} and reqId={} ", request.getStatusType(), request.getReqId()); - String apiName = "View_All_Complaint_By_Status_Type"; + String apiName = BBPSConstant.API_VIEW_ALL_COMPLAINTS_BY_STATUS; String txnId = helper.generateTxnId(15); String reqId = request.getReqId(); String fullUrl = complainDataUrl + BBPSConstant.VIEW_ALL_COMPLAINTS_BASE + "?pageNo=" + request.getPageNo() - + "&pageSize=" + request.getPageSize() + "&statusType=" + request.getStatusType() + "&ticketType=" - + request.getTicketType(); + + "&pageSize=" + request.getPageSize() + "&statusType=" + request.getStatusType() + "&ticketType=" + + request.getTicketType(); helper.validateMerchant(request.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); String requestJson = helper.convertObjectToJson(request); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), "POST", - requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, "GET", - request.getStatusType()); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(), BBPSConstant.HTTP_POST, + requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, + request.getStatusType()); LOGGER.debug("Outbound log created successfully for Complaint : {}", fullUrl); try { LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -500,11 +505,12 @@ public class ComplainServiceImpl implements ComplainService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.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("")); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), String.valueOf("")); } ViewAllComplaintsTicketsResponse responseWrapper = objectMapper.convertValue(dataMap, @@ -521,7 +527,7 @@ public class ComplainServiceImpl implements ComplainService { Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { LOGGER.error("Error parsing Complaint Id JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java index dc84b78..5caf1ca 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java @@ -10,10 +10,7 @@ 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; import org.springframework.stereotype.Service; - -import com.billpaymentservice.bbps.dto.ContactMaster; import com.billpaymentservice.bbps.dto.CustomParamDTO; import com.billpaymentservice.bbps.dto.CustomerParamGroupsDTO; import com.billpaymentservice.bbps.dto.GeneralResp; @@ -108,16 +105,16 @@ public class MasterDataServiceImpl implements MasterDataService { public ResponseModel getMasterData(MasterRequest masterRequest) { LOGGER.info("Fetching Master Data for ReqId={} and MID={}", masterRequest.getReqId(), masterRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetMasterData"; + String apiName = BBPSConstant.API_GET_MASTER_DATA; String requestId = masterRequest.getReqId(); String requestJson = helper.convertObjectToJson(masterRequest); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); try { // Merchant Validation helper.validateMerchant(masterRequest.getMid()); // check Tenant Id is present DB - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); if (headersData == null) { LOGGER.warn("header data not found for the orgID"); throw new CustomException("Something went wrong", "FAILED", 500, ""); @@ -125,21 +122,21 @@ public class MasterDataServiceImpl implements MasterDataService { // get full url String fullUrl = masterRegisterUrl + BBPSConstant.MASTER_CATEGORY_URL + headersData.getTenantId(); LOGGER.info("Calling external API: {}", fullUrl); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); HttpHeaders headers = helper.buildHeaders(headersData); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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")) // remarks + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // remarks ); } @@ -155,8 +152,9 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); + } } @@ -168,31 +166,31 @@ public class MasterDataServiceImpl implements MasterDataService { helper.validateMerchant(billerDetailRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetBillerByBillerId"; + String apiName = BBPSConstant.API_GET_BILLER_BY_ID; String requestId = billerDetailRequest.getReqId(); String billerId = billerDetailRequest.getBillerId(); String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL + billerId; String requestJson = helper.convertObjectToJson(billerDetailRequest); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, billerDetailRequest.getMid(), - "POST", requestJson); + BBPSConstant.HTTP_POST, requestJson); System.out.println(billerDataRespository.findByBillerId(billerId)); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("fetched data from api is :{}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); try { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, 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"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } BillerDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillerDataResponse.class); GeneralResp generalResp = responseWrapper.getGeneralResp(); @@ -208,7 +206,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -220,21 +218,21 @@ public class MasterDataServiceImpl implements MasterDataService { customerParamRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetCustomerParamByBillerId"; + String apiName = BBPSConstant.API_GET_CUSTOMER_PARAM_BY_BILLER_ID; String requestId = customerParamRequest.getReqId(); String requestJson = helper.convertObjectToJson(customerParamRequest); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, customerParamRequest.getMid(), - "POST", requestJson); + BBPSConstant.HTTP_POST, requestJson); try { helper.validateMerchant(customerParamRequest.getMid()); String billerId = customerParamRequest.getBillerId(); String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMPARAM_URL + billerId; - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("data is :{}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -242,12 +240,12 @@ public class MasterDataServiceImpl implements MasterDataService { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } CustomParamResp responseWrapper = objectMapper.convertValue(dataMap, CustomParamResp.class); @@ -270,7 +268,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -280,23 +278,23 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Contact Master Request Data " + contactMasterRequest); String txnID = helper.generateTxnId(15); - String apiName = "FetchMasterDataCategoryWise"; + String apiName = BBPSConstant.API_FETCH_MASTER_DATA_CATEGORY_WISE; String requestId = contactMasterRequest.getReqId(); String requestJson = helper.convertObjectToJson(contactMasterRequest); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, contactMasterRequest.getMid(), - "POST", requestJson); + BBPSConstant.HTTP_POST, requestJson); try { helper.validateMerchant(contactMasterRequest.getMid()); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); String fullUrl = masterRegisterUrl + String.format(BBPSConstant.CONTACT_MASTER_URL, headersData.getTenantId(), contactMasterRequest.getCategory()); LOGGER.info("Contact Master Full URL-:" + fullUrl); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); HttpHeaders headers = helper.buildHeaders(headersData); Map responseMap = httpService.getRequest(fullUrl, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Response Data: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -305,12 +303,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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")) // remarks + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // remarks ); } @@ -329,7 +327,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -339,10 +337,10 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Master Data CategoryResponseList-wise " + masterRequest); String txnID = helper.generateTxnId(15); - String apiName = "FetchMasterDataCategoryWise"; + String apiName = BBPSConstant.API_FETCH_MASTER_DATA_CATEGORY_WISE; String requestId = masterRequest.getReqId(); String requestJson = helper.convertObjectToJson(masterRequest); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); try { helper.validateMerchant(masterRequest.getMid()); @@ -351,10 +349,10 @@ public class MasterDataServiceImpl implements MasterDataService { masterRequest.getPageNo(), masterRequest.getPageSize()); LOGGER.info("Calling external API: {}", fullUrl); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); // LOGGER.info("Response Data: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -363,12 +361,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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")) // remarks + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // remarks ); } @@ -386,7 +384,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -397,17 +395,17 @@ public class MasterDataServiceImpl implements MasterDataService { dispositionDetailRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetDispositionDetails"; + String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS; String requestId = dispositionDetailRequest.getReqId(); helper.validateMerchant(dispositionDetailRequest.getMid()); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, - dispositionDetailRequest.getMid(), "GET", "N/A"); + dispositionDetailRequest.getMid(), BBPSConstant.HTTP_GET, "N/A"); String fullUrl = masterRegisterUrl + BBPSConstant.DISPOSTION_URL; - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); try { @@ -415,12 +413,12 @@ public class MasterDataServiceImpl implements MasterDataService { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } DispositionResponse responseWrapper = objectMapper.convertValue(dataMap, DispositionResponse.class); @@ -447,7 +445,7 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } @@ -458,31 +456,31 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Customer Param Group for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchCustomerParamGroup"; + String apiName = BBPSConstant.API_FETCH_CUSTOMER_PARAM_GROUP; String requestId = requestModel.getReqId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel)); try { helper.validateMerchant(requestModel.getMid()); String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMER_PARAM_GROUP + requestModel.getBillerId(); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map apiResponse = httpService.getRequest(fullUrl); - String responseData = apiResponse.get("data").toString(); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString(); helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } CustomerParamGroupsResponse responseWrapper = objectMapper.convertValue(dataMap, @@ -501,7 +499,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } @@ -513,20 +511,20 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Master Data Amount List for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchAllMasterAmountOption"; + String apiName = BBPSConstant.API_FETCH_ALL_MASTER_AMOUNT_OPTION; String requestId = requestModel.getReqId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel)); try { helper.validateMerchant(requestModel.getMid()); String fullUrl = masterRegisterUrl + BBPSConstant.AMOUNT_OPTIONS + requestModel.getBillerId(); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map apiResponse = httpService.getRequest(fullUrl); LOGGER.info("Response" + apiResponse); - String responseData = apiResponse.get("data").toString(); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString(); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -534,12 +532,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } AmountOptionsResponse responseWrapper = objectMapper.convertValue(dataMap, AmountOptionsResponse.class); @@ -558,7 +556,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } @@ -568,20 +566,20 @@ public class MasterDataServiceImpl implements MasterDataService { public ResponseModel fetchPlanCategorie(BillerDetailRequest requestModel) { LOGGER.info("Fetching Plan Categories for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchPlanCategorie"; + String apiName = BBPSConstant.API_FETCH_PLAN_CATEGORIES; String requestId = requestModel.getReqId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel)); try { helper.validateMerchant(requestModel.getMid()); String fullUrl = masterRegisterUrl + BBPSConstant.PLAN_CATEGORIES + requestModel.getBillerId(); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map apiResponse = httpService.getRequest(fullUrl); LOGGER.info("Response" + apiResponse); - String responseData = apiResponse.get("data").toString(); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString(); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -589,12 +587,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } PlaneCategoriesResponse responseWrapper = objectMapper.convertValue(dataMap, PlaneCategoriesResponse.class); @@ -611,7 +609,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } @@ -622,9 +620,9 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Initiating Channel for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchInitiatingChannel"; + String apiName = BBPSConstant.API_FETCH_INITIATING_CHANNEL; String requestId = requestModel.getReqId(); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel)); try { @@ -632,11 +630,11 @@ public class MasterDataServiceImpl implements MasterDataService { String fullUrl = masterRegisterUrl + BBPSConstant.INITIATING_CHANNEL; - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling Master API: {}", fullUrl); Map apiResponse = httpService.getRequest(fullUrl); LOGGER.info("Response" + apiResponse); - String responseData = apiResponse.get("data").toString(); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString(); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -644,12 +642,12 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } ChannelsListResponse responseWrapper = objectMapper.convertValue(dataMap, ChannelsListResponse.class); @@ -664,7 +662,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } @@ -675,7 +673,7 @@ public class MasterDataServiceImpl implements MasterDataService { LOGGER.info("Fetching Plan By Categories for ReqId={} and MID={}", requestModel.getReqId(), requestModel.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "FetchPlanByCategories"; + String apiName = BBPSConstant.API_FETCH_PLAN_BY_CATEGORIES; String requestId = requestModel.getReqId(); helper.validateMerchant(requestModel.getMid()); @@ -691,12 +689,12 @@ public class MasterDataServiceImpl implements MasterDataService { // Convert request to JSON and create inbound & outbound logs String requestJson = helper.convertObjectToJson(requestModel); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(), BBPSConstant.HTTP_POST, requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, null); try { Map apiResponse = httpService.getRequest(url); - String responseData = apiResponse.get("data"); + String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Response Data: {}", responseData); // Update outbound log with response @@ -706,12 +704,13 @@ public class MasterDataServiceImpl implements MasterDataService { new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { // Failure response - helper.updateInboundLogFailure(inboundLog, responseData, 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"))); + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } // Success response @@ -727,7 +726,7 @@ public class MasterDataServiceImpl implements MasterDataService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -738,17 +737,17 @@ public class MasterDataServiceImpl implements MasterDataService { dispositionDetailRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "GetTicketDispositionDetails"; + String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS; String requestId = dispositionDetailRequest.getReqId(); helper.validateMerchant(dispositionDetailRequest.getMid()); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, - dispositionDetailRequest.getMid(), "GET", "N/A"); + dispositionDetailRequest.getMid(), BBPSConstant.HTTP_GET, "N/A"); String fullUrl = masterRegisterUrl + BBPSConstant.TICKET_DISPOSTION_URL; - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external API: {}", fullUrl); Map responseMap = httpService.getRequest(fullUrl); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); try { @@ -756,12 +755,12 @@ public class MasterDataServiceImpl implements MasterDataService { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); - 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"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status + Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode (int) + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY))); } TicketDispositionResponse responseWrapper = objectMapper.convertValue(dataMap, @@ -779,9 +778,9 @@ public class MasterDataServiceImpl implements MasterDataService { return responseModel; } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage()); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } -} +} \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java index d54bb22..4bfe2a1 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java @@ -10,7 +10,6 @@ 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; import org.springframework.stereotype.Service; import com.billpaymentservice.bbps.dto.GeneralResp; import com.billpaymentservice.bbps.dto.ResponseModel; diff --git a/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java b/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java index 71924f1..be6c549 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java +++ b/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java @@ -59,4 +59,80 @@ public class BBPSConstant { public static final String ADD_COMPLAIN_ENDPOINT = "/couapp/ticket/raise"; public static final String VIEW_ALL_COMPLAINTS_BASE = "/couapp/tickets"; -} + // New centralized string/constants used across services + public static final String API_INITIATE_BILL_FETCH = "InitiateBillFetch"; + public static final String API_FETCH_BILL_BY_ID = "FetchBillById"; + public static final String API_INITIATE_BILL_VALIDATE = "InitiateBillValidate"; + public static final String API_FETCH_BILL_VALIDATE_BY_CLIENT_ID = "FetchBillValidateByClientIdRequest"; + public static final String API_FETCH_BILL_BY_CLIENT_ID = "FetchBillByClientIdRequest"; + + public static final String HTTP_POST = "POST"; + public static final String HTTP_GET = "GET"; + + public static final String INVALID_RESPONSE = "INVALID_RESPONSE"; + public static final String JSON_ERROR = "JSON_ERROR"; + + public static final String CALLBACK_RECEIVED_SUCCESS = "CallBack Recieved Successfully"; + public static final String NO_BILL_FOUND = "No Bill Found for given Client Req Id"; + + public static final String SUCCESS_CODE_STR = "200"; + + // Added constants referenced by ComplainServiceImpl + public static final String ORG_ID = "ORG001"; + + public static final String API_ADD_COMPLAIN = "ADD_COMPLAIN"; + public static final String API_COMPLAINT_STATUS = "COMPLAINT_STATUS"; + public static final String API_VIEW_COMPLAINT_HISTORY = "View_Complaint_History"; + public static final String API_VIEW_COMPLAINT_BY_ID = "View_Complaint_By_ID"; + public static final String API_GET_ALL_MASTER_OPTIONS = "View All Options Fetch By Id"; + public static final String API_CHECK_TXN_STATUS = "CheckTxnStatus"; + public static final String API_VIEW_ALL_COMPLAINTS_BY_STATUS = "View_All_Complaint_By_Status_Type"; + + // API names used by MasterDataServiceImpl + public static final String API_GET_MASTER_DATA = "GetMasterData"; + public static final String API_GET_BILLER_BY_ID = "GetBillerByBillerId"; + public static final String API_GET_CUSTOMER_PARAM_BY_BILLER_ID = "GetCustomerParamByBillerId"; + public static final String API_FETCH_MASTER_DATA_CATEGORY_WISE = "FetchMasterDataCategoryWise"; + public static final String API_FETCH_CUSTOMER_PARAM_GROUP = "FetchCustomerParamGroup"; + public static final String API_FETCH_ALL_MASTER_AMOUNT_OPTION = "FetchAllMasterAmountOption"; + public static final String API_FETCH_PLAN_CATEGORIES = "FetchPlanCategorie"; + public static final String API_FETCH_INITIATING_CHANNEL = "FetchInitiatingChannel"; + public static final String API_FETCH_PLAN_BY_CATEGORIES = "FetchPlanByCategories"; + public static final String API_GET_TICKET_DISPOSITIONS = "GetTicketDispositionDetails"; + + // Payment related API names + public static final String API_INITIATE_PAYMENT = "InitiatePayment"; + public static final String API_CHECK_TRANSACTION_STATUS = "CheckTransactionStatus"; + public static final String API_CHECK_TRANSACTION_PUBLIC = "checkTrasactionStatus"; + public static final String API_CHECK_BY_CLIENT_REQ_ID = "checkTrasactionStatusbyClientReqId"; + + // Response and helper keys (already existing ones kept) + public static final String RESPONSE_GENERIC_KEY = "genericResponse"; + + // Common messages used in PaymentServiceImpl + public static final String EMPTY_RESPONSE_FROM_BBPS = "Empty response from BBPS"; + public static final String INVALID_STRUCTURE = "INVALID_STRUCTURE"; + public static final String FAILED_STR = "FAILED"; + + public static final int HTTP_OK_INT = 200; + public static final int HTTP_NOT_FOUND = 404; + public static final int HTTP_INTERNAL_SERVER_ERROR = 500; + + // Response and helper keys + public static final String HTTP_SERVICE_ERROR_PREFIX = "HttpService Error"; + public static final String RESPONSE_DATA_KEY = "data"; + public static final String RESPONSE_MESSAGE_KEY = "message"; + public static final String RESPONSE_STATUS_KEY = "status"; + public static final String RESPONSE_STATUSCODE_KEY = "statusCode"; + public static final String RESPONSE_REMARKS_KEY = "remarks"; + public static final String RESPONSE_GENERAL_RESP = "generalResp"; + public static final String SUCCESS_RESPONSE = "SUCCESS"; + + // Newly added constants used by ComplainServiceImpl + public static final String DB_OPTIONS = "/db/options"; // used as a logical URL/identifier for master options + public static final String NULL_DATA_FROM_DB = "NULL_DATA_FROM_DB"; + public static final String NO_MASTER_FIELDS_FOUND = "No master fields found"; + public static final String ALL_MASTER_FIELDS_FETCH = "All master fields fetched successfully"; + public static final String SOMETHING_WENT_WRONG = "Something went wrong"; + +} \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/util/EntityRelationshipUtil.java b/src/main/java/com/billpaymentservice/bbps/util/EntityRelationshipUtil.java index caec51d..3d7c59f 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/EntityRelationshipUtil.java +++ b/src/main/java/com/billpaymentservice/bbps/util/EntityRelationshipUtil.java @@ -1,7 +1,4 @@ package com.billpaymentservice.bbps.util; - -import com.billpaymentservice.bbps.dto.request.FetchBillRequest; -import com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest; import com.billpaymentservice.bbps.entites.BillerDetails; import com.billpaymentservice.bbps.entites.BillerResponseParams; import com.billpaymentservice.bbps.entites.InterchangeFee; diff --git a/src/main/java/com/billpaymentservice/bbps/util/Helper.java b/src/main/java/com/billpaymentservice/bbps/util/Helper.java index edda1a7..087ca8f 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/Helper.java +++ b/src/main/java/com/billpaymentservice/bbps/util/Helper.java @@ -2,44 +2,14 @@ package com.billpaymentservice.bbps.util; import java.security.SecureRandom; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.modelmapper.ModelMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; - -import com.billpaymentservice.bbps.dto.AdditionalInfoBillDTO; -import com.billpaymentservice.bbps.dto.CustomerParamDAO; -import com.billpaymentservice.bbps.dto.ResponseModel; -import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest; -import com.billpaymentservice.bbps.dto.request.BillPaymentRequest; -import com.billpaymentservice.bbps.dto.request.FetchBillRequest; -import com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest; -import com.billpaymentservice.bbps.dto.response.BillDataResponse; -import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; -import com.billpaymentservice.bbps.dto.sentRequest.BillPaymentForwardRequest; -import com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest; -import com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest; -import com.billpaymentservice.bbps.entites.AdditionalInfoBill; -import com.billpaymentservice.bbps.entites.AdditionalInfoBillValidate; import com.billpaymentservice.bbps.entites.BBPSMastersData; -import com.billpaymentservice.bbps.entites.BillMaster; -import com.billpaymentservice.bbps.entites.BillValidation; -import com.billpaymentservice.bbps.entites.BillerDetails; -import com.billpaymentservice.bbps.entites.BillerResponse; -import com.billpaymentservice.bbps.entites.CustomerParamBill; -import com.billpaymentservice.bbps.entites.CustomerParamBillValidation; import com.billpaymentservice.bbps.entites.InboundTraceLog; import com.billpaymentservice.bbps.entites.OutboundTraceLog; -import com.billpaymentservice.bbps.entites.PaymentChannel; -import com.billpaymentservice.bbps.entites.PaymentMode; import com.billpaymentservice.bbps.entites.BharatConnectMaster; import com.billpaymentservice.bbps.exception.CustomException; import com.billpaymentservice.bbps.repository.BBPSMasterDataRepo; @@ -81,34 +51,6 @@ public class Helper { * * */ - public void startPolling(T requestObject, // Request object (any type) - Function apiCallFunction, // Function to call API - int intervalSeconds, // gap between two polls - int maxDurationSeconds // total polling time - ) { - new Thread(() -> { - try { - int maxAttempts = maxDurationSeconds / intervalSeconds; - - for (int i = 0; i < maxAttempts; i++) { - LOGGER.info("⏳ Polling attempt {}...", i + 1); - - ResponseModel response = apiCallFunction.apply(requestObject); - LOGGER.info("📥 Poll response: {}", response); - - if ("SUCCESS".equalsIgnoreCase(response.getStatus())) { - LOGGER.info("✅ Polling successful, stopping early."); - break; - } - - Thread.sleep(intervalSeconds * 1000L); - } - } catch (Exception e) { - LOGGER.error("❌ Error in polling thread: {}", e.getMessage(), e); - } - }).start(); - } - public void validateMerchant(String mid) { if (mid == null || mid == "") { LOGGER.warn("MerchantRequestModel or MID is null"); @@ -206,7 +148,6 @@ public class Helper { outboundLog.setResponsePayload(responsePayload); outboundLog.setResponseReceiveTime(LocalDateTime.now()); outboundTraceLogRepository.save(outboundLog); - } /* ---------- End helpers ---------- */ From d0812656ff2aee80b1eb0c0ab8e29a01d7d66553 Mon Sep 17 00:00:00 2001 From: Lincpay Tech Date: Mon, 24 Nov 2025 18:35:43 +0530 Subject: [PATCH 5/5] added some more constants bpps constant --- .../bbps/serviceImpl/AgentServiceImpl.java | 56 ++++++------- .../bbps/serviceImpl/PaymentServiceImpl.java | 82 +++++++++---------- .../bbps/util/BBPSConstant.java | 5 ++ 3 files changed, 73 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java index 5196372..2665c3d 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java @@ -97,8 +97,8 @@ public class AgentServiceImpl implements AgentService { try { LOGGER.info("Calling external API: {}", fullUrl); - Map responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); - String responseData = responseMap.get("data"); + Map responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID))); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); LOGGER.debug("Response received from BBPS: {}", responseData); @@ -106,7 +106,7 @@ public class AgentServiceImpl implements AgentService { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("genericResponse")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response received for txnId: {}", txnId); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), @@ -138,7 +138,7 @@ public class AgentServiceImpl implements AgentService { billFetchByBillIdRequest.setReqId(requestId); LOGGER.info("Waiting for 2 seconds before fetching bill by ID..."); try { - Thread.sleep(5000); + Thread.sleep((long) BBPSConstant.BILL_FETCH_DELAY_MS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOGGER.warn("Thread interrupted during delay: {}", e.getMessage()); @@ -167,8 +167,8 @@ public class AgentServiceImpl implements AgentService { try { LOGGER.info("Calling external API: {}", fullUrl); - Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); - String responseData = responseMap.get("data"); + Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID))); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Bill FetchById Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -177,7 +177,7 @@ public class AgentServiceImpl implements AgentService { new TypeReference>() { }); - if (!dataMap.containsKey("genericResponse")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response structure for txnId: {}", txnId); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), @@ -223,8 +223,8 @@ public class AgentServiceImpl implements AgentService { OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl); - Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); - String responseData = responseMap.get("data"); + Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID))); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -233,7 +233,7 @@ public class AgentServiceImpl implements AgentService { new TypeReference>() { }); - if (!dataMap.containsKey("genericResponse")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData); throw new CustomException(String.valueOf(dataMap.get("message")), @@ -286,8 +286,8 @@ public class AgentServiceImpl implements AgentService { try { LOGGER.info("Calling external API: {}", fullUrl); - Map responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); - String responseData = responseMap.get("data"); + Map responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID))); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); LOGGER.debug("Response received from BBPS: {}", responseData); @@ -295,7 +295,7 @@ public class AgentServiceImpl implements AgentService { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() { }); - if (!dataMap.containsKey("genericResponse")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response received for txnId: {}", txnId); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), @@ -326,7 +326,7 @@ public class AgentServiceImpl implements AgentService { billFetchByBillIdRequest.setReqId(reqId); LOGGER.info("Waiting for 2 seconds before fetching bill by ID..."); try { - Thread.sleep(12000); + Thread.sleep((long) BBPSConstant.BILL_VALIDATE_DELAY_MS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOGGER.warn("Thread interrupted during delay: {}", e.getMessage()); @@ -357,8 +357,8 @@ public class AgentServiceImpl implements AgentService { try { LOGGER.info("Calling external API: {}", fullUrl); - Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); - String responseData = responseMap.get("data"); + Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID))); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Bill FetchById Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -367,7 +367,7 @@ public class AgentServiceImpl implements AgentService { new TypeReference>() { }); - if (!dataMap.containsKey("genericResponse")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response structure for txnId: {}", txnId); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), @@ -416,15 +416,15 @@ public class AgentServiceImpl implements AgentService { OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); LOGGER.info("Calling external BBPS API for ValidateByBillId, URL={}", fullUrl); - Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); - String responseData = responseMap.get("data"); + Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID))); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData); helper.updateOutboundLogResponse(outboundLog, responseData); Map dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference>(){}); - if (!dataMap.containsKey("genericResponse")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData); throw new CustomException(String.valueOf(dataMap.get("message")), @@ -475,8 +475,8 @@ public class AgentServiceImpl implements AgentService { try { LOGGER.info("Calling BBPS API FetchBillValidateByClientReqId, URL={}", fullUrl); - Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); - String responseData = responseMap.get("data"); + Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID))); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -484,7 +484,7 @@ public class AgentServiceImpl implements AgentService { new TypeReference>() { }); - if (!dataMap.containsKey("genericResponse")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), @@ -530,8 +530,8 @@ public class AgentServiceImpl implements AgentService { try { LOGGER.info("Calling BBPS API FetchBillByClientReqId, URL={}", fullUrl); - Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); - String responseData = responseMap.get("data"); + Map responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID))); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -539,7 +539,7 @@ public class AgentServiceImpl implements AgentService { new TypeReference>() { }); - if (!dataMap.containsKey("genericResponse")) { + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); throw new CustomException(String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("status")), Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), @@ -569,7 +569,7 @@ public class AgentServiceImpl implements AgentService { } return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS, BBPSConstant.SUCCESS_CODE_STR, - 200, + BBPSConstant.HTTP_OK_INT, "" ); } @@ -583,7 +583,7 @@ public class AgentServiceImpl implements AgentService { } return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS, BBPSConstant.SUCCESS_CODE_STR, - 200, + BBPSConstant.HTTP_OK_INT, "" ); } diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java index 4bfe2a1..009127b 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java @@ -92,42 +92,42 @@ public class PaymentServiceImpl implements PaymentService { @Override public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) { - String apiName = "InitiatePayment"; + String apiName = BBPSConstant.API_INITIATE_PAYMENT; String txnId = helper.generateTxnId(15); String requestId = billPaymentRequest.getReqId(); String url = paymentUrl + BBPSConstant.PAYMENT_URL; billPaymentRequest.setClientReqId(txnId); LOGGER.info("Initiating payment for reqId={} and txnId={}", requestId, txnId); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); BillPaymentForwardRequest forwardReq = mapperHelper.billPaymentForwardRequest(billPaymentRequest); String forwardjson = helper.convertObjectToJson(forwardReq); String requestJson = helper.convertObjectToJson(billPaymentRequest); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(), "POST", requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "POST", forwardjson); + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_POST, forwardjson); try { LOGGER.info("Calling BBPS payment URL: {}", url); Map responseMap = httpService.postRequest(url, forwardjson, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Payment API Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); if (responseData == null || responseData.isEmpty()) { - helper.updateInboundLogFailure(inboundLog, "Empty response from BBPS", "FAILED"); + helper.updateInboundLogFailure(inboundLog, BBPSConstant.EMPTY_RESPONSE_FROM_BBPS, BBPSConstant.FAILED_STR); LOGGER.warn("Empty response received from BBPS for txnId={}", txnId); - throw new CustomException("Empty response from BBPS server"); + throw new CustomException(BBPSConstant.EMPTY_RESPONSE_FROM_BBPS); } Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey("genericResponse")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_STRUCTURE"); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_STRUCTURE); LOGGER.warn("Invalid response structure received for txnId={}", txnId); - throw new CustomException("Invalid response structure from BBPS"); + throw new CustomException(BBPSConstant.INVALID_STRUCTURE); } BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class); @@ -151,7 +151,7 @@ public class PaymentServiceImpl implements PaymentService { transactionStatusRequest.setReqId(requestId); try { - Thread.sleep(9000); + Thread.sleep((long) BBPSConstant.PAYMENT_STATUS_DELAY_MS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage()); @@ -161,13 +161,13 @@ public class PaymentServiceImpl implements PaymentService { } catch (JsonProcessingException e) { LOGGER.error("JSON Parsing Error in initiatePayment: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest, InboundTraceLog inboundLog) { - String apiName = "CheckTransactionStatus"; + String apiName = BBPSConstant.API_CHECK_TRANSACTION_STATUS; String txnId = helper.generateTxnId(15); String requestId = transactionStatusRequest.getReqId(); @@ -175,21 +175,21 @@ public class PaymentServiceImpl implements PaymentService { LOGGER.info("Checking transaction status (internal) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "GET", null); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_GET, null); Map responseMap = httpService.getRequest(url, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Transaction status response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); try { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid transaction status response for txnId={}", transactionStatusRequest.getTxnId()); throw new CustomException( String.valueOf(dataMap.get("message")), @@ -229,7 +229,7 @@ public class PaymentServiceImpl implements PaymentService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing transaction status JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -238,28 +238,28 @@ public class PaymentServiceImpl implements PaymentService { public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) { helper.validateMerchant(transactionStatusRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "checkTrasactionStatus"; + String apiName = BBPSConstant.API_CHECK_TRANSACTION_PUBLIC; String requestId = transactionStatusRequest.getReqId(); String requestJson = helper.convertObjectToJson(transactionStatusRequest); String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); LOGGER.info("Checking transaction status (public) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, transactionStatusRequest.getMid(), "POST", requestJson); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, "GET", null); + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, null); Map responseMap = httpService.getRequest(url, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Transaction status response data: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); try { Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); LOGGER.warn("Invalid transaction status response for txnId={} from BBPS", transactionStatusRequest.getTxnId()); throw new CustomException( String.valueOf(dataMap.get("message")), @@ -287,7 +287,7 @@ public class PaymentServiceImpl implements PaymentService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing responseData JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } } @@ -298,7 +298,7 @@ public class PaymentServiceImpl implements PaymentService { helper.validateMerchant(transactionStatusRequest.getMid()); String txnID = helper.generateTxnId(15); - String apiName = "checkTrasactionStatusbyClientReqId"; + String apiName = BBPSConstant.API_CHECK_BY_CLIENT_REQ_ID; String requestId = transactionStatusRequest.getReqId(); String clientReqId = transactionStatusRequest.getClientReqId(); String requestJson = helper.convertObjectToJson(transactionStatusRequest); @@ -307,25 +307,25 @@ public class PaymentServiceImpl implements PaymentService { Optional paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId); if (paymentInitiate.isEmpty()) { - throw new CustomException("No Transaction Found for given Client Req Id"); + throw new CustomException(BBPSConstant.NO_BILL_FOUND); } String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_BY_CLIENT_REQ_ID_URL + paymentInitiate.get().getTxnId(); - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001"); + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); HttpHeaders headers = helper.buildHeaders(headersData); InboundTraceLog inboundLog = helper.createInboundLog( - requestId, txnID, apiName, transactionStatusRequest.getMid(), "POST", requestJson); + requestId, txnID, apiName, transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); OutboundTraceLog outboundLog = helper.createOutboundLog( - txnID, requestId, apiName, url, "GET", null); + txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, null); try { LOGGER.info("Calling BBPS Transaction Status API URL={}", url); Map responseMap = httpService.getRequest(url, headers); - String responseData = responseMap.get("data"); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); LOGGER.info("Transaction Status Response: {}", responseData); helper.updateOutboundLogResponse(outboundLog, responseData); @@ -333,8 +333,8 @@ public class PaymentServiceImpl implements PaymentService { Map dataMap = objectMapper.readValue( responseData, new TypeReference>() {}); - if (!dataMap.containsKey("generalResp")) { - helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); LOGGER.warn("Invalid transaction status response for clientReqId={} | Response={}", clientReqId, responseData); @@ -355,7 +355,6 @@ public class PaymentServiceImpl implements PaymentService { LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus()); helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - return new ResponseModel( generalResp.getMessage(), generalResp.getStatus(), @@ -365,8 +364,7 @@ public class PaymentServiceImpl implements PaymentService { } catch (JsonProcessingException e) { LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e); - - helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR"); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); throw new CustomException("Invalid JSON received from API"); } @@ -376,16 +374,16 @@ public class PaymentServiceImpl implements PaymentService { public ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse) { LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", transactionStatusResponse); - if (transactionStatusResponse.getGeneralResp().getStatusCode().equals("200")) { + if (transactionStatusResponse.getGeneralResp().getStatusCode().equals(BBPSConstant.SUCCESS_CODE_STR)) { } else { LOGGER.info("Bill Fetch Callback Failed with Status: {}", transactionStatusResponse.getGeneralResp().getStatus()); } - return new ResponseModel("CallBack Recieved Successfully", - "200", - 200, + return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS, + BBPSConstant.SUCCESS_CODE_STR, + BBPSConstant.HTTP_OK_INT, ""); } } \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java b/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java index be6c549..4eb656d 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java +++ b/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java @@ -135,4 +135,9 @@ public class BBPSConstant { public static final String ALL_MASTER_FIELDS_FETCH = "All master fields fetched successfully"; public static final String SOMETHING_WENT_WRONG = "Something went wrong"; + // Timing/delay constants (milliseconds) + public static final long BILL_FETCH_DELAY_MS = 5000L; // used after initiate bill fetch + public static final long BILL_VALIDATE_DELAY_MS = 12000L; // used after initiate bill validate + public static final long PAYMENT_STATUS_DELAY_MS = 9000L; // used after initiate payment + } \ No newline at end of file