Merge pull request 'feature/id-length-fix' (#38) from feature/id-length-fix into develop
Reviewed-on: https://git.zeptic.in/himanshu/bbps/pulls/38
This commit is contained in:
@@ -468,14 +468,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
throw new CustomException(BBPSConstant.MSG_INVALID_JSON_FROM_UPSTREAM,BBPSConstant.FAILED_STATUS, BBPSConstant.INVALID_JSON_STATUS_CODE, e.getMessage());
|
||||
}
|
||||
}
|
||||
// ================================== 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)
|
||||
// >>>>>>>d0812656ff2aee80b1eb0c0ab8e29a01d7d66553
|
||||
|
||||
@Override
|
||||
public ResponseModel fetchBillValidateByClientReqId(BillValidateByClientIdRequest billValidateByClientIdRequest) {
|
||||
|
||||
@@ -127,7 +127,7 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
|
||||
try {
|
||||
|
||||
Optional<TransactionMaster> dataById = transactionMasterRepository.findById(complainRequestDTO.getTxnId());
|
||||
Optional<TransactionMaster> dataById = transactionMasterRepository.findByBankTxnId(complainRequestDTO.getTxnId());
|
||||
if (dataById == null || dataById.isEmpty()) {
|
||||
LOGGER.warn("Txn Data Not Found This Txn Id is null");
|
||||
throw new CustomException(BBPSConstant.USER_Txn_IS_NOT_FOUND, "FAILED", BBPSConstant.BADREQUEST, null);
|
||||
|
||||
@@ -181,20 +181,15 @@ public class HttpService {
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
|
||||
log.info("🌐 Sending FORM POST to: {}", url);
|
||||
log.info("📦 Payload: {}", formBody);
|
||||
|
||||
ResponseEntity<String> restResponse = restClient.post()
|
||||
.uri(url)
|
||||
.headers(h -> h.addAll(headers))
|
||||
.body(formBody)
|
||||
.retrieve()
|
||||
.toEntity(String.class);
|
||||
|
||||
response.put("respCode", String.valueOf(restResponse.getStatusCode().value()));
|
||||
|
||||
// HTML RESPONSE directly stored
|
||||
response.put("data", restResponse.getBody());
|
||||
|
||||
log.info("✅ FORM POST Response Status: {}", restResponse.getStatusCode());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -12,6 +13,7 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.TransactionDTO;
|
||||
import com.billpaymentservice.bbps.dto.request.BillPaymentRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.TransactionStatusRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.TrasactionStatusByClientReqIdRequest;
|
||||
@@ -23,14 +25,12 @@ import com.billpaymentservice.bbps.entites.BharatConnectMaster;
|
||||
import com.billpaymentservice.bbps.entites.BillPayment;
|
||||
import com.billpaymentservice.bbps.entites.InboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.PaymentInitiate;
|
||||
import com.billpaymentservice.bbps.entites.TransactionMaster;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.AgentFundTransferRepository;
|
||||
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
|
||||
import com.billpaymentservice.bbps.repository.InboundTraceLogRepository;
|
||||
import com.billpaymentservice.bbps.repository.OutboundTraceLogRepository;
|
||||
import com.billpaymentservice.bbps.repository.PaymentIntiateRepository;
|
||||
import com.billpaymentservice.bbps.repository.PaymentRepository;
|
||||
import com.billpaymentservice.bbps.repository.TransactionMasterRepository;
|
||||
import com.billpaymentservice.bbps.service.PaymentService;
|
||||
@@ -54,7 +54,6 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
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 BillerMapperHelper mapperHelper;
|
||||
@@ -66,8 +65,7 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
|
||||
public PaymentServiceImpl(BharatConnectMasterRepository beneficiaryDetailsRepository, HttpService httpService,
|
||||
Helper helper, PaymentRepository paymentRepository, InboundTraceLogRepository inboundTraceLogRepository,
|
||||
OutboundTraceLogRepository outboundTraceLogRepository, PaymentIntiateRepository paymentIntiateRepository,
|
||||
TransactionMasterRepository transactionMasterRepository,
|
||||
OutboundTraceLogRepository outboundTraceLogRepository, TransactionMasterRepository transactionMasterRepository,
|
||||
AgentFundTransferRepository agentFundTransferRepository, BillerMapperHelper mapperHelper) {
|
||||
this.beneficiaryDetailsRepository = beneficiaryDetailsRepository;
|
||||
this.httpService = httpService;
|
||||
@@ -75,7 +73,6 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
this.paymentRepository = paymentRepository;
|
||||
this.inboundTraceLogRepository = inboundTraceLogRepository;
|
||||
this.outboundTraceLogRepository = outboundTraceLogRepository;
|
||||
this.paymentIntiateRepository = paymentIntiateRepository;
|
||||
this.transactionMasterRepository = transactionMasterRepository;
|
||||
this.agentFundTransferRepository = agentFundTransferRepository;
|
||||
this.mapperHelper = mapperHelper;
|
||||
@@ -108,97 +105,76 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
String requestJson = helper.convertObjectToJson(billPaymentRequest);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(),
|
||||
BBPSConstant.HTTP_POST, requestJson);
|
||||
BBPSConstant.HTTP_POST, requestJson);
|
||||
LOGGER.debug("Inbound log created for api={} | reqId={} | txnId={}", apiName, requestId, txnId);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_POST,
|
||||
forwardjson);
|
||||
forwardjson);
|
||||
LOGGER.debug("Outbound log created for api={} | reqId={} | txnId={}", apiName, requestId, txnId);
|
||||
|
||||
try {
|
||||
LOGGER.info("Calling BBPS payment URL: {}", url);
|
||||
Map<String, String> responseMap = httpService.postRequest(url, forwardjson, headers);
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Payment API Response: {}", responseData);
|
||||
TransactionMaster preTransaction=null;
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
LOGGER.debug("Outbound log response updated for txnId={}", txnId);
|
||||
preTransaction = new TransactionMaster();
|
||||
preTransaction.setTxnId(txnId);
|
||||
preTransaction.setInitiatorTxnId(txnId);
|
||||
preTransaction.setReqId(requestId);
|
||||
preTransaction.setMid(billPaymentRequest.getMid());
|
||||
preTransaction.setClientUserId(billPaymentRequest.getClientUserId());
|
||||
preTransaction.setClientReqId(billPaymentRequest.getClientReqId());
|
||||
preTransaction.setUserId(userId);
|
||||
preTransaction.setStatus("PENDING");
|
||||
EntityRelationshipUtil.linkTransactionMasterRelationships(preTransaction);
|
||||
// ensure txnId exists (no uniqueness suffixing)
|
||||
preTransaction.setTxnId(ensureTxnId(preTransaction.getTxnId()));
|
||||
transactionMasterRepository.save(preTransaction);
|
||||
LOGGER.info("Pre-request TransactionMaster saved with status=INITIATED for txnId={}", txnId);
|
||||
|
||||
if (responseData == null || responseData.isEmpty()) {
|
||||
helper.updateInboundLogFailure(inboundLog, BBPSConstant.EMPTY_RESPONSE_FROM_BBPS,
|
||||
BBPSConstant.FAILED_STR);
|
||||
LOGGER.warn("Empty response received from BBPS for txnId={}", txnId);
|
||||
throw new CustomException(
|
||||
BBPSConstant.EMPTY_RESPONSE_FROM_BBPS, // message
|
||||
BBPSConstant.FAILED_STATUS, // status
|
||||
502, // statusCode
|
||||
"BBPS upstream returned empty response"
|
||||
);
|
||||
}
|
||||
LOGGER.info("Calling BBPS payment URL: {}", url);
|
||||
Map<String, String> responseMap = httpService.postRequest(url, forwardjson, headers);
|
||||
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Payment API Response: {}", responseData);
|
||||
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
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(BBPSConstant.INVALID_STRUCTURE);
|
||||
}
|
||||
BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class);
|
||||
|
||||
GeneralResp generalResponse = billPaymentResponse.getGenericResponse();
|
||||
LOGGER.info("genric Response" + generalResponse);
|
||||
if(generalResponse.getStatus().equalsIgnoreCase("Failed")) {
|
||||
throw new CustomException(generalResponse.getMessage(), generalResponse.getStatus(),
|
||||
Integer.parseInt(generalResponse.getStatusCode()), generalResponse.getRemarks());
|
||||
}
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
LOGGER.debug("Outbound log response updated for txnId={}", txnId);
|
||||
|
||||
|
||||
BillPayment entity = modelMapper.map(billPaymentResponse, BillPayment.class);
|
||||
paymentRepository.save(entity);
|
||||
LOGGER.info("BillPayment entity saved successfully for txnId={}", txnId);
|
||||
Map<String, Object> dataMap = parseJsonToMap(responseData, inboundLog);
|
||||
|
||||
BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class);
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus());
|
||||
PaymentInitiate paymentInitiate = new PaymentInitiate();
|
||||
paymentInitiate.setTxnId(txnId);
|
||||
paymentInitiate.setUserId(userId);
|
||||
paymentInitiate.setReqId(requestId);
|
||||
paymentInitiate.setMid(billPaymentRequest.getMid());
|
||||
paymentInitiate.setClientUserId(billPaymentRequest.getClientUserId());
|
||||
paymentInitiate.setBankTxnId(billPaymentResponse.getTxnId());
|
||||
paymentInitiate.setStatus(billPaymentResponse.getStatus());
|
||||
paymentIntiateRepository.save(paymentInitiate);
|
||||
LOGGER.info("PaymentInitiate entry saved successfully for txnId={}", txnId);
|
||||
GeneralResp generalResponse = billPaymentResponse.getGenericResponse();
|
||||
LOGGER.info("genric Response" + generalResponse);
|
||||
|
||||
|
||||
TransactionStatusRequest transactionStatusRequest = new TransactionStatusRequest();
|
||||
transactionStatusRequest.setTxnId(billPaymentResponse.getTxnId());
|
||||
transactionStatusRequest.setReqId(requestId);
|
||||
transactionStatusRequest.setMid(billPaymentRequest.getMid());
|
||||
transactionStatusRequest.setClientUserId(billPaymentRequest.getClientUserId());
|
||||
BillPayment entity = modelMapper.map(billPaymentResponse, BillPayment.class);
|
||||
paymentRepository.save(entity);
|
||||
LOGGER.info("BillPayment entity saved successfully for txnId={}", txnId);
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep((long) BBPSConstant.PAYMENT_STATUS_DELAY_MS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage());
|
||||
}
|
||||
LOGGER.info("Checking transaction status for txnId={}", billPaymentResponse.getTxnId());
|
||||
LOGGER.info("[{}] END | reqId={} | txnId={}", apiName, requestId, txnId);
|
||||
return checkTrasactionStatus(transactionStatusRequest, inboundLog);
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus());
|
||||
|
||||
preTransaction.setBankTxnId(entity.getTxnId());
|
||||
transactionMasterRepository.save(preTransaction);
|
||||
LOGGER.info("updated TransactionMaster with bankTxnId for txnId={}", txnId);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("JSON Parsing Error in initiatePayment: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException(BBPSConstant.MSG_INVALID_JSON_FROM_UPSTREAM, BBPSConstant.FAILED_STATUS, BBPSConstant.INVALID_JSON_STATUS_CODE, e.getMessage());
|
||||
}
|
||||
|
||||
TransactionStatusRequest transactionStatusRequest = new TransactionStatusRequest();
|
||||
transactionStatusRequest.setReqId(billPaymentRequest.getReqId());
|
||||
transactionStatusRequest.setTxnId(entity.getTxnId());
|
||||
ResponseModel responseModel = checkTrasactionStatus(transactionStatusRequest, inboundLog);
|
||||
return responseModel;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest,
|
||||
InboundTraceLog inboundLog) {
|
||||
String apiName = BBPSConstant.API_CHECK_TRANSACTION_STATUS;
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String checkerTxnId = helper.generateTxnId(15);
|
||||
String requestId = transactionStatusRequest.getReqId();
|
||||
// START log for internal transaction status check
|
||||
LOGGER.info("[{}] START (internal) | checkTxnId={} | reqId={} | bankTxnId={}", apiName, txnId, requestId,
|
||||
LOGGER.info("[{}] START (internal) | checkTxnId={} | reqId={} | bankTxnId={}", apiName, checkerTxnId, requestId,
|
||||
transactionStatusRequest.getTxnId());
|
||||
|
||||
String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId();
|
||||
@@ -209,132 +185,142 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_GET,
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(checkerTxnId, requestId, apiName, url, BBPSConstant.HTTP_GET,
|
||||
null);
|
||||
LOGGER.debug("Outbound log created for internal status check | txnId={} | reqId={}", txnId, requestId);
|
||||
LOGGER.debug("Outbound log created for internal status check | txnId={} | reqId={}", checkerTxnId, requestId);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Transaction status response: {}", responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
LOGGER.debug("Outbound log response updated for internal status check | txnId={}", txnId);
|
||||
LOGGER.debug("Outbound log response updated for internal status check | txnId={}", checkerTxnId);
|
||||
|
||||
try {
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
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")), 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();
|
||||
LOGGER.info("Transaction status received: {}", generalResp.getStatus());
|
||||
|
||||
TransactionMaster transactionMaster = modelMapper.map(responseWrapper.getTransactionDAO(),
|
||||
TransactionMaster.class);
|
||||
transactionMaster.setTxnId(txnId);
|
||||
transactionMaster.setReqId(transactionStatusRequest.getReqId());
|
||||
transactionMaster.setMid(transactionStatusRequest.getMid());
|
||||
transactionMaster.setClientUserId(transactionStatusRequest.getClientUserId());
|
||||
EntityRelationshipUtil.linkTransactionMasterRelationships(transactionMaster);
|
||||
transactionMasterRepository.save(transactionMaster);
|
||||
LOGGER.info("TransactionMaster saved successfully for txnId={}", txnId);
|
||||
|
||||
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);
|
||||
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
LOGGER.info("[{}] END (internal) | checkTxnId={} | reqId={} | status={}", apiName, txnId, requestId,
|
||||
generalResp.getStatus());
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing transaction status JSON: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException(BBPSConstant.MSG_INVALID_JSON_FROM_UPSTREAM, BBPSConstant.FAILED_STATUS, BBPSConstant.INVALID_JSON_STATUS_CODE, e.getMessage());
|
||||
Map<String, Object> dataMap = parseJsonToMap(responseData, inboundLog);
|
||||
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")), 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();
|
||||
TransactionDTO txDao = responseWrapper.getTransactionDAO();
|
||||
|
||||
TransactionMaster transactionMaster = modelMapper.map(txDao,
|
||||
TransactionMaster.class);
|
||||
|
||||
LOGGER.info("INBOUND TRANSACTION ID:{}",inboundLog.getTxnId());
|
||||
TransactionMaster
|
||||
existingTransaction=transactionMasterRepository.findByInitiatorTxnId(
|
||||
inboundLog.getTxnId());
|
||||
LOGGER.info("existingTransaction :{}",existingTransaction);
|
||||
if(existingTransaction != null) {
|
||||
LOGGER.info("Existing TransactionMaster found for bankTxnId");
|
||||
// Merge incoming non-null fields into the existing DB entity so we preserve DB values
|
||||
helper.mergeNonNullFields(transactionMaster, existingTransaction);
|
||||
transactionMaster = existingTransaction;
|
||||
}
|
||||
transactionMaster.setCheckerTxnId(checkerTxnId);
|
||||
EntityRelationshipUtil.linkTransactionMasterRelationships(transactionMaster);
|
||||
AgentFundTransfer agentFundTransfer = null;
|
||||
if (responseWrapper.getAgentFundTransfer() != null) {
|
||||
agentFundTransfer = modelMapper.map(responseWrapper.getAgentFundTransfer(), AgentFundTransfer.class);
|
||||
} else {
|
||||
agentFundTransfer = new AgentFundTransfer();
|
||||
}
|
||||
agentFundTransfer.setTxnId(transactionMaster.getTxnId());
|
||||
agentFundTransfer.setReqId(transactionStatusRequest.getReqId());
|
||||
agentFundTransfer.setTransactionMasterId(transactionMaster.getBankTxnId());
|
||||
|
||||
transactionMasterRepository.save(transactionMaster);
|
||||
if (agentFundTransfer != null) { agentFundTransferRepository.save(agentFundTransfer); }
|
||||
LOGGER.info("Persisted TransactionMaster and AgentFundTransfer for txnId={} bankTxnId={}"
|
||||
, transactionMaster.getTxnId(), transactionMaster.getBankTxnId());
|
||||
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
LOGGER.info("[{}] END (internal) | checkTxnId={} | reqId={} | status={}", apiName, checkerTxnId, requestId, generalResp.getStatus());
|
||||
return responseModel;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) {
|
||||
helper.validateMerchant(transactionStatusRequest.getMid());
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = BBPSConstant.API_CHECK_TRANSACTION_PUBLIC;
|
||||
String requestId = transactionStatusRequest.getReqId();
|
||||
LOGGER.info("[{}] START (public) | reqId={} | mid={} | checkBankTxnId={}", apiName, requestId,
|
||||
transactionStatusRequest.getMid(), transactionStatusRequest.getTxnId());
|
||||
String requestJson = helper.convertObjectToJson(transactionStatusRequest);
|
||||
String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId();
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String apiName = BBPSConstant.API_CHECK_TRANSACTION_PUBLIC;
|
||||
String requestId = transactionStatusRequest.getReqId();
|
||||
LOGGER.info("[{}] START (public) | reqId={} | mid={} | checkBankTxnId={}", apiName, requestId,
|
||||
transactionStatusRequest.getMid(), transactionStatusRequest.getTxnId());
|
||||
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);
|
||||
LOGGER.info("Checking transaction status (public) for txnId={} and reqId{}",
|
||||
transactionStatusRequest.getTxnId(), requestId);
|
||||
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
// First, attempt to find an existing TransactionMaster by initiatorTxnId and update it
|
||||
String initiatorTxnId = transactionStatusRequest.getTxnId();
|
||||
if (initiatorTxnId != null && !initiatorTxnId.isBlank()) {
|
||||
// logic intentionally left minimal here — any runtime exception should bubble
|
||||
// to the global exception handler so failures are visible and handled centrally.
|
||||
}
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName,
|
||||
transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson);
|
||||
LOGGER.debug("Inbound log created for public status check | reqId={} | txnId={}", requestId, txnID);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET,
|
||||
null);
|
||||
LOGGER.debug("Outbound log created for public status check | reqId={} | txnId={}", requestId, txnID);
|
||||
LOGGER.info("Falling back to external BBPS status check URL={}", url);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Transaction status response data: {}", responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
LOGGER.debug("Outbound log response updated for public status check | reqId={} | txnId={}", requestId, txnID);
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
try {
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
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")), String.valueOf(dataMap.get("status")),
|
||||
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
|
||||
String.valueOf(dataMap.get("remarks")));
|
||||
}
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName,
|
||||
transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson);
|
||||
LOGGER.debug("Inbound log created for public status check | reqId={} | txnId={}", requestId, txnID);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET,
|
||||
null);
|
||||
LOGGER.debug("Outbound log created for public status check | reqId={} | txnId={}", requestId, txnID);
|
||||
|
||||
TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap,
|
||||
TransactionStatusResponse.class);
|
||||
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
||||
Map<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Transaction status response data: {}", responseData);
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
LOGGER.debug("Outbound log response updated for public status check | reqId={} | txnId={}", requestId, txnID);
|
||||
|
||||
String status = generalResp.getStatus();
|
||||
LOGGER.info("Current transaction status: {}", status);
|
||||
Map<String, Object> dataMap = parseJsonToMap(responseData, inboundLog);
|
||||
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")), String.valueOf(dataMap.get("status")),
|
||||
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
|
||||
String.valueOf(dataMap.get("remarks")));
|
||||
}
|
||||
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap,
|
||||
TransactionStatusResponse.class);
|
||||
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
LOGGER.info("[{}] END (public) | reqId={} | txnId={} | status={}", apiName, requestId, txnID,
|
||||
generalResp.getStatus());
|
||||
return responseModel;
|
||||
String status = generalResp.getStatus();
|
||||
LOGGER.info("Current transaction status: {}", status);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException(BBPSConstant.MSG_INVALID_JSON_FROM_UPSTREAM,BBPSConstant.FAILED_STATUS, BBPSConstant.INVALID_JSON_STATUS_CODE, e.getMessage());
|
||||
}
|
||||
}
|
||||
// --- NEW: attempt to persist/update TransactionMaster so DB reflects new status/bankTxnId ---
|
||||
TransactionDTO txDao = responseWrapper.getTransactionDAO();
|
||||
TransactionMaster updatedEntity = null;
|
||||
|
||||
|
||||
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
LOGGER.info("[{}] END (public) | reqId={} | txnId={} | status={}", apiName, requestId, txnID,
|
||||
generalResp.getStatus());
|
||||
return responseModel;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel checkTrasactionStatusByClientReqId(
|
||||
@@ -350,73 +336,93 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
LOGGER.info("[{}] START | reqId={} | mid={} | clientReqId={}", apiName, requestId,
|
||||
transactionStatusRequest.getMid(), clientReqId);
|
||||
|
||||
Optional<PaymentInitiate> paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId);
|
||||
if (paymentInitiate.isEmpty()) {
|
||||
// look up TransactionMaster(s) by clientReqId instead of PaymentInitiate
|
||||
List<TransactionMaster> transactionMasters = transactionMasterRepository.findByClientReqId(clientReqId);
|
||||
if (transactionMasters == null || transactionMasters.isEmpty()) {
|
||||
throw new CustomException(
|
||||
BBPSConstant.NO_BILL_FOUND, // message // status
|
||||
BBPSConstant.FAILED_STATUS,
|
||||
BBPSConstant.HTTP_NOT_FOUND, // statusCode
|
||||
"Bill not found in database for given clientReqId"
|
||||
BBPSConstant.NO_BILL_FOUND, // message // status
|
||||
BBPSConstant.FAILED_STATUS,
|
||||
BBPSConstant.HTTP_NOT_FOUND, // statusCode
|
||||
"Bill not found in database for given clientReqId"
|
||||
);
|
||||
}
|
||||
|
||||
// prefer a TransactionMaster with a real bankTxnId (not a placeholder)
|
||||
TransactionMaster chosen = null;
|
||||
for (TransactionMaster t : transactionMasters) {
|
||||
if (t.getBankTxnId() != null && !t.getBankTxnId().startsWith("PENDING_") && !t.getBankTxnId().startsWith("INVALID_") && !t.getBankTxnId().startsWith("INVALID_JSON_")) {
|
||||
chosen = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chosen == null) chosen = transactionMasters.get(0);
|
||||
|
||||
String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_BY_CLIENT_REQ_ID_URL
|
||||
+ paymentInitiate.get().getTxnId();
|
||||
+ chosen.getTxnId();
|
||||
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
||||
HttpHeaders headers = helper.buildHeaders(headersData);
|
||||
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName,
|
||||
transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson);
|
||||
transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson);
|
||||
LOGGER.debug("Inbound log created for clientReqId check | reqId={} | txnId={}", requestId, txnID);
|
||||
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET,
|
||||
null);
|
||||
null);
|
||||
LOGGER.debug("Outbound log created for clientReqId check | reqId={} | txnId={}", requestId, txnID);
|
||||
|
||||
LOGGER.info("Calling BBPS Transaction Status API URL={}", url);
|
||||
Map<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Transaction Status Response: {}", responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
LOGGER.debug("Outbound log response updated for clientReqId check | reqId={} | txnId={}", requestId, txnID);
|
||||
|
||||
Map<String, Object> dataMap = parseJsonToMap(responseData, inboundLog);
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
|
||||
LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus());
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
LOGGER.info("[{}] END | reqId={} | clientReqId={} | status={}", apiName, requestId, clientReqId,
|
||||
generalResp.getStatus());
|
||||
|
||||
return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
}
|
||||
|
||||
private String ensureTxnId(String txnId) {
|
||||
if (txnId == null || txnId.isBlank()) {
|
||||
return helper.generateTxnId(15);
|
||||
}
|
||||
return txnId;
|
||||
}
|
||||
|
||||
private Map<String, Object> parseJsonToMap(String responseData, InboundTraceLog inboundLog) {
|
||||
try {
|
||||
LOGGER.info("Calling BBPS Transaction Status API URL={}", url);
|
||||
Map<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
|
||||
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
||||
LOGGER.info("Transaction Status Response: {}", responseData);
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
LOGGER.debug("Outbound log response updated for clientReqId check | reqId={} | txnId={}", requestId, txnID);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
|
||||
LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus());
|
||||
|
||||
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
||||
LOGGER.info("[{}] END | reqId={} | clientReqId={} | status={}", apiName, requestId, clientReqId,
|
||||
generalResp.getStatus());
|
||||
return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
||||
|
||||
return objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e);
|
||||
LOGGER.error("Error parsing JSON response: {}", e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException(BBPSConstant.MSG_INVALID_JSON_FROM_UPSTREAM,BBPSConstant.FAILED_STATUS, BBPSConstant.INVALID_JSON_STATUS_CODE, e.getMessage());
|
||||
throw new CustomException(BBPSConstant.MSG_INVALID_JSON_FROM_UPSTREAM, BBPSConstant.FAILED_STATUS, BBPSConstant.INVALID_JSON_STATUS_CODE, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+98
-80
@@ -87,7 +87,6 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
String txnId = helper.generateTxnId(15);
|
||||
LOGGER.info("MID IS:{}",paymentMid);
|
||||
LOGGER.info("[startIntentPayment] enter requestId={} txnId={} mid={}", requestId, txnId, request.getMid());
|
||||
|
||||
helper.validateMerchant(request.getMid());
|
||||
|
||||
// inbound log
|
||||
@@ -102,7 +101,7 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
sent.setEnckey(paymentEncryKey);
|
||||
String plaintext = helper.convertObjectToJson(sent);
|
||||
String encrypted = encryptionUtil.encryptMData(plaintext, paymentEncryKey);
|
||||
|
||||
|
||||
PaymentRequestPayload finalPayload = new PaymentRequestPayload();
|
||||
finalPayload.setMid(paymentMid);
|
||||
finalPayload.setPayload(encrypted);
|
||||
@@ -111,9 +110,13 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
|
||||
LOGGER.info("[startIntentPayment] outbound payload prepared txnId={} orderNo={}", txnId, orderNo);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, BBPSConstant.UAT_PAYMENT_URL_INTENT, BBPSConstant.HTTP_POST, forwardJson);
|
||||
|
||||
PaymentStartRecord paymentRecord=bbpsMapperHelper.savePaymentStartRecord(request, null, txnId, orderNo, requestJson, null, null);
|
||||
|
||||
|
||||
// call external API
|
||||
Map<String, String> responseMap = httpService.postRequest(BBPSConstant.UAT_PAYMENT_URL_INTENT, forwardJson, null);
|
||||
|
||||
LOGGER.debug("[startIntentPayment] raw response map: {}", responseMap);
|
||||
|
||||
int httpCode = Integer.parseInt(responseMap.getOrDefault(BBPSConstant.RESP_CODE_KEY, String.valueOf(BBPSConstant.HTTP_INTERNAL_SERVER_ERROR)));
|
||||
@@ -124,12 +127,15 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
if (httpCode != BBPSConstant.HTTP_OK_INT) {
|
||||
helper.updateInboundLogFailure(inboundLog, respBody, String.valueOf(httpCode));
|
||||
LOGGER.error("[startIntentPayment] upstream HTTP error txnId={} httpCode={} body={}", txnId, httpCode, respBody);
|
||||
paymentRecord.setTxnStatus(BBPSConstant.FAILED_STR);
|
||||
paymentStartRecordRepository.save(paymentRecord);
|
||||
throw new CustomException(BBPSConstant.MSG_UPSTREAM_HTTP_ERROR, BBPSConstant.FAILED_STR, httpCode, respBody);
|
||||
}
|
||||
|
||||
if (respBody == null || respBody.isEmpty()) {
|
||||
helper.updateInboundLogFailure(inboundLog, BBPSConstant.MSG_EMPTY_RESPONSE_PROVIDER, String.valueOf(BBPSConstant.HTTP_INTERNAL_SERVER_ERROR));
|
||||
LOGGER.error("[startIntentPayment] empty response txnId={}", txnId);
|
||||
paymentRecord.setTxnStatus(BBPSConstant.FAILED_STR);
|
||||
throw new CustomException(BBPSConstant.MSG_EMPTY_RESPONSE_PROVIDER, BBPSConstant.FAILED_STR, BBPSConstant.HTTP_INTERNAL_SERVER_ERROR, null);
|
||||
}
|
||||
|
||||
@@ -211,79 +217,83 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseModel startWebPayment(PaymentStartUserRequest request) {
|
||||
|
||||
String requestId = request.getReqId();
|
||||
String apiName = BBPSConstant.API_START_PAYMENT;
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String requestId = request.getReqId();
|
||||
String apiName = BBPSConstant.API_START_PAYMENT;
|
||||
String txnId = helper.generateTxnId(15);
|
||||
LOGGER.info("[startWebPayment] enter requestId={} txnId={} mid={}", requestId, txnId, request.getMid());
|
||||
|
||||
LOGGER.info("[startWebPayment] enter requestId={} txnId={} mid={}", requestId, txnId, request.getMid());
|
||||
helper.validateMerchant(request.getMid());
|
||||
|
||||
helper.validateMerchant(request.getMid());
|
||||
|
||||
// inbound log
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
InboundTraceLog inboundLog =
|
||||
// inbound log
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
InboundTraceLog inboundLog =
|
||||
helper.createInboundLog(requestId, txnId, apiName, request.getMid(),
|
||||
BBPSConstant.HTTP_POST, requestJson);
|
||||
LOGGER.debug("[startWebPayment] inbound log created txnId={} requestId={}", txnId, requestId);
|
||||
LOGGER.debug("[startWebPayment] inbound log created txnId={} requestId={}", txnId, requestId);
|
||||
|
||||
// Prepare request payload
|
||||
PaymentDetailSentRequest sent = createPaymentSentRequest(request);
|
||||
String orderNo = "ORD" + helper.generateTxnId(12);
|
||||
sent.setOrderNo(orderNo);
|
||||
// Prepare request payload
|
||||
PaymentDetailSentRequest sent = createPaymentSentRequest(request);
|
||||
String orderNo = "ORD" + helper.generateTxnId(12);
|
||||
sent.setOrderNo(orderNo);
|
||||
|
||||
String plaintext = helper.convertObjectToJson(sent);
|
||||
String encKey = paymentEncryKey;
|
||||
sent.setEnckey(encKey);
|
||||
String plaintext = helper.convertObjectToJson(sent);
|
||||
String encKey = paymentEncryKey;
|
||||
sent.setEnckey(encKey);
|
||||
|
||||
LOGGER.debug("[startWebPayment] plaintext prepared txnId={} orderNo={}", txnId, orderNo);
|
||||
LOGGER.debug("[startWebPayment] plaintext prepared txnId={} orderNo={}", txnId, orderNo);
|
||||
|
||||
String encrypted = encryptionUtil.encryptMData(plaintext, encKey);
|
||||
LOGGER.info("[startWebPayment] payload encrypted txnId={} orderNo={}", txnId, orderNo);
|
||||
String encrypted = encryptionUtil.encryptMData(plaintext, encKey);
|
||||
LOGGER.info("[startWebPayment] payload encrypted txnId={} orderNo={}", txnId, orderNo);
|
||||
|
||||
// ----------- BUILD x-www-form-urlencoded PAYLOAD -----------
|
||||
String formPayload =
|
||||
"mid=" + URLEncoder.encode(paymentMid, StandardCharsets.UTF_8) +
|
||||
"&payload=" + URLEncoder.encode(encrypted, StandardCharsets.UTF_8);
|
||||
// ----------- BUILD x-www-form-urlencoded PAYLOAD -----------
|
||||
String formPayload =
|
||||
"mid=" + URLEncoder.encode(paymentMid, StandardCharsets.UTF_8) +
|
||||
"&payload=" + URLEncoder.encode(encrypted, StandardCharsets.UTF_8);
|
||||
LOGGER.info("[startWebPayment] Form Payload: {}", formPayload);
|
||||
OutboundTraceLog outboundLog =
|
||||
helper.createOutboundLog(txnId, requestId, apiName, BBPSConstant.UAT_PAYMENT_URL_WEB,
|
||||
BBPSConstant.HTTP_POST, formPayload);
|
||||
LOGGER.debug("[startWebPayment] outbound log created txnId={} url={}", txnId, BBPSConstant.UAT_PAYMENT_URL_WEB);
|
||||
OutboundTraceLog outboundLog =
|
||||
helper.createOutboundLog(txnId, requestId, apiName, BBPSConstant.UAT_PAYMENT_URL_WEB,
|
||||
BBPSConstant.HTTP_POST, formPayload);
|
||||
LOGGER.debug("[startWebPayment] outbound log created txnId={} url={}", txnId, BBPSConstant.UAT_PAYMENT_URL_WEB);
|
||||
PaymentStartRecord paymentRecord= bbpsMapperHelper.savePaymentStartRecord(request, null, txnId, orderNo, requestJson, null, null);
|
||||
|
||||
// ----------- CALL API (FORM URL-ENCODED) -----------
|
||||
Map<String, String> responseMap =
|
||||
httpService.postFormRequest(BBPSConstant.UAT_PAYMENT_URL_WEB, formPayload);
|
||||
// ----------- CALL API (FORM URL-ENCODED) -----------
|
||||
Map<String, String> responseMap = httpService.postFormRequest(BBPSConstant.UAT_PAYMENT_URL_WEB, formPayload);
|
||||
|
||||
LOGGER.info("[startWebPayment] Payment Start Response: {}", responseMap);
|
||||
LOGGER.info("[startWebPayment] Payment Start Response: {}", responseMap);
|
||||
|
||||
// parse http code and response body using centralized keys
|
||||
int httpCode = Integer.parseInt(responseMap.getOrDefault(BBPSConstant.RESP_CODE_KEY, String.valueOf(BBPSConstant.HTTP_INTERNAL_SERVER_ERROR)));
|
||||
String respBody = responseMap.getOrDefault(BBPSConstant.RESPONSE_DATA_KEY, "");
|
||||
helper.updateOutboundLogResponse(outboundLog, respBody);
|
||||
LOGGER.debug("[startWebPayment] updated outbound log response txnId={} httpCode={}", txnId, httpCode);
|
||||
// parse http code and response body using centralized keys
|
||||
int httpCode = Integer.parseInt(responseMap.getOrDefault(BBPSConstant.RESP_CODE_KEY, String.valueOf(BBPSConstant.HTTP_INTERNAL_SERVER_ERROR)));
|
||||
String respBody = responseMap.getOrDefault(BBPSConstant.RESPONSE_DATA_KEY, "");
|
||||
helper.updateOutboundLogResponse(outboundLog, respBody);
|
||||
LOGGER.debug("[startWebPayment] updated outbound log response txnId={} httpCode={}", txnId, httpCode);
|
||||
|
||||
// ---- HTTP FAILURE ----
|
||||
if (httpCode != BBPSConstant.HTTP_OK_INT) {
|
||||
helper.updateInboundLogFailure(inboundLog, respBody, String.valueOf(httpCode));
|
||||
LOGGER.error("[startWebPayment] upstream HTTP error txnId={} httpCode={} body={}", txnId, httpCode, respBody);
|
||||
throw new CustomException("Upstream HTTP Error", BBPSConstant.FAILED_STR, httpCode, respBody);
|
||||
}
|
||||
// ---- HTTP FAILURE ----
|
||||
if (httpCode != BBPSConstant.HTTP_OK_INT) {
|
||||
helper.updateInboundLogFailure(inboundLog, respBody, String.valueOf(httpCode));
|
||||
LOGGER.error("[startWebPayment] upstream HTTP error txnId={} httpCode={} body={}", txnId, httpCode, respBody);
|
||||
paymentRecord.setTxnStatus(BBPSConstant.FAILED_STR);
|
||||
paymentStartRecordRepository.save(paymentRecord);
|
||||
throw new CustomException("Upstream HTTP Error", BBPSConstant.FAILED_STR, httpCode, respBody);
|
||||
}
|
||||
|
||||
// ---- EMPTY RESPONSE ----
|
||||
if (respBody == null || respBody.isEmpty()) {
|
||||
helper.updateInboundLogFailure(inboundLog, BBPSConstant.MSG_EMPTY_RESPONSE_PG, String.valueOf(BBPSConstant.HTTP_INTERNAL_SERVER_ERROR));
|
||||
LOGGER.error("[startWebPayment] empty response from PG txnId={}", txnId);
|
||||
throw new CustomException(BBPSConstant.MSG_EMPTY_RESPONSE_PG, BBPSConstant.FAILED_STR, BBPSConstant.HTTP_INTERNAL_SERVER_ERROR, null);
|
||||
}
|
||||
// ---- EMPTY RESPONSE ----
|
||||
if (respBody == null || respBody.isEmpty()) {
|
||||
helper.updateInboundLogFailure(inboundLog, BBPSConstant.MSG_EMPTY_RESPONSE_PG, String.valueOf(BBPSConstant.HTTP_INTERNAL_SERVER_ERROR));
|
||||
LOGGER.error("[startWebPayment] empty response from PG txnId={}", txnId);
|
||||
paymentRecord.setTxnStatus(BBPSConstant.FAILED_STR);
|
||||
paymentStartRecordRepository.save(paymentRecord);
|
||||
throw new CustomException(BBPSConstant.MSG_EMPTY_RESPONSE_PG, BBPSConstant.FAILED_STR, BBPSConstant.HTTP_INTERNAL_SERVER_ERROR, null);
|
||||
}
|
||||
|
||||
// PG RETURNS HTML → NO JSON PARSING REQUIRED
|
||||
helper.updateInboundLogSuccess(inboundLog, respBody, String.valueOf(BBPSConstant.HTTP_OK_INT));
|
||||
LOGGER.info("[startWebPayment] received HTML response txnId={} length={}", txnId, respBody.length());
|
||||
// PG RETURNS HTML → NO JSON PARSING REQUIRED
|
||||
helper.updateInboundLogSuccess(inboundLog, respBody, String.valueOf(BBPSConstant.HTTP_OK_INT));
|
||||
LOGGER.info("[startWebPayment] received HTML response txnId={} length={}", txnId, respBody.length());
|
||||
|
||||
// Save record with HTML (persist original request and HTML response)
|
||||
// Save record with HTML (persist original request and HTML response)
|
||||
String responseTypeWeb = BBPSConstant.RESPONSE_TYPE_HTML;
|
||||
String rawResponseWeb = respBody == null ? "" : respBody;
|
||||
|
||||
@@ -291,8 +301,8 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
Map<String, String> parsed = parseHtmlResponse(rawResponseWeb);
|
||||
|
||||
// Build a minimal PaymentStartApiResponse so savePaymentStartRecord() can safely read fields
|
||||
com.billpaymentservice.bbps.dto.response.PaymentStartApiResponse apiResp = new com.billpaymentservice.bbps.dto.response.PaymentStartApiResponse();
|
||||
com.billpaymentservice.bbps.dto.response.PaymentStartApiResponse.ResponseData rd = new com.billpaymentservice.bbps.dto.response.PaymentStartApiResponse.ResponseData();
|
||||
PaymentStartApiResponse apiResp = new PaymentStartApiResponse();
|
||||
PaymentStartApiResponse.ResponseData rd = new PaymentStartApiResponse.ResponseData();
|
||||
|
||||
String parsedTxn = parsed.getOrDefault("txnId", "");
|
||||
String parsedAmount = parsed.getOrDefault("amount", "0.00");
|
||||
@@ -353,14 +363,8 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
|
||||
LOGGER.info("[{}] Decrypted data for mid={}", apiName, mid);
|
||||
|
||||
// Parse decrypted JSON
|
||||
Map<String, Object> payloadMap;
|
||||
try {
|
||||
payloadMap = objectMapper.readValue(decrypted, new TypeReference<Map<String, Object>>(){});
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("[{}] Failed to parse decrypted callback JSON: {}", apiName, e.getMessage(), e);
|
||||
return new ResponseModel(BBPSConstant.MSG_INVALID_DECRYPTED_JSON, String.valueOf(BBPSConstant.STATUS_CODE_207), BBPSConstant.HTTP_OK_INT, null);
|
||||
}
|
||||
// Parse decrypted JSON (convert checked Jackson exception into unchecked CustomException so global handler can catch it)
|
||||
Map<String, Object> payloadMap = parseJsonToMap(decrypted, apiName);
|
||||
|
||||
String txnId = String.valueOf(payloadMap.getOrDefault("txnId", payloadMap.getOrDefault("txn_id", "")));
|
||||
String orderNo = String.valueOf(payloadMap.getOrDefault("orderNo", payloadMap.getOrDefault("order_no", "")));
|
||||
@@ -402,7 +406,7 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
record.setSignature(signature);
|
||||
// update txn status and callback timestamp
|
||||
record.setTxnStatus(txnStatus);
|
||||
record.setCallbackReceivedOn(java.time.LocalDateTime.now().toString());
|
||||
record.setCallbackReceivedOn(LocalDateTime.now().toString());
|
||||
|
||||
String merchantStatus;
|
||||
if (!signatureMatches) {
|
||||
@@ -437,30 +441,44 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
||||
return new ResponseModel(BBPSConstant.MSG_CALLBACK_PROCESSED, merchantStatus, BBPSConstant.HTTP_OK_INT, null);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> parseHtmlResponse(String html) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
try {
|
||||
Document doc = Jsoup.parse(html);
|
||||
Document doc = Jsoup.parse(html);
|
||||
|
||||
Element txnId = doc.selectFirst("input[name=txnId]");
|
||||
Element amount = doc.selectFirst("input[name=amount]");
|
||||
Element mid = doc.selectFirst("input[name=mid]");
|
||||
Element txnId = doc.selectFirst("input[name=txnId]");
|
||||
Element amount = doc.selectFirst("input[name=amount]");
|
||||
Element mid = doc.selectFirst("input[name=mid]");
|
||||
|
||||
if (txnId != null) map.put("txnId", txnId.attr("value"));
|
||||
if (amount != null) map.put("amount", amount.attr("value"));
|
||||
if (mid != null) map.put("mid", mid.attr("value"));
|
||||
if (txnId != null) map.put("txnId", txnId.attr("value"));
|
||||
if (amount != null) map.put("amount", amount.attr("value"));
|
||||
if (mid != null) map.put("mid", mid.attr("value"));
|
||||
|
||||
LOGGER.debug("[parseHtmlResponse] parsed txnId={} amount={} mid={}", map.get("txnId"), map.get("amount"), map.get("mid"));
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("[parseHtmlResponse] error parsing HTML: {}", e.getMessage(), e);
|
||||
}
|
||||
LOGGER.debug("[parseHtmlResponse] parsed txnId={} amount={} mid={}", map.get("txnId"), map.get("amount"), map.get("mid"));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
// Helper: parse JSON string into Map and rethrow Jackson checked exceptions as CustomException (unchecked)
|
||||
private Map<String, Object> parseJsonToMap(String json, String apiName) {
|
||||
if (json == null || json.trim().isEmpty()) {
|
||||
LOGGER.error("[{}] Decrypted callback JSON is empty or null (length={})", apiName, json == null ? 0 : json.length());
|
||||
throw new CustomException(BBPSConstant.MSG_INVALID_DECRYPTED_JSON, BBPSConstant.FAILED_STR, BBPSConstant.HTTP_INTERNAL_SERVER_ERROR, json);
|
||||
}
|
||||
|
||||
// Log a short preview (avoid full sensitive data in logs)
|
||||
int previewLen = Math.min(120, json.length());
|
||||
String preview = json.substring(0, previewLen) + (json.length() > previewLen ? "..." : "");
|
||||
LOGGER.debug("[{}] parsing decrypted JSON preview (len={}): {}", apiName, json.length(), preview);
|
||||
|
||||
try {
|
||||
return objectMapper.readValue(json, new TypeReference<Map<String, Object>>(){});
|
||||
} catch (Exception e) {
|
||||
// Jackson throws JsonProcessingException / IOException; catch any parsing error and rethrow as unchecked
|
||||
LOGGER.error("[{}] Failed to parse decrypted callback JSON (len={}) error={}", apiName, json.length(), e.getMessage(), e);
|
||||
throw new CustomException(BBPSConstant.MSG_INVALID_DECRYPTED_JSON, BBPSConstant.FAILED_STR, BBPSConstant.HTTP_INTERNAL_SERVER_ERROR, json);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -23,7 +23,6 @@ public class PollBackServiceImpl implements PollBackService {
|
||||
this.helper = helper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseModel managePollBack(PollBackRequest request) {
|
||||
|
||||
|
||||
@@ -109,7 +109,6 @@ public class TxnHistoryServiceImpl implements TxnHistoryService {
|
||||
String mid = request.getMid();
|
||||
String clientUserId = request.getClientUserId();
|
||||
log.info("[{}] START | reqId={} | mid={} | userId={}", apiName, requestId, mid, clientUserId);
|
||||
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String fullUrl = "this api fetch data from DB not BBPS url !";
|
||||
log.info("[{}] Full URL={}", apiName, fullUrl);
|
||||
|
||||
Reference in New Issue
Block a user