added seprate forwardrequest code and added find things by clientReqId
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.convention.MatchingStrategies;
|
||||
@@ -14,8 +15,10 @@ import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
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.BillPaymentResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.TransactionStatusResponse;
|
||||
import com.billpaymentservice.bbps.dto.sentRequest.BillPaymentForwardRequest;
|
||||
import com.billpaymentservice.bbps.entites.AgentFundTransfer;
|
||||
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
|
||||
import com.billpaymentservice.bbps.entites.BillPayment;
|
||||
@@ -80,7 +83,7 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
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");
|
||||
@@ -92,15 +95,20 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
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", 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, requestJson, headers);
|
||||
Map<String, String> responseMap = httpService.postRequest(url, forwardjson, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Payment API Response: {}", responseData);
|
||||
|
||||
@@ -142,7 +150,7 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
transactionStatusRequest.setReqId(requestId);
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
Thread.sleep(9000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage());
|
||||
@@ -161,6 +169,8 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
String apiName = "CheckTransactionStatus";
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String requestId = transactionStatusRequest.getReqId();
|
||||
|
||||
|
||||
String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId();
|
||||
|
||||
LOGGER.info("Checking transaction status (internal) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId);
|
||||
@@ -293,8 +303,102 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseModel checkTrasactionStatusByClientReqId(TrasactionStatusByClientReqIdRequest transactionStatusRequest) {
|
||||
|
||||
helper.validateMerchant(transactionStatusRequest.getMid());
|
||||
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = "checkTrasactionStatusbyClientReqId";
|
||||
String requestId = transactionStatusRequest.getReqId();
|
||||
String clientReqId = transactionStatusRequest.getClientReqId();
|
||||
String requestJson = helper.convertObjectToJson(transactionStatusRequest);
|
||||
|
||||
LOGGER.info("Checking transaction status for clientReqId={} and reqId={}", clientReqId, requestId);
|
||||
|
||||
// Fetch Txn from DB
|
||||
Optional<PaymentInitiate> paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId);
|
||||
if (paymentInitiate.isEmpty()) {
|
||||
throw new CustomException("No Transaction Found for given Client Req Id");
|
||||
}
|
||||
|
||||
String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_BY_CLIENT_REQ_ID_URL + paymentInitiate.get().getTxnId();
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
// 🔵 Create Inbound + Outbound Logs
|
||||
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();
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling BBPS Transaction Status API URL={}", url);
|
||||
Map<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Transaction Status Response: {}", responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
// Parse response
|
||||
Map<String, Object> dataMap = objectMapper.readValue(
|
||||
responseData, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
// Validate response
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
helper.updateInboundLogFailure(inboundLog, responseData, "INVALID_RESPONSE");
|
||||
|
||||
LOGGER.warn("Invalid transaction status response for clientReqId={} | Response={}",
|
||||
clientReqId, 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"))
|
||||
);
|
||||
}
|
||||
|
||||
// Convert into proper DTO
|
||||
TransactionStatusResponse responseWrapper =
|
||||
objectMapper.convertValue(dataMap, TransactionStatusResponse.class);
|
||||
|
||||
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
||||
|
||||
LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus());
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
|
||||
return new ResponseModel(
|
||||
generalResp.getMessage(),
|
||||
generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()),
|
||||
responseWrapper
|
||||
);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e);
|
||||
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
||||
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
}
|
||||
/* PollBack logic for the fetchTxnByTxnId API
|
||||
* @Override public ResponseModel fetchTxnByTxnId(BillFetchByBillIdRequest
|
||||
* billFetchByBillIdRequest) {
|
||||
|
||||
Reference in New Issue
Block a user