Merge branch 'develop' into feature/callbackpaymentintent

This commit is contained in:
Lincpay Tech
2025-12-03 11:41:44 +05:30
8 changed files with 103 additions and 11 deletions
@@ -76,4 +76,10 @@ public class ComplainController {
ResponseModel response = complainService.ViewAllComplaints(request);
return ResponseEntity.ok(response);
}
@PostMapping(value = "/viewAllComplaintsByUserId", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ResponseModel> viewAllComplaintsByUserId(@Validated @RequestBody AllMasterOptionsRequest request) {
ResponseModel response = complainService.viewAllComplaintsByUserId(request);
return ResponseEntity.ok(response);
}
}
@@ -63,4 +63,7 @@ public class ComplaintResponseEntity extends Auditable<String> {
@Column(name = "txn_id")
private String txnId;
@Column(name = "user_id")
private String userId;
}
@@ -1,6 +1,10 @@
package com.billpaymentservice.bbps.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.billpaymentservice.bbps.entites.ComplaintResponseEntity;
@@ -8,4 +12,6 @@ import com.billpaymentservice.bbps.entites.ComplaintResponseEntity;
@Repository
public interface ComplaintResponseRepository extends JpaRepository<ComplaintResponseEntity, Long> {
@Query("SELECT c FROM ComplaintResponseEntity c WHERE c.userId = :userId")
List<ComplaintResponseEntity> findByUserIdCustom(@Param("userId") String userId);
}
@@ -28,4 +28,6 @@ public interface ComplainService {
ResponseModel ViewAllComplaints(ViewAllComplaintsTicketsRequest request);
ResponseModel viewAllComplaintsByUserId(AllMasterOptionsRequest request);
}
@@ -29,6 +29,7 @@ import com.billpaymentservice.bbps.dto.response.ViewComplainByIdResponse;
import com.billpaymentservice.bbps.dto.sentRequest.FetchComplaintForwardRequest;
import com.billpaymentservice.bbps.dto.sentRequest.FetchTicketLatestStatusRequest;
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
import com.billpaymentservice.bbps.entites.ComplaintResponseEntity;
import com.billpaymentservice.bbps.entites.ComplaintStatusOptionsMaster;
import com.billpaymentservice.bbps.entites.InboundTraceLog;
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
@@ -37,6 +38,7 @@ import com.billpaymentservice.bbps.exception.CustomException;
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
import com.billpaymentservice.bbps.repository.ComplainRepository;
import com.billpaymentservice.bbps.repository.ComplaintOptionsStatusMasterRepository;
import com.billpaymentservice.bbps.repository.ComplaintResponseRepository;
import com.billpaymentservice.bbps.repository.TransactionMasterRepository;
import com.billpaymentservice.bbps.service.ComplainService;
import com.billpaymentservice.bbps.util.BBPSConstant;
@@ -65,6 +67,7 @@ public class ComplainServiceImpl implements ComplainService {
private final ComplainRepository complainRepository;
private final ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository;
private final TransactionMasterRepository transactionMasterRepository;
private final ComplaintResponseRepository complaintResponseRepository;
// moved to class-level
private final ObjectMapper objectMapper;
@@ -74,7 +77,8 @@ public class ComplainServiceImpl implements ComplainService {
BharatConnectMasterRepository beneficiaryDetailsRepository, BillerMapperHelper mapperHelper,
ComplainRepository complainRepository,
ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository,
TransactionMasterRepository transactionMasterRepository) {
TransactionMasterRepository transactionMasterRepository,
ComplaintResponseRepository complaintResponseRepository) {
this.restClient = restClient;
this.httpService = httpService;
this.helper = helper;
@@ -86,6 +90,7 @@ public class ComplainServiceImpl implements ComplainService {
// initialize shared ObjectMapper once
this.objectMapper = new ObjectMapper();
this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
this.complaintResponseRepository = complaintResponseRepository;
}
@Override
@@ -94,7 +99,8 @@ public class ComplainServiceImpl implements ComplainService {
String apiName = BBPSConstant.API_ADD_COMPLAIN;
String requestId = complainRequestDTO.getReqId();
String mid = complainRequestDTO.getMid();
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid);
String userId = complainRequestDTO.getClientUserId();
LOGGER.info("[{}] START | reqId={} | mid={} | clientUserId={}", apiName, requestId, mid, userId);
String txnId = helper.generateTxnId(15);
String fullUrl = complainDataUrl + BBPSConstant.ADD_COMPLAIN_ENDPOINT;
@@ -186,7 +192,7 @@ public class ComplainServiceImpl implements ComplainService {
ComplaintResponse responseWrapper = objectMapper.convertValue(dataMap, ComplaintResponse.class);
String saveComplaintResponseEntity = mapperHelper.saveComplaintResponseEntity(responseWrapper, requestId,
txnId);
txnId, userId);
LOGGER.info("Save Complaint Response Count" + saveComplaintResponseEntity);
ResponseModel responseModel = new ResponseModel(responseWrapper.getMessage(), responseWrapper.getStatus(),
Integer.parseInt(responseWrapper.getStatusCode()), responseWrapper);
@@ -543,7 +549,7 @@ public class ComplainServiceImpl implements ComplainService {
String requestJson = helper.convertObjectToJson(request);
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(),
BBPSConstant.HTTP_POST, requestJson);
BBPSConstant.HTTP_GET, requestJson);
helper.validateMerchant(request.getMid());
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
HttpHeaders headers = helper.buildHeaders(headersData);
@@ -592,4 +598,69 @@ public class ComplainServiceImpl implements ComplainService {
}
}
@Override
public ResponseModel viewAllComplaintsByUserId(AllMasterOptionsRequest request) {
String apiName = BBPSConstant.API_VIEW_ALL_COMPLAINTS_BY_USER_ID;
String reqId = request.getReqId();
String mid = request.getMid();
String userId = request.getClientUserId();
LOGGER.info("[{}] START | reqId={} | mid={} | userId={}", apiName, reqId, mid, userId);
String txnId = helper.generateTxnId(15);
String requestJson = helper.convertObjectToJson(request);
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, mid, BBPSConstant.HTTP_GET,
requestJson);
helper.validateMerchant(mid); // Validate merchant before continuing
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
HttpHeaders headers = helper.buildHeaders(headersData);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, apiName, BBPSConstant.HTTP_GET,
requestJson);
LOGGER.debug("Outbound log created successfully for Complaint: {}", apiName);
try {
// Validate userId
if (userId.isEmpty() || userId == null) {
helper.updateOutboundLogResponse(outboundLog, BBPSConstant.USER_ID_IS_EMPTY);
return new ResponseModel(BBPSConstant.USER_ID_IS_EMPTY, "User ID cannot be null or empty", // Provide a
BBPSConstant.BADREQUEST, null, 0 // Return 0 as the size when no complaints
);
}
// Log the call to external API
LOGGER.info("[{}] Calling external API | URL={}", apiName, apiName);
List<ComplaintResponseEntity> complaintUserData = complaintResponseRepository.findByUserIdCustom(userId);
// Check if complaints were found
if (complaintUserData == null || complaintUserData.isEmpty()) {
LOGGER.info("[{}] No complaints found for userId={}", apiName, userId);
throw new CustomException("No complaints found for this User ID", "FAILED", BBPSConstant.BADREQUEST,
null);
}
// Log the number of complaints fetched
LOGGER.info("[{}] Complaints found for userId={} | count={}", apiName, userId, complaintUserData.size());
// Update outbound log with the count
String count = String.valueOf(complaintUserData.size());
helper.updateOutboundLogResponse(outboundLog, count);
// Return successful response with complaints data
return new ResponseModel(BBPSConstant.ALL_COMPLAINT_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE,
BBPSConstant.HTTP_OK_INT, complaintUserData, complaintUserData.size());
} catch (CustomException e) {
// Rethrow custom exception for handling at the controller level
throw e;
} catch (Exception e) {
// Log generic exception and create inbound log failure
LOGGER.error("[{}] Error: {}", apiName, e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
throw new CustomException("An error occurred while processing the request");
}
}
}
@@ -220,7 +220,7 @@ public class MasterDataServiceImpl implements MasterDataService {
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
BillerDetails entity = mapper.map(responseWrapper.getBillerDAO(), BillerDetails.class);
EntityRelationshipUtil.linkBillerRelationships(entity);// linking nesting entity foreign key
mapperHelper.saveOrUpdateBillerData(entity);
//mapperHelper.saveOrUpdateBillerData(entity);
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
@@ -96,6 +96,7 @@ public class BBPSConstant {
public static final String API_GET_ALL_MASTER_OPTIONS = "View All Options Fetch By Id";
public static final String API_CHECK_TXN_STATUS = "CheckTxnStatus";
public static final String API_VIEW_ALL_COMPLAINTS_BY_STATUS = "View_All_Complaint_By_Status_Type";
public static final String API_VIEW_ALL_COMPLAINTS_BY_USER_ID = "View_All_Complaint_By_USER_ID";
// API names used by MasterDataServiceImpl
public static final String API_GET_MASTER_DATA = "GetMasterData";
@@ -145,15 +146,17 @@ public class BBPSConstant {
public static final String NULL_DATA_FROM_DB = "NULL_DATA_FROM_DB";
public static final String NO_MASTER_FIELDS_FOUND = "No master fields found";
public static final String ALL_MASTER_FIELDS_FETCH = "All master fields fetched successfully";
public static final String ALL_COMPLAINT_FIELDS_FETCH = "All complaint fields fetched successfully";
public static final String SOMETHING_WENT_WRONG = "Something went wrong";
public static final String USER_ID_IS_EMPTY = "User id is empty";
// Timing/delay constants (milliseconds)
public static final long BILL_FETCH_DELAY_MS = 5000L; // used after initiate bill fetch
public static final long BILL_VALIDATE_DELAY_MS = 12000L; // used after initiate bill validate
public static final long PAYMENT_STATUS_DELAY_MS = 9000L; // used after initiate payment
public static final String enckey="zk52olsyr9fl95h50eus8bhtyhoo5lp7";
public static final String mid="Test-By-Aditya-1001";
public static final String callbackurl= "https://checkout.solwio.in/PGPayU/payu/callback";
public static final String companyName= "techwork technology";
public static final String enckey = "zk52olsyr9fl95h50eus8bhtyhoo5lp7";
public static final String mid = "Test-By-Aditya-1001";
public static final String callbackurl = "https://checkout.solwio.in/PGPayU/payu/callback";
public static final String companyName = "techwork technology";
}
@@ -1198,7 +1198,7 @@ public class BillerMapperHelper {
}
}
public String saveComplaintResponseEntity(ComplaintResponse responseWrapper, String requestId, String txnId) {
public String saveComplaintResponseEntity(ComplaintResponse responseWrapper, String requestId, String txnId,String userId) {
// 1. Convert ComplaintResponse DTO to ComplaintResponseEntity
ComplaintResponseEntity complaintResponseEntity = new ComplaintResponseEntity();
@@ -1222,6 +1222,7 @@ public class BillerMapperHelper {
// Set requestId and txnId from parameters
complaintResponseEntity.setReqId(requestId);
complaintResponseEntity.setTxnId(txnId);
complaintResponseEntity.setUserId(userId);
complaintResponseEntity.setCreateDateTime(new Date());
// If you need a separate complaintTicketId, you can set it here
complaintResponseEntity.setComplaintTicketId(generateComplaintTicketId()); // Generate or set manually