added some more constants bpps constant

This commit is contained in:
Lincpay Tech
2025-11-24 18:35:43 +05:30
parent 435ee0dacf
commit d0812656ff
3 changed files with 73 additions and 70 deletions
@@ -97,8 +97,8 @@ public class AgentServiceImpl implements AgentService {
try { try {
LOGGER.info("Calling external API: {}", fullUrl); LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID)));
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
LOGGER.debug("Response received from BBPS: {}", responseData); LOGGER.debug("Response received from BBPS: {}", responseData);
@@ -106,7 +106,7 @@ public class AgentServiceImpl implements AgentService {
Map<String, Object> dataMap = objectMapper.readValue(responseData, Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() { new TypeReference<Map<String, Object>>() {
}); });
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
LOGGER.warn("Invalid response received for txnId: {}", txnId); LOGGER.warn("Invalid response received 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")),
@@ -138,7 +138,7 @@ public class AgentServiceImpl implements AgentService {
billFetchByBillIdRequest.setReqId(requestId); billFetchByBillIdRequest.setReqId(requestId);
LOGGER.info("Waiting for 2 seconds before fetching bill by ID..."); LOGGER.info("Waiting for 2 seconds before fetching bill by ID...");
try { try {
Thread.sleep(5000); Thread.sleep((long) BBPSConstant.BILL_FETCH_DELAY_MS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
LOGGER.warn("Thread interrupted during delay: {}", e.getMessage()); LOGGER.warn("Thread interrupted during delay: {}", e.getMessage());
@@ -167,8 +167,8 @@ public class AgentServiceImpl implements AgentService {
try { try {
LOGGER.info("Calling external API: {}", fullUrl); LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID)));
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("Bill FetchById Response: {}", responseData); LOGGER.info("Bill FetchById Response: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -177,7 +177,7 @@ public class AgentServiceImpl implements AgentService {
new TypeReference<Map<String, Object>>() { new TypeReference<Map<String, Object>>() {
}); });
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
LOGGER.warn("Invalid response structure for txnId: {}", txnId); 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")),
@@ -223,8 +223,8 @@ public class AgentServiceImpl implements AgentService {
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null);
LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl); LOGGER.info("Calling external BBPS API for FetchBillById, URL={}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID)));
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData); LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -233,7 +233,7 @@ public class AgentServiceImpl implements AgentService {
new TypeReference<Map<String, Object>>() { new TypeReference<Map<String, Object>>() {
}); });
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData); LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData);
throw new CustomException(String.valueOf(dataMap.get("message")), throw new CustomException(String.valueOf(dataMap.get("message")),
@@ -286,8 +286,8 @@ public class AgentServiceImpl implements AgentService {
try { try {
LOGGER.info("Calling external API: {}", fullUrl); LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); Map<String, String> responseMap = httpService.postRequest(fullUrl, forwardJson, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID)));
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
LOGGER.debug("Response received from BBPS: {}", responseData); LOGGER.debug("Response received from BBPS: {}", responseData);
@@ -295,7 +295,7 @@ public class AgentServiceImpl implements AgentService {
Map<String, Object> dataMap = objectMapper.readValue(responseData, Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() { new TypeReference<Map<String, Object>>() {
}); });
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
LOGGER.warn("Invalid response received for txnId: {}", txnId); LOGGER.warn("Invalid response received 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")),
@@ -326,7 +326,7 @@ public class AgentServiceImpl implements AgentService {
billFetchByBillIdRequest.setReqId(reqId); billFetchByBillIdRequest.setReqId(reqId);
LOGGER.info("Waiting for 2 seconds before fetching bill by ID..."); LOGGER.info("Waiting for 2 seconds before fetching bill by ID...");
try { try {
Thread.sleep(12000); Thread.sleep((long) BBPSConstant.BILL_VALIDATE_DELAY_MS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
LOGGER.warn("Thread interrupted during delay: {}", e.getMessage()); LOGGER.warn("Thread interrupted during delay: {}", e.getMessage());
@@ -357,8 +357,8 @@ public class AgentServiceImpl implements AgentService {
try { try {
LOGGER.info("Calling external API: {}", fullUrl); LOGGER.info("Calling external API: {}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID)));
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("Bill FetchById Response: {}", responseData); LOGGER.info("Bill FetchById Response: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -367,7 +367,7 @@ public class AgentServiceImpl implements AgentService {
new TypeReference<Map<String, Object>>() { new TypeReference<Map<String, Object>>() {
}); });
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
LOGGER.warn("Invalid response structure for txnId: {}", txnId); 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")),
@@ -416,15 +416,15 @@ public class AgentServiceImpl implements AgentService {
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null); OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, fullUrl, BBPSConstant.HTTP_GET, null);
LOGGER.info("Calling external BBPS API for ValidateByBillId, URL={}", fullUrl); LOGGER.info("Calling external BBPS API for ValidateByBillId, URL={}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID)));
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData); LOGGER.info("Response received from BBPS for billId={} : {}", billId, responseData);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
Map<String, Object> dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Object>>(){}); Map<String, Object> dataMap = objectMapper.readValue(responseData, new com.fasterxml.jackson.core.type.TypeReference<Map<String, Object>>(){});
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData); LOGGER.warn("Invalid response structure received for billId={} | Response={}", billId, responseData);
throw new CustomException(String.valueOf(dataMap.get("message")), throw new CustomException(String.valueOf(dataMap.get("message")),
@@ -475,8 +475,8 @@ public class AgentServiceImpl implements AgentService {
try { try {
LOGGER.info("Calling BBPS API FetchBillValidateByClientReqId, URL={}", fullUrl); LOGGER.info("Calling BBPS API FetchBillValidateByClientReqId, URL={}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID)));
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -484,7 +484,7 @@ public class AgentServiceImpl implements AgentService {
new TypeReference<Map<String, Object>>() { new TypeReference<Map<String, Object>>() {
}); });
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
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"))), Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
@@ -530,8 +530,8 @@ public class AgentServiceImpl implements AgentService {
try { try {
LOGGER.info("Calling BBPS API FetchBillByClientReqId, URL={}", fullUrl); LOGGER.info("Calling BBPS API FetchBillByClientReqId, URL={}", fullUrl);
Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId("ORG001"))); Map<String, String> responseMap = httpService.getRequest(fullUrl, helper.buildHeaders(beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID)));
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -539,7 +539,7 @@ public class AgentServiceImpl implements AgentService {
new TypeReference<Map<String, Object>>() { new TypeReference<Map<String, Object>>() {
}); });
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
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"))), Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
@@ -569,7 +569,7 @@ public class AgentServiceImpl implements AgentService {
} }
return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS, return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS,
BBPSConstant.SUCCESS_CODE_STR, 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, return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS,
BBPSConstant.SUCCESS_CODE_STR, BBPSConstant.SUCCESS_CODE_STR,
200, BBPSConstant.HTTP_OK_INT,
"" ""
); );
} }
@@ -92,42 +92,42 @@ public class PaymentServiceImpl implements PaymentService {
@Override @Override
public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) { public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) {
String apiName = "InitiatePayment"; String apiName = BBPSConstant.API_INITIATE_PAYMENT;
String txnId = helper.generateTxnId(15); String txnId = helper.generateTxnId(15);
String requestId = billPaymentRequest.getReqId(); String requestId = billPaymentRequest.getReqId();
String url = paymentUrl + BBPSConstant.PAYMENT_URL; String url = paymentUrl + BBPSConstant.PAYMENT_URL;
billPaymentRequest.setClientReqId(txnId); billPaymentRequest.setClientReqId(txnId);
LOGGER.info("Initiating payment for reqId={} and txnId={}", requestId, 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); HttpHeaders headers = helper.buildHeaders(headersData);
BillPaymentForwardRequest forwardReq = mapperHelper.billPaymentForwardRequest(billPaymentRequest); BillPaymentForwardRequest forwardReq = mapperHelper.billPaymentForwardRequest(billPaymentRequest);
String forwardjson = helper.convertObjectToJson(forwardReq); String forwardjson = helper.convertObjectToJson(forwardReq);
String requestJson = helper.convertObjectToJson(billPaymentRequest); String requestJson = helper.convertObjectToJson(billPaymentRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(), "POST", requestJson); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(), BBPSConstant.HTTP_POST, requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, "POST", forwardjson); OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_POST, forwardjson);
try { try {
LOGGER.info("Calling BBPS payment URL: {}", url); LOGGER.info("Calling BBPS payment URL: {}", url);
Map<String, String> responseMap = httpService.postRequest(url, forwardjson, headers); Map<String, String> 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); LOGGER.info("Payment API Response: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
if (responseData == null || responseData.isEmpty()) { 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); 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<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {}); Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
if (!dataMap.containsKey("genericResponse")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_STRUCTURE"); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_STRUCTURE);
LOGGER.warn("Invalid response structure received for txnId={}", txnId); 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); BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class);
@@ -151,7 +151,7 @@ public class PaymentServiceImpl implements PaymentService {
transactionStatusRequest.setReqId(requestId); transactionStatusRequest.setReqId(requestId);
try { try {
Thread.sleep(9000); Thread.sleep((long) BBPSConstant.PAYMENT_STATUS_DELAY_MS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage()); LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage());
@@ -161,13 +161,13 @@ public class PaymentServiceImpl implements PaymentService {
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
LOGGER.error("JSON Parsing Error in initiatePayment: {}", e.getMessage(), 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"); throw new CustomException("Invalid JSON received from API");
} }
} }
public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest, InboundTraceLog inboundLog) { public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest, InboundTraceLog inboundLog) {
String apiName = "CheckTransactionStatus"; String apiName = BBPSConstant.API_CHECK_TRANSACTION_STATUS;
String txnId = helper.generateTxnId(15); String txnId = helper.generateTxnId(15);
String requestId = transactionStatusRequest.getReqId(); 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); 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); 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<String, String> responseMap = httpService.getRequest(url, headers); Map<String, String> responseMap = httpService.getRequest(url, headers);
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("Transaction status response: {}", responseData); LOGGER.info("Transaction status response: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
try { try {
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {}); Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
if (!dataMap.containsKey("generalResp")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
LOGGER.warn("Invalid transaction status response for txnId={}", transactionStatusRequest.getTxnId()); LOGGER.warn("Invalid transaction status response for txnId={}", transactionStatusRequest.getTxnId());
throw new CustomException( throw new CustomException(
String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("message")),
@@ -229,7 +229,7 @@ public class PaymentServiceImpl implements PaymentService {
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
LOGGER.error("Error parsing transaction status JSON: {}", e.getMessage(), 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"); throw new CustomException("Invalid JSON received from API");
} }
} }
@@ -238,28 +238,28 @@ public class PaymentServiceImpl implements PaymentService {
public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) { public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) {
helper.validateMerchant(transactionStatusRequest.getMid()); helper.validateMerchant(transactionStatusRequest.getMid());
String txnID = helper.generateTxnId(15); String txnID = helper.generateTxnId(15);
String apiName = "checkTrasactionStatus"; String apiName = BBPSConstant.API_CHECK_TRANSACTION_PUBLIC;
String requestId = transactionStatusRequest.getReqId(); String requestId = transactionStatusRequest.getReqId();
String requestJson = helper.convertObjectToJson(transactionStatusRequest); String requestJson = helper.convertObjectToJson(transactionStatusRequest);
String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId();
LOGGER.info("Checking transaction status (public) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); 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); HttpHeaders headers = helper.buildHeaders(headersData);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, transactionStatusRequest.getMid(), "POST", requestJson); InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, transactionStatusRequest.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);
Map<String, String> responseMap = httpService.getRequest(url, headers); Map<String, String> 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); LOGGER.info("Transaction status response data: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
try { try {
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {}); Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
if (!dataMap.containsKey("generalResp")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) {
helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status"))); helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)));
LOGGER.warn("Invalid transaction status response for txnId={} from BBPS", transactionStatusRequest.getTxnId()); LOGGER.warn("Invalid transaction status response for txnId={} from BBPS", transactionStatusRequest.getTxnId());
throw new CustomException( throw new CustomException(
String.valueOf(dataMap.get("message")), String.valueOf(dataMap.get("message")),
@@ -287,7 +287,7 @@ public class PaymentServiceImpl implements PaymentService {
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage(), 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"); throw new CustomException("Invalid JSON received from API");
} }
} }
@@ -298,7 +298,7 @@ public class PaymentServiceImpl implements PaymentService {
helper.validateMerchant(transactionStatusRequest.getMid()); helper.validateMerchant(transactionStatusRequest.getMid());
String txnID = helper.generateTxnId(15); String txnID = helper.generateTxnId(15);
String apiName = "checkTrasactionStatusbyClientReqId"; String apiName = BBPSConstant.API_CHECK_BY_CLIENT_REQ_ID;
String requestId = transactionStatusRequest.getReqId(); String requestId = transactionStatusRequest.getReqId();
String clientReqId = transactionStatusRequest.getClientReqId(); String clientReqId = transactionStatusRequest.getClientReqId();
String requestJson = helper.convertObjectToJson(transactionStatusRequest); String requestJson = helper.convertObjectToJson(transactionStatusRequest);
@@ -307,25 +307,25 @@ public class PaymentServiceImpl implements PaymentService {
Optional<PaymentInitiate> paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId); Optional<PaymentInitiate> paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId);
if (paymentInitiate.isEmpty()) { 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(); 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); HttpHeaders headers = helper.buildHeaders(headersData);
InboundTraceLog inboundLog = helper.createInboundLog( InboundTraceLog inboundLog = helper.createInboundLog(
requestId, txnID, apiName, transactionStatusRequest.getMid(), "POST", requestJson); requestId, txnID, apiName, transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson);
OutboundTraceLog outboundLog = helper.createOutboundLog( OutboundTraceLog outboundLog = helper.createOutboundLog(
txnID, requestId, apiName, url, "GET", null); txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, null);
try { try {
LOGGER.info("Calling BBPS Transaction Status API URL={}", url); LOGGER.info("Calling BBPS Transaction Status API URL={}", url);
Map<String, String> responseMap = httpService.getRequest(url, headers); Map<String, String> responseMap = httpService.getRequest(url, headers);
String responseData = responseMap.get("data"); String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
LOGGER.info("Transaction Status Response: {}", responseData); LOGGER.info("Transaction Status Response: {}", responseData);
helper.updateOutboundLogResponse(outboundLog, responseData); helper.updateOutboundLogResponse(outboundLog, responseData);
@@ -333,8 +333,8 @@ public class PaymentServiceImpl implements PaymentService {
Map<String, Object> dataMap = objectMapper.readValue( Map<String, Object> dataMap = objectMapper.readValue(
responseData, new TypeReference<Map<String, Object>>() {}); responseData, new TypeReference<Map<String, Object>>() {});
if (!dataMap.containsKey("generalResp")) { if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) {
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE"); helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE);
LOGGER.warn("Invalid transaction status response for clientReqId={} | Response={}", LOGGER.warn("Invalid transaction status response for clientReqId={} | Response={}",
clientReqId, responseData); clientReqId, responseData);
@@ -355,7 +355,6 @@ public class PaymentServiceImpl implements PaymentService {
LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus()); LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus());
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
return new ResponseModel( return new ResponseModel(
generalResp.getMessage(), generalResp.getMessage(),
generalResp.getStatus(), generalResp.getStatus(),
@@ -365,8 +364,7 @@ public class PaymentServiceImpl implements PaymentService {
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e); LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
throw new CustomException("Invalid JSON received from API"); throw new CustomException("Invalid JSON received from API");
} }
@@ -376,16 +374,16 @@ public class PaymentServiceImpl implements PaymentService {
public ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse) { public ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse) {
LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", 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 { } else {
LOGGER.info("Bill Fetch Callback Failed with Status: {}", transactionStatusResponse.getGeneralResp().getStatus()); LOGGER.info("Bill Fetch Callback Failed with Status: {}", transactionStatusResponse.getGeneralResp().getStatus());
} }
return new ResponseModel("CallBack Recieved Successfully", return new ResponseModel(BBPSConstant.CALLBACK_RECEIVED_SUCCESS,
"200", BBPSConstant.SUCCESS_CODE_STR,
200, BBPSConstant.HTTP_OK_INT,
""); "");
} }
} }
@@ -135,4 +135,9 @@ public class BBPSConstant {
public static final String ALL_MASTER_FIELDS_FETCH = "All master fields fetched successfully"; public static final String ALL_MASTER_FIELDS_FETCH = "All master fields fetched successfully";
public static final String SOMETHING_WENT_WRONG = "Something went wrong"; 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
} }