added intent based pg

This commit is contained in:
Lincpay Tech
2025-12-01 17:10:06 +05:30
11 changed files with 274 additions and 6 deletions
@@ -21,6 +21,7 @@ import com.billpaymentservice.bbps.entites.UsersDetails;
import com.billpaymentservice.bbps.repository.UserRepository;
import com.billpaymentservice.bbps.repository.UsersDetailsRepository;
import com.billpaymentservice.bbps.service.AuthService;
import com.billpaymentservice.bbps.util.BBPSConstant;
import com.billpaymentservice.bbps.util.Helper;
import com.billpaymentservice.bbps.util.OtpClient;
import java.util.Optional;
@@ -93,8 +94,13 @@ public class AuthServiceImpl implements AuthService {
return ResponseModel.builder().message("Login Success").status("Success").statusCode(200).data(authResp)
.build();
} else {
AuthResponses authResp = new AuthResponses("", "User Not Found", "Authentication failed", 401, null);
return ResponseModel.builder().message("User Not Found").status("Failure").statusCode(401)
LOGGER.warn("OTP verified successfully, but user not found for mobileNo: {}", mobileNo);
// AuthResponses authResp = new AuthResponses("", "User Not Found", "Authentication failed", 401, null);
AuthResponses authResp = new AuthResponses("", "User Not Found",
"OTP verified successfully, but user not found", BBPSConstant.OTP_VERIFIED_USER_NOT_FORUN,
null);
return ResponseModel.builder().message("OTP verified successfully, but user not found")
.status("Failure").statusCode(BBPSConstant.OTP_VERIFIED_USER_NOT_FORUN) // Not Found
.data(authResp).build();
}
@@ -0,0 +1,89 @@
package com.billpaymentservice.bbps.serviceImpl;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import com.billpaymentservice.bbps.dto.ResponseModel;
import com.billpaymentservice.bbps.dto.TransactionHistoryMasterDTO;
import com.billpaymentservice.bbps.dto.request.PaymentHistoryRequest;
import com.billpaymentservice.bbps.entites.InboundTraceLog;
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
import com.billpaymentservice.bbps.entites.TransactionMaster;
import com.billpaymentservice.bbps.exception.CustomException;
import com.billpaymentservice.bbps.repository.TransactionMasterRepository;
import com.billpaymentservice.bbps.service.TxnHistoryService;
import com.billpaymentservice.bbps.util.BBPSConstant;
import com.billpaymentservice.bbps.util.BillerMapperHelper;
import com.billpaymentservice.bbps.util.Helper;
import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
public class TxnHistoryServiceImpl implements TxnHistoryService {
private final Helper helper;
private final BillerMapperHelper mapperHelper;
private final TransactionMasterRepository transactionMasterRepository;
public TxnHistoryServiceImpl(Helper helper, BillerMapperHelper mapperHelper,
TransactionMasterRepository transactionMasterRepository) {
this.helper = helper;
this.mapperHelper = mapperHelper;
this.transactionMasterRepository = transactionMasterRepository;
}
@Override
public ResponseModel getPaymentHostoryDetails(PaymentHistoryRequest paymentHistoryRequest) {
String apiName = BBPSConstant.GET_PAYMENT_HISTORY;
String requestId = paymentHistoryRequest.getReqId();
String mid = paymentHistoryRequest.getMid();
String clientUserId = paymentHistoryRequest.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);
String requestJson = helper.convertObjectToJson(paymentHistoryRequest);
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, mid, BBPSConstant.HTTP_GET,
requestJson);
helper.validateMerchant(mid);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl,
BBPSConstant.HTTP_GET, null);
try {
List<TransactionMaster> dataResult = transactionMasterRepository.findByMidOrClientUserId(mid, clientUserId);
if (dataResult == null || dataResult.isEmpty()) {
log.info("[{}] Response Fetch From DB | reqId={} | data={}", apiName, requestId, dataResult);
throw new CustomException("No Transcation Found This Mid", "FAILED", BBPSConstant.BADREQUEST, null);
}
Integer responseData = dataResult.size();
log.info("[{}] Response Fetch From DB | reqId={} | data={}", apiName, requestId, responseData);
List<TransactionHistoryMasterDTO> responseDatas = dataResult.stream().map(mapperHelper::toDTO)
.collect(Collectors.toList());
helper.updateOutboundLogResponse(outboundLog, String.valueOf(responseData));
return new ResponseModel(BBPSConstant.ALL_MASTER_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE,
BBPSConstant.HTTP_OK_INT, responseDatas, responseDatas.size());
} catch (CustomException e) {
// Log and rethrow the custom exception
log.error("[{}] CustomException occurred: {}", apiName, e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.NO_BILL_FOUND);
throw e; // Propagate the exact CustomException
} catch (Exception e) {
log.error("JSON Parsing Error: {}", e.getMessage());
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
throw new CustomException("Invalid JSON received from API");
}
}
}