666 lines
30 KiB
Java
666 lines
30 KiB
Java
// java
|
|
package com.billpaymentservice.bbps.serviceImpl;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import org.modelmapper.ModelMapper;
|
|
import org.modelmapper.convention.MatchingStrategies;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import com.billpaymentservice.bbps.dto.GeneralResp;
|
|
import com.billpaymentservice.bbps.dto.MasterApiResponse;
|
|
import com.billpaymentservice.bbps.dto.ResponseModel;
|
|
import com.billpaymentservice.bbps.dto.request.BillerDetailRequest;
|
|
import com.billpaymentservice.bbps.dto.request.ContactMasterRequest;
|
|
import com.billpaymentservice.bbps.dto.request.CustomParamRequest;
|
|
import com.billpaymentservice.bbps.dto.request.DispositionRequest;
|
|
import com.billpaymentservice.bbps.dto.request.MasterCategoryRequest;
|
|
import com.billpaymentservice.bbps.dto.request.MasterRequest;
|
|
import com.billpaymentservice.bbps.dto.response.AmountOptionsResponse;
|
|
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
|
|
import com.billpaymentservice.bbps.dto.response.BillerResponse;
|
|
import com.billpaymentservice.bbps.dto.response.ChannelsListResponse;
|
|
import com.billpaymentservice.bbps.dto.response.CustomParamResp;
|
|
import com.billpaymentservice.bbps.dto.response.CustomerParamGroupsResponse;
|
|
import com.billpaymentservice.bbps.dto.response.DispositionResponse;
|
|
import com.billpaymentservice.bbps.dto.response.PlaneCategoriesResponse;
|
|
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
|
|
import com.billpaymentservice.bbps.entites.BillerDetails;
|
|
import com.billpaymentservice.bbps.entites.DispositionDetails;
|
|
import com.billpaymentservice.bbps.entites.InboundTraceLog;
|
|
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
|
|
import com.billpaymentservice.bbps.exception.CustomException;
|
|
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
|
|
import com.billpaymentservice.bbps.repository.BillerDataRepository;
|
|
import com.billpaymentservice.bbps.repository.DispositionRepository;
|
|
import com.billpaymentservice.bbps.repository.InboundTraceLogRepository;
|
|
import com.billpaymentservice.bbps.repository.MerchantRepository;
|
|
import com.billpaymentservice.bbps.repository.OutboundTraceLogRepository;
|
|
import com.billpaymentservice.bbps.service.MasterDataService;
|
|
import com.billpaymentservice.bbps.util.BBPSConstant;
|
|
import com.billpaymentservice.bbps.util.EntityRelationshipUtil;
|
|
import com.billpaymentservice.bbps.util.Helper;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
@Service
|
|
public class MasterDataServiceImpl implements MasterDataService {
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(MasterDataServiceImpl.class);
|
|
|
|
@Value("${master.data.url}")
|
|
private String masterRegisterUrl;
|
|
private final BharatConnectMasterRepository beneficiaryDetailsRepository;
|
|
|
|
private MerchantRepository merchantRegisterRepo;
|
|
private HttpClientApi httpClientApi;
|
|
private final DispositionRepository dispositionRepository;
|
|
private final Helper helper;
|
|
private final BillerDataRepository billerDataRespository;
|
|
private static final Logger log = LoggerFactory.getLogger(MasterDataServiceImpl.class);
|
|
private final HttpService httpService;
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
private final InboundTraceLogRepository inboundTraceLogRepository;
|
|
private final OutboundTraceLogRepository outboundTraceLogRepository;
|
|
|
|
|
|
public MasterDataServiceImpl(MerchantRepository merchantRegisterRepo, HttpService httpService,
|
|
HttpClientApi httpClientApi, Helper helper, BillerDataRepository billerDataRespository,
|
|
DispositionRepository dispositionRepository, BharatConnectMasterRepository beneficiaryDetailsRepository,
|
|
InboundTraceLogRepository inboundTraceLogRepository,
|
|
OutboundTraceLogRepository outboundTraceLogRepository) {
|
|
this.merchantRegisterRepo = merchantRegisterRepo;
|
|
this.httpService = httpService;
|
|
this.httpClientApi = httpClientApi;
|
|
this.helper = helper;
|
|
this.billerDataRespository = billerDataRespository;
|
|
this.dispositionRepository = dispositionRepository;
|
|
this.beneficiaryDetailsRepository = beneficiaryDetailsRepository;
|
|
this.inboundTraceLogRepository = inboundTraceLogRepository;
|
|
this.outboundTraceLogRepository = outboundTraceLogRepository;
|
|
|
|
}
|
|
|
|
/* ---------- Trace helper methods ---------- */
|
|
private InboundTraceLog createInboundLog(String requestId, String txnId, String apiName, String mid, String httpMethod, String requestPayload) {
|
|
InboundTraceLog inboundLog = new InboundTraceLog(requestId, txnId, apiName, mid == null ? "N/A" : mid, "BBPS_ORG", httpMethod, requestPayload == null ? "N/A" : requestPayload);
|
|
inboundTraceLogRepository.save(inboundLog);
|
|
return inboundLog;
|
|
}
|
|
|
|
private void updateInboundLogSuccess(InboundTraceLog inboundLog, String responsePayload, String responseCode) {
|
|
if (inboundLog == null) return;
|
|
inboundLog.setResponsePayload(responsePayload);
|
|
inboundLog.setResponseCode(responseCode);
|
|
inboundLog.setStatus("SUCCESS");
|
|
inboundLog.setResponseTime(LocalDateTime.now());
|
|
inboundTraceLogRepository.save(inboundLog);
|
|
}
|
|
|
|
private void updateInboundLogFailure(InboundTraceLog inboundLog, String responsePayload, String responseCode) {
|
|
if (inboundLog == null) return;
|
|
inboundLog.setResponsePayload(responsePayload);
|
|
inboundLog.setResponseCode(responseCode);
|
|
inboundLog.setStatus("FAILED");
|
|
inboundLog.setResponseTime(LocalDateTime.now());
|
|
inboundTraceLogRepository.save(inboundLog);
|
|
}
|
|
|
|
private OutboundTraceLog createOutboundLog(String txnId, String requestId, String apiName, String url, String httpMethod, String requestPayload) {
|
|
OutboundTraceLog outboundLog = new OutboundTraceLog(txnId, requestId, apiName, url, httpMethod, requestPayload == null ? "N/A" : requestPayload);
|
|
outboundTraceLogRepository.save(outboundLog);
|
|
return outboundLog;
|
|
}
|
|
|
|
private void updateOutboundLogResponse(OutboundTraceLog outboundLog, String responsePayload) {
|
|
if (outboundLog == null) return;
|
|
outboundLog.setResponsePayload(responsePayload);
|
|
outboundLog.setResponseReceiveTime(LocalDateTime.now());
|
|
outboundTraceLogRepository.save(outboundLog);
|
|
}
|
|
|
|
/* ---------- End helpers ---------- */
|
|
|
|
@Override
|
|
public ResponseModel getMasterData(MasterRequest masterRequest) {
|
|
LOGGER.info("Request DTO: {}", masterRequest);
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "GetMasterData";
|
|
String requestId =masterRequest.getReqId();
|
|
String requestJson = helper.convertObjectToJson(masterRequest);
|
|
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, masterRequest.getMid(), "POST", requestJson);
|
|
|
|
try {
|
|
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
|
log.info("ResPONSE" + headersData);
|
|
if (headersData == null) {
|
|
updateInboundLogFailure(inboundLog, "Tenant Id Is Null", "NOT_FOUND");
|
|
return new ResponseModel("Tenant Id Is Null", "Not Found",
|
|
BBPSConstant.BADREQUEST, headersData);
|
|
}
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.MASTER_CATEGORY_URL + headersData.getTenantId();
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get("data");
|
|
LOGGER.info("Response Data: {}", responseData);
|
|
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
throw new CustomException(String.valueOf(dataMap.get("message")), // message
|
|
String.valueOf(dataMap.get("status")), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode
|
|
String.valueOf(dataMap.get("remarks")) // remarks
|
|
);
|
|
}
|
|
|
|
MasterApiResponse responseWrapper = objectMapper.convertValue(dataMap, MasterApiResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "GetBillerByBillerId";
|
|
String requestId = billerDetailRequest.getReqId();
|
|
String billerId = billerDetailRequest.getBillerId();
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL + billerId;
|
|
|
|
String requestJson = helper.convertObjectToJson(billerDetailRequest);
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, billerDetailRequest.getMid(), "POST", requestJson);
|
|
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get("data");
|
|
log.info("data is :{}", responseData);
|
|
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
try {
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {});
|
|
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
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"))
|
|
);
|
|
}
|
|
|
|
BillerDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillerDataResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ModelMapper mapper = new ModelMapper();
|
|
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
|
|
BillerDetails entity = mapper.map(responseWrapper.getBillerDAO(), BillerDetails.class);
|
|
EntityRelationshipUtil.linkBillerRelationships(entity);
|
|
|
|
ResponseModel responseModel = new ResponseModel(
|
|
generalResp.getMessage(),
|
|
generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()),
|
|
responseWrapper
|
|
);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getCustomerParamByBillerId(CustomParamRequest customerParamRequest) {
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "GetCustomerParamByBillerId";
|
|
String requestId = customerParamRequest.getReqId();
|
|
String requestJson = helper.convertObjectToJson(customerParamRequest);
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName,customerParamRequest.getMid(), "POST", requestJson);
|
|
|
|
try {
|
|
|
|
String billerId = customerParamRequest.getBillerId();
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMPARAM_URL + billerId;
|
|
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get("data");
|
|
log.info("data is :{}", responseData);
|
|
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
throw new CustomException(String.valueOf(dataMap.get("message")), // message
|
|
String.valueOf(dataMap.get("status")), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
|
|
String.valueOf(dataMap.get("remarks")));
|
|
}
|
|
|
|
CustomParamResp responseWrapper = objectMapper.convertValue(dataMap, CustomParamResp.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getContactMaster(ContactMasterRequest contactMasterRequest) {
|
|
/*
|
|
* String txnID = helper.generateTxnId(15); String apiName = "GetContactMaster";
|
|
* String requestId = contactMasterRequest != null ?
|
|
* contactMasterRequest.getReqId() : "N/A"; String requestJson =
|
|
* helper.convertObjectToJson(contactMasterRequest); InboundTraceLog inboundLog
|
|
* = createInboundLog(requestId, txnID, apiName, contactMasterRequest != null ?
|
|
* contactMasterRequest.getMid() : "N/A", "POST", requestJson);
|
|
*
|
|
* // Implementation not present previously - create inbound log and return
|
|
* empty response updateInboundLogSuccess(inboundLog, "N/A", "SUCCESS");
|
|
*/
|
|
return new ResponseModel();
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchMasterDataCategoryWise(MasterCategoryRequest masterRequest) {
|
|
LOGGER.info("Fetching Master Data Category-wise " + masterRequest);
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "FetchMasterDataCategoryWise";
|
|
String requestId = masterRequest.getReqId();
|
|
String requestJson = helper.convertObjectToJson(masterRequest);
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName,masterRequest.getMid(), "POST", requestJson);
|
|
|
|
try {
|
|
|
|
String validateMerchant = helper.validateMerchant(masterRequest);
|
|
|
|
if (!"Valid".equalsIgnoreCase(validateMerchant)) {
|
|
LOGGER.warn("Merchant validation failed: {}", validateMerchant);
|
|
updateInboundLogFailure(inboundLog, validateMerchant, "INVALID_MERCHANT");
|
|
return new ResponseModel("Merchant validation failed", validateMerchant, BBPSConstant.BADREQUEST, null);
|
|
}
|
|
|
|
String fullUrl = String.format("%s%s?billerName=%s&category=%s&page=%d&pagesize=%d", masterRegisterUrl,
|
|
BBPSConstant.BILLER_URL, masterRequest.getBillerName(), masterRequest.getCategory(),
|
|
masterRequest.getPageStart(), masterRequest.getPageEnd());
|
|
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get("data");
|
|
LOGGER.info("Response Data: {}", responseData);
|
|
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
throw new CustomException(String.valueOf(dataMap.get("message")), // message
|
|
String.valueOf(dataMap.get("status")), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode
|
|
String.valueOf(dataMap.get("remarks")) // remarks
|
|
);
|
|
}
|
|
|
|
BillerResponse responseWrapper = objectMapper.convertValue(dataMap, BillerResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getDispositionDetails(DispositionRequest dispositionDetailRequest) {
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "GetDispositionDetails";
|
|
String requestId = dispositionDetailRequest.getReqId();;
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName,dispositionDetailRequest.getMid() , "GET", "N/A");
|
|
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.DISPOSTION_URL;
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get("data");
|
|
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
try {
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
throw new CustomException(String.valueOf(dataMap.get("message")), // message
|
|
String.valueOf(dataMap.get("status")), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
|
|
String.valueOf(dataMap.get("remarks")));
|
|
}
|
|
|
|
DispositionResponse responseWrapper = objectMapper.convertValue(dataMap, DispositionResponse.class);
|
|
System.out.println(responseWrapper);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
ModelMapper mapper = new ModelMapper();
|
|
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
|
|
List<DispositionDetails> entities = responseWrapper.getDispositionsList().stream()
|
|
.map(dto -> mapper.map(dto, DispositionDetails.class)).collect(Collectors.toList());
|
|
|
|
System.out.println(entities);
|
|
|
|
if (entities != null) {
|
|
dispositionRepository.saveAll(entities);
|
|
} else {
|
|
LOGGER.warn("No disposition found in response to save.");
|
|
}
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchCustomerParamGroup(BillerDetailRequest requestModel) {
|
|
LOGGER.info("Fetching Master Data Category-wise for MID={}", requestModel.getMid());
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "FetchCustomerParamGroup";
|
|
String requestId = requestModel.getReqId();
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName,requestModel.getMid() , "POST", helper.convertObjectToJson(requestModel));
|
|
|
|
try {
|
|
|
|
String validateMerchant = helper.validateMerchant(requestModel);
|
|
|
|
if (!"Valid".equalsIgnoreCase(validateMerchant)) {
|
|
LOGGER.warn("Merchant validation failed: {}", validateMerchant);
|
|
updateInboundLogFailure(inboundLog, validateMerchant, "INVALID_MERCHANT");
|
|
return new ResponseModel("Merchant validation failed", validateMerchant, BBPSConstant.BADREQUEST, null);
|
|
}
|
|
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMER_PARAM_GROUP + requestModel.getBillerId();
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
|
|
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
|
String responseData = apiResponse.get("data").toString();
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
throw new CustomException(String.valueOf(dataMap.get("message")), // message
|
|
String.valueOf(dataMap.get("status")), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
|
|
String.valueOf(dataMap.get("remarks")));
|
|
}
|
|
|
|
CustomerParamGroupsResponse responseWrapper = objectMapper.convertValue(dataMap,
|
|
CustomerParamGroupsResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchAllMasterAmountOption(BillerDetailRequest requestModel) {
|
|
LOGGER.info("Fetching Master Data Amount List for MID={}", requestModel.getMid());
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "FetchAllMasterAmountOption";
|
|
String requestId = requestModel.getReqId();
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", helper.convertObjectToJson(requestModel));
|
|
|
|
try {
|
|
String validateMerchant = helper.validateMerchant(requestModel);
|
|
|
|
if (!"Valid".equalsIgnoreCase(validateMerchant)) {
|
|
LOGGER.warn("Merchant validation failed: {}", validateMerchant);
|
|
updateInboundLogFailure(inboundLog, validateMerchant, "INVALID_MERCHANT");
|
|
return new ResponseModel("Merchant validation failed", validateMerchant, BBPSConstant.BADREQUEST, null);
|
|
}
|
|
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.AMOUNT_OPTIONS + requestModel.getBillerId();
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
|
|
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
|
log.info("Response" + apiResponse);
|
|
String responseData = apiResponse.get("data").toString();
|
|
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
throw new CustomException(String.valueOf(dataMap.get("message")), // message
|
|
String.valueOf(dataMap.get("status")), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
|
|
String.valueOf(dataMap.get("remarks")));
|
|
}
|
|
|
|
AmountOptionsResponse responseWrapper = objectMapper.convertValue(dataMap, AmountOptionsResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
} catch (CustomException e) {
|
|
LOGGER.error("Custom Exception: {}", e.getMessage());
|
|
throw e; // Rethrow custom exceptions to be handled by the controller
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchPlanCategorie(BillerDetailRequest requestModel) {
|
|
LOGGER.info("Fetching Master Data Amount List for MID={}", requestModel.getMid());
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "FetchPlanCategorie";
|
|
String requestId = requestModel.getReqId();
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, requestModel.getMid() , "POST", helper.convertObjectToJson(requestModel));
|
|
|
|
try {
|
|
String validateMerchant = helper.validateMerchant(requestModel);
|
|
|
|
if (!"Valid".equalsIgnoreCase(validateMerchant)) {
|
|
LOGGER.warn("Merchant validation failed: {}", validateMerchant);
|
|
updateInboundLogFailure(inboundLog, validateMerchant, "INVALID_MERCHANT");
|
|
return new ResponseModel("Merchant validation failed", validateMerchant, BBPSConstant.BADREQUEST, null);
|
|
}
|
|
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.PLAN_CATEGORIES + requestModel.getBillerId();
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
|
|
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
|
log.info("Response" + apiResponse);
|
|
String responseData = apiResponse.get("data").toString();
|
|
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
throw new CustomException(String.valueOf(dataMap.get("message")), // message
|
|
String.valueOf(dataMap.get("status")), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
|
|
String.valueOf(dataMap.get("remarks")));
|
|
}
|
|
|
|
PlaneCategoriesResponse responseWrapper = objectMapper.convertValue(dataMap, PlaneCategoriesResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
} catch (CustomException e) {
|
|
LOGGER.error("Custom Exception: {}", e.getMessage());
|
|
throw e; // Rethrow custom exceptions to be handled by the controller
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchInitiatingChannel(BillerDetailRequest requestModel) {
|
|
LOGGER.info("Fetching Initiating Channel List for MID={}", requestModel.getMid());
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String apiName = "FetchInitiatingChannel";
|
|
String requestId =requestModel.getReqId();
|
|
InboundTraceLog inboundLog = createInboundLog(requestId, txnID, apiName, requestModel.getMid(), "POST", helper.convertObjectToJson(requestModel));
|
|
|
|
try {
|
|
String validateMerchant = helper.validateMerchant(requestModel);
|
|
|
|
if (!"Valid".equalsIgnoreCase(validateMerchant)) {
|
|
LOGGER.warn("Merchant validation failed: {}", validateMerchant);
|
|
updateInboundLogFailure(inboundLog, validateMerchant, "INVALID_MERCHANT");
|
|
return new ResponseModel("Merchant validation failed", validateMerchant, BBPSConstant.BADREQUEST, null);
|
|
}
|
|
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.INITIATING_CHANNEL;
|
|
LOGGER.info("Calling Master API: {}", fullUrl);
|
|
|
|
OutboundTraceLog outboundLog = createOutboundLog(txnID, requestId, apiName, fullUrl, "GET", null);
|
|
|
|
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
|
log.info("Response" + apiResponse);
|
|
String responseData = apiResponse.get("data").toString();
|
|
|
|
updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
|
|
if (!dataMap.containsKey("generalResp")) {
|
|
updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get("status")));
|
|
throw new CustomException(String.valueOf(dataMap.get("message")), // message
|
|
String.valueOf(dataMap.get("status")), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
|
|
String.valueOf(dataMap.get("remarks")));
|
|
}
|
|
|
|
ChannelsListResponse responseWrapper = objectMapper.convertValue(dataMap, ChannelsListResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGenericResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
updateInboundLogFailure(inboundLog, e.getMessage(), "JSON_ERROR");
|
|
throw new CustomException("Invalid JSON received from API");
|
|
} catch (CustomException e) {
|
|
LOGGER.error("Custom Exception: {}", e.getMessage());
|
|
throw e; // Rethrow custom exceptions to be handled by the controller
|
|
}
|
|
}
|
|
|
|
}
|