removed heades section from impl and added it in helper
This commit is contained in:
@@ -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<String, String> 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<String, String> 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<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
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<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
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<String, String> 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<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
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<String, String> 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<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
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<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Transaction status response data: {}", responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
Map<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Transaction status response data: {}", responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
try {
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
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<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
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> 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> 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<String, String> 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<String, Object> dataMap = objectMapper.readValue(
|
||||
responseData, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling BBPS Transaction Status API URL={}", url);
|
||||
Map<String, String> 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<String, Object> dataMap = objectMapper.readValue(
|
||||
responseData, new TypeReference<Map<String, Object>>() {});
|
||||
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<String, String> responseMap = httpService.getRequest(fullUrl,headers);
|
||||
* String responseData = responseMap.get("data"); log.info("data is :{}",
|
||||
* responseData);
|
||||
*
|
||||
*
|
||||
* ObjectMapper objectMapper = new ObjectMapper();
|
||||
*
|
||||
* try { Map<String, Object> dataMap = objectMapper.readValue(responseData, new
|
||||
* TypeReference<Map<String, Object>>() { }); if
|
||||
* (!dataMap.containsKey("genericResponse")) { throw new
|
||||
* CustomException(String.valueOf(dataMap.get("message")), // message
|
||||
* String.valueOf(dataMap.get("status")), // status
|
||||
* Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode
|
||||
* (int) String.valueOf(dataMap.get("remarks")) ); }
|
||||
*
|
||||
* BillDataResponse responseWrapper = objectMapper.convertValue(dataMap,
|
||||
* BillDataResponse.class);
|
||||
*
|
||||
* GeneralResp generalResp = responseWrapper.getGenericResponse();
|
||||
*
|
||||
* ResponseModel responseModel=new ResponseModel( generalResp.getMessage(),
|
||||
* generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()),
|
||||
* responseWrapper);
|
||||
*
|
||||
* 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<String, String> responseMap = httpService.getRequest(url,
|
||||
* headers); String responseData = responseMap.get("data");
|
||||
* LOGGER.info("Transaction status response: {}", responseData);
|
||||
*
|
||||
* helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
*
|
||||
* try { Map<String, Object> dataMap = objectMapper.readValue(responseData, new
|
||||
* TypeReference<Map<String, Object>>() {});
|
||||
*
|
||||
* 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"); } }
|
||||
* }
|
||||
*
|
||||
*
|
||||
*/
|
||||
return new ResponseModel("CallBack Recieved Successfully",
|
||||
"200",
|
||||
200,
|
||||
"");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user