merged with himanshu code after bbps contant added
This commit is contained in:
@@ -2,16 +2,12 @@ package com.billpaymentservice.bbps.util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
<<<<<<< HEAD
|
||||
|
||||
import com.billpaymentservice.bbps.dto.AdditionalInfoBillDTO;
|
||||
import com.billpaymentservice.bbps.dto.CustomerParamDAO;
|
||||
@@ -31,17 +27,12 @@ import com.billpaymentservice.bbps.dto.sentRequest.FetchComplaintForwardRequest;
|
||||
import com.billpaymentservice.bbps.dto.sentRequest.FetchTicketLatestStatusRequest;
|
||||
import com.billpaymentservice.bbps.entites.AdditionalInfoBill;
|
||||
import com.billpaymentservice.bbps.entites.AdditionalInfoBillValidate;
|
||||
=======
|
||||
>>>>>>> d0812656ff2aee80b1eb0c0ab8e29a01d7d66553
|
||||
import com.billpaymentservice.bbps.entites.BBPSMastersData;
|
||||
import com.billpaymentservice.bbps.entites.BillMaster;
|
||||
import com.billpaymentservice.bbps.entites.BillValidation;
|
||||
import com.billpaymentservice.bbps.entites.BillerDetails;
|
||||
import com.billpaymentservice.bbps.entites.BillerResponse;
|
||||
import com.billpaymentservice.bbps.entites.CustomerParamBill;
|
||||
import com.billpaymentservice.bbps.entites.CustomerParamBillValidation;
|
||||
import com.billpaymentservice.bbps.entites.InboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.PaymentChannel;
|
||||
import com.billpaymentservice.bbps.entites.PaymentMode;
|
||||
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.BBPSMasterDataRepo;
|
||||
import com.billpaymentservice.bbps.repository.BillMasterRepository;
|
||||
@@ -61,14 +52,12 @@ public class Helper {
|
||||
private static final String CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
private static final SecureRandom secureRandom = new SecureRandom();
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final BBPSMasterDataRepo bbpsMasterDataRepo;
|
||||
private final BillerDataRepository billerDataRespository;
|
||||
private final BillMasterRepository billMasterRepository;
|
||||
private final BillValidationRepository billValidationRepository;
|
||||
|
||||
|
||||
// Constructor Injection
|
||||
public Helper(BBPSMasterDataRepo bbpsMasterDataRepo, InboundTraceLogRepository inboundTraceLogRepository,
|
||||
<<<<<<< HEAD
|
||||
OutboundTraceLogRepository outboundTraceLogRepository, BillerDataRepository billerDataRepository,
|
||||
BillMasterRepository billMasterRepository, BillValidationRepository billValidationRepository) {
|
||||
this.bbpsMasterDataRepo = bbpsMasterDataRepo;
|
||||
@@ -78,6 +67,13 @@ public class Helper {
|
||||
this.billMasterRepository = billMasterRepository;
|
||||
this.billValidationRepository = billValidationRepository;
|
||||
}
|
||||
=======
|
||||
OutboundTraceLogRepository outboundTraceLogRepository,BillerDataRepository billerDataRepository,
|
||||
BillMasterRepository billMasterRepository,BillValidationRepository billValidationRepository) {
|
||||
this.inboundTraceLogRepository = inboundTraceLogRepository;
|
||||
this.outboundTraceLogRepository = outboundTraceLogRepository;
|
||||
this.bbpsMasterDataRepo = bbpsMasterDataRepo;}
|
||||
>>>>>>> d0812656ff2aee80b1eb0c0ab8e29a01d7d66553
|
||||
|
||||
/**
|
||||
* Validates whether the merchant exists and is active.
|
||||
@@ -89,35 +85,6 @@ public class Helper {
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public <T> void startPolling(T requestObject, // Request object (any type)
|
||||
Function<T, ResponseModel> apiCallFunction, // Function to call API
|
||||
int intervalSeconds, // gap between two polls
|
||||
int maxDurationSeconds // total polling time
|
||||
) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
int maxAttempts = maxDurationSeconds / intervalSeconds;
|
||||
|
||||
for (int i = 0; i < maxAttempts; i++) {
|
||||
LOGGER.info("⏳ Polling attempt {}...", i + 1);
|
||||
|
||||
ResponseModel response = apiCallFunction.apply(requestObject);
|
||||
LOGGER.info("📥 Poll response: {}", response);
|
||||
|
||||
if ("SUCCESS".equalsIgnoreCase(response.getStatus())) {
|
||||
LOGGER.info("✅ Polling successful, stopping early.");
|
||||
break;
|
||||
}
|
||||
|
||||
Thread.sleep(intervalSeconds * 1000L);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("❌ Error in polling thread: {}", e.getMessage(), e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void validateMerchant(String mid) {
|
||||
if (mid == null || mid == "") {
|
||||
LOGGER.warn("MerchantRequestModel or MID is null");
|
||||
@@ -215,12 +182,15 @@ public class Helper {
|
||||
outboundLog.setResponsePayload(responsePayload);
|
||||
outboundLog.setResponseReceiveTime(LocalDateTime.now());
|
||||
outboundTraceLogRepository.save(outboundLog);
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> d0812656ff2aee80b1eb0c0ab8e29a01d7d66553
|
||||
}
|
||||
|
||||
/* ---------- End helpers ---------- */
|
||||
public void saveOrUpdateBillerData(BillerDetails newEntity) {
|
||||
|
||||
<<<<<<< HEAD
|
||||
Optional<BillerDetails> existingOpt = billerDataRespository.findByBillerId(newEntity.getBillerId());
|
||||
|
||||
if (existingOpt.isPresent()) {
|
||||
@@ -419,4 +389,18 @@ public class Helper {
|
||||
forward.setTxnNpciId(request.getTxnNpciId());
|
||||
return forward;
|
||||
}
|
||||
=======
|
||||
// New reusable header builder for BBPS calls
|
||||
public HttpHeaders buildHeaders(BharatConnectMaster headersData) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
if (headersData != null) {
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
}
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
return headers;
|
||||
}
|
||||
|
||||
>>>>>>> d0812656ff2aee80b1eb0c0ab8e29a01d7d66553
|
||||
}
|
||||
Reference in New Issue
Block a user