880 lines
43 KiB
Java
880 lines
43 KiB
Java
package com.billpaymentservice.bbps.serviceImpl;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
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.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import com.billpaymentservice.bbps.config.JwtUtil;
|
|
import com.billpaymentservice.bbps.dto.CustomParamDTO;
|
|
import com.billpaymentservice.bbps.dto.CustomerParamGroupsDTO;
|
|
import com.billpaymentservice.bbps.dto.GeneralResp;
|
|
import com.billpaymentservice.bbps.dto.MasterApiResponse;
|
|
import com.billpaymentservice.bbps.dto.ResponseModel;
|
|
import com.billpaymentservice.bbps.dto.UserDetailsDTO;
|
|
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.LoginRequest;
|
|
import com.billpaymentservice.bbps.dto.request.MasterCategoryRequest;
|
|
import com.billpaymentservice.bbps.dto.request.MasterRequest;
|
|
import com.billpaymentservice.bbps.dto.request.PlanRequest;
|
|
import com.billpaymentservice.bbps.dto.response.AmountOptionsResponse;
|
|
import com.billpaymentservice.bbps.dto.response.AuthResponses;
|
|
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.ContactMasterResponse;
|
|
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.PlanResponse;
|
|
import com.billpaymentservice.bbps.dto.response.PlaneCategoriesResponse;
|
|
import com.billpaymentservice.bbps.dto.response.TicketDispositionResponse;
|
|
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
|
|
import com.billpaymentservice.bbps.entites.BillerCategoryWise;
|
|
import com.billpaymentservice.bbps.entites.BillerDetails;
|
|
import com.billpaymentservice.bbps.entites.CustomParam;
|
|
import com.billpaymentservice.bbps.entites.DispositionDetails;
|
|
import com.billpaymentservice.bbps.entites.InboundTraceLog;
|
|
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
|
|
import com.billpaymentservice.bbps.entites.PlanResponses;
|
|
import com.billpaymentservice.bbps.entites.UsersDetails;
|
|
import com.billpaymentservice.bbps.exception.CustomException;
|
|
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
|
|
import com.billpaymentservice.bbps.repository.BillerDataRepository;
|
|
import com.billpaymentservice.bbps.repository.CustomParamRepository;
|
|
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.repository.UsersDetailsRepository;
|
|
import com.billpaymentservice.bbps.service.MasterDataService;
|
|
import com.billpaymentservice.bbps.util.BBPSConstant;
|
|
import com.billpaymentservice.bbps.util.BillerMapperHelper;
|
|
import com.billpaymentservice.bbps.util.EntityRelationshipUtil;
|
|
import com.billpaymentservice.bbps.util.Helper;
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
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 final BillerMapperHelper mapperHelper;
|
|
private MerchantRepository merchantRegisterRepo;
|
|
private HttpClientApi httpClientApi;
|
|
private final DispositionRepository dispositionRepository;
|
|
|
|
private final Helper helper;
|
|
private final BillerDataRepository billerDataRespository;
|
|
private final HttpService httpService;
|
|
private final ObjectMapper objectMapper;
|
|
private final InboundTraceLogRepository inboundTraceLogRepository;
|
|
private final OutboundTraceLogRepository outboundTraceLogRepository;
|
|
private final CustomParamRepository customParamReposiotory;
|
|
|
|
public MasterDataServiceImpl(MerchantRepository merchantRegisterRepo, HttpService httpService,
|
|
HttpClientApi httpClientApi, Helper helper, BillerDataRepository billerDataRespository,
|
|
DispositionRepository dispositionRepository, BharatConnectMasterRepository beneficiaryDetailsRepository,
|
|
InboundTraceLogRepository inboundTraceLogRepository, OutboundTraceLogRepository outboundTraceLogRepository,
|
|
BillerMapperHelper mapperHelper, CustomParamRepository customParamReposiotory) {
|
|
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;
|
|
this.mapperHelper = mapperHelper;
|
|
this.customParamReposiotory = customParamReposiotory;
|
|
|
|
this.objectMapper = new ObjectMapper();
|
|
this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getMasterData(MasterRequest masterRequest) {
|
|
|
|
String apiName = BBPSConstant.API_GET_MASTER_DATA;
|
|
String requestId = masterRequest.getReqId();
|
|
String mid = masterRequest.getMid();
|
|
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid);
|
|
String txnID = helper.generateTxnId(15);
|
|
String requestJson = helper.convertObjectToJson(masterRequest);
|
|
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(),
|
|
BBPSConstant.HTTP_POST, requestJson);
|
|
helper.validateMerchant(mid);
|
|
try {
|
|
// check Tenant Id is present DB
|
|
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
|
if (headersData == null) {
|
|
LOGGER.warn("header data not found for the orgID");
|
|
throw new CustomException("Something went wrong", "FAILED", 500, "");
|
|
}
|
|
// get full url
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.MASTER_CATEGORY_URL + headersData.getTenantId();
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
HttpHeaders headers = helper.buildHeaders(headersData);
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
|
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
|
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // 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);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
|
|
String apiName = BBPSConstant.API_GET_BILLER_BY_ID;
|
|
String requestId = billerDetailRequest.getReqId();
|
|
String billerId = billerDetailRequest.getBillerId();
|
|
String mid = billerDetailRequest.getMid();
|
|
|
|
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid, billerId);
|
|
|
|
// 2. Transaction Id
|
|
String txnID = helper.generateTxnId(15);
|
|
// 3. Prepare URL
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL + billerId;
|
|
// 4. Prepare Logs
|
|
String requestJson = helper.convertObjectToJson(billerDetailRequest);
|
|
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, billerDetailRequest.getMid(),
|
|
BBPSConstant.HTTP_POST, requestJson);
|
|
helper.validateMerchant(mid);
|
|
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
|
LOGGER.info("fetched data from api is :{}", responseData);
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)),
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)),
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))),
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
// Mapping to Model
|
|
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);// linking nesting entity foreign key
|
|
mapperHelper.saveOrUpdateBillerData(entity);
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getCustomerParamByBillerId(CustomParamRequest customerParamRequest) {
|
|
String apiName = BBPSConstant.API_GET_CUSTOMER_PARAM_BY_BILLER_ID;
|
|
String requestId = customerParamRequest.getReqId();
|
|
String mid = customerParamRequest.getMid();
|
|
|
|
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid,
|
|
customerParamRequest.getBillerId());
|
|
String txnID = helper.generateTxnId(15);
|
|
String billerId = customerParamRequest.getBillerId();
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMPARAM_URL + billerId;
|
|
|
|
String requestJson = helper.convertObjectToJson(customerParamRequest);
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, customerParamRequest.getMid(),
|
|
BBPSConstant.HTTP_POST, requestJson);
|
|
helper.validateMerchant(mid);
|
|
try {
|
|
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
|
LOGGER.info("data is :{}", responseData);
|
|
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
// (int)
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
|
|
CustomParamResp responseWrapper = objectMapper.convertValue(dataMap, CustomParamResp.class);
|
|
List<CustomParamDTO> customParams = responseWrapper.getCustomParamResp();
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
List<CustomParamDTO> customParam = responseWrapper.getCustomParamResp();
|
|
ModelMapper mapper = new ModelMapper();
|
|
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
|
|
|
|
// Map DTOs to entities
|
|
List<CustomParam> entities = customParams.stream().map(dto -> mapper.map(dto, CustomParam.class))
|
|
.collect(Collectors.toList());
|
|
// Save all to DB
|
|
customParamReposiotory.saveAll(entities);
|
|
LOGGER.info("[{}] Saved {} custom param records to DB", apiName, entities.size());
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getContactMaster(ContactMasterRequest contactMasterRequest) {
|
|
|
|
String apiName = BBPSConstant.API_FETCH_CATEGORY_MASTER_DATA;
|
|
String requestId = contactMasterRequest.getReqId();
|
|
String mid = contactMasterRequest.getMid();
|
|
LOGGER.info("[{}] START | reqId={} | mid={} | category={}", apiName, requestId, contactMasterRequest.getMid(),
|
|
contactMasterRequest.getCategory());
|
|
String txnID = helper.generateTxnId(15);
|
|
|
|
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
|
|
String fullUrl = masterRegisterUrl + String.format(BBPSConstant.CONTACT_MASTER_URL, headersData.getTenantId(),
|
|
contactMasterRequest.getCategory());
|
|
|
|
String requestJson = helper.convertObjectToJson(contactMasterRequest);
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, contactMasterRequest.getMid(),
|
|
BBPSConstant.HTTP_POST, requestJson);
|
|
helper.validateMerchant(mid);
|
|
try {
|
|
|
|
LOGGER.info("Contact Master Full URL-:" + fullUrl);
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
|
|
HttpHeaders headers = helper.buildHeaders(headersData);
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
|
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
|
LOGGER.info("Response Data: {}", responseData);
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // remarks
|
|
);
|
|
}
|
|
|
|
ContactMasterResponse responseWrapper = objectMapper.convertValue(dataMap, ContactMasterResponse.class);
|
|
String result = mapperHelper.saveContactMasterData(responseWrapper.getContactMasterList(), requestId,
|
|
txnID);
|
|
|
|
LOGGER.info("[{}] DB Save Result | reqId={} | result={}", apiName, requestId, result);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchMasterDataCategoryWise(MasterCategoryRequest masterRequest) {
|
|
|
|
String apiName = BBPSConstant.API_FETCH_MASTER_DATA_CATEGORY_WISE;
|
|
String requestId = masterRequest.getReqId();
|
|
String mid = masterRequest.getMid();
|
|
|
|
LOGGER.info("[{}] START | reqId={} | mid={} | billerName={} | category={}", apiName, requestId, mid,
|
|
masterRequest.getBillerName(), masterRequest.getCategory());
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String fullUrl = String.format("%s%s?billerName=%s&category=%s&page=%d&pagesize=%d", masterRegisterUrl,
|
|
BBPSConstant.BILLER_URL, masterRequest.getBillerName(), masterRequest.getCategory(),
|
|
masterRequest.getPageNo(), masterRequest.getPageSize());
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
String requestJson = helper.convertObjectToJson(masterRequest);
|
|
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, masterRequest.getMid(),
|
|
BBPSConstant.HTTP_POST, requestJson);
|
|
helper.validateMerchant(mid);
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
|
|
try {
|
|
|
|
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
|
|
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
|
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
|
|
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)) // remarks
|
|
);
|
|
}
|
|
|
|
BillerResponse responseWrapper = objectMapper.convertValue(dataMap, BillerResponse.class);
|
|
List<BillerCategoryWise> savedEntities = mapperHelper.mapAndSaveAll(responseWrapper.getBillerResp(),
|
|
requestId, txnID);
|
|
LOGGER.info("[{}] Saved {} records to DB | reqId={}", apiName, savedEntities.size(), requestId);
|
|
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getDispositionDetails(DispositionRequest dispositionDetailRequest) {
|
|
|
|
String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS;
|
|
String requestId = dispositionDetailRequest.getReqId();
|
|
String mid = dispositionDetailRequest.getMid();
|
|
String requestJson = helper.convertObjectToJson(dispositionDetailRequest);
|
|
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid);
|
|
String txnID = helper.generateTxnId(15);
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.DISPOSTION_URL;
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName,
|
|
dispositionDetailRequest.getMid(), BBPSConstant.HTTP_GET, requestJson);
|
|
helper.validateMerchant(mid);
|
|
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, requestJson);
|
|
|
|
try {
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
|
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
// (int)
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
|
|
DispositionResponse responseWrapper = objectMapper.convertValue(dataMap, DispositionResponse.class);
|
|
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());
|
|
|
|
LOGGER.info("[{}] Dispositions Received: {}", apiName, entities.size());
|
|
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);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchCustomerParamGroup(BillerDetailRequest requestModel) {
|
|
|
|
String apiName = BBPSConstant.API_FETCH_CUSTOMER_PARAM_GROUP;
|
|
String requestId = requestModel.getReqId();
|
|
String mid = requestModel.getMid();
|
|
|
|
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid,
|
|
requestModel.getBillerId());
|
|
helper.validateMerchant(mid);
|
|
String txnID = helper.generateTxnId(15);
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMER_PARAM_GROUP + requestModel.getBillerId();
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(),
|
|
BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel));
|
|
|
|
try {
|
|
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
|
|
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
|
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString();
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
// (int)
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
|
|
CustomerParamGroupsResponse responseWrapper = objectMapper.convertValue(dataMap,
|
|
CustomerParamGroupsResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
CustomerParamGroupsDTO responseDTO = mapperHelper
|
|
.saveCustomerParamGroups(responseWrapper.getCustomerParamGroupResp(), requestId, txnID);
|
|
|
|
LOGGER.info("[{}] Saved {} Customer Param Group records | reqId={}", apiName, responseDTO.toString(),
|
|
requestId);
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchAllMasterAmountOption(BillerDetailRequest requestModel) {
|
|
|
|
String apiName = BBPSConstant.API_FETCH_ALL_MASTER_AMOUNT_OPTION;
|
|
String requestId = requestModel.getReqId();
|
|
String mid = requestModel.getMid();
|
|
|
|
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid,
|
|
requestModel.getBillerId());
|
|
|
|
String txnID = helper.generateTxnId(15);
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.AMOUNT_OPTIONS + requestModel.getBillerId();
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(),
|
|
BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel));
|
|
helper.validateMerchant(mid);
|
|
try {
|
|
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
|
|
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
|
LOGGER.info("Response" + apiResponse);
|
|
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString();
|
|
|
|
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
// (int)
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
|
|
AmountOptionsResponse responseWrapper = objectMapper.convertValue(dataMap, AmountOptionsResponse.class);
|
|
|
|
String saveAmountOptionsResponse = mapperHelper.saveAmountOptionsResponse(responseWrapper, requestId,
|
|
txnID);
|
|
LOGGER.info("[{}] Save Result | reqId={} | result={}", apiName, requestId, saveAmountOptionsResponse);
|
|
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchPlanCategorie(BillerDetailRequest requestModel) {
|
|
|
|
String apiName = BBPSConstant.API_FETCH_PLAN_CATEGORIES;
|
|
String requestId = requestModel.getReqId();
|
|
String mid = requestModel.getMid();
|
|
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid,
|
|
requestModel.getBillerId());
|
|
helper.validateMerchant(requestModel.getMid());
|
|
String txnID = helper.generateTxnId(15);
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.PLAN_CATEGORIES + requestModel.getBillerId();
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(),
|
|
BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel));
|
|
helper.validateMerchant(mid);
|
|
try {
|
|
LOGGER.info("[{}] Calling External API | URL={} | Method=GET", apiName, fullUrl);
|
|
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
|
LOGGER.info("Response" + apiResponse);
|
|
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString();
|
|
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
// (int)
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
|
|
PlaneCategoriesResponse responseWrapper = objectMapper.convertValue(dataMap, PlaneCategoriesResponse.class);
|
|
|
|
String saveCategoryItems = mapperHelper.saveCategoryItems(responseWrapper.getCategoryRespList(), requestId,
|
|
txnID);
|
|
LOGGER.info("[{}] Saved category items | reqId={} | count={}", apiName, requestId, saveCategoryItems);
|
|
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel fetchInitiatingChannel(BillerDetailRequest requestModel) {
|
|
|
|
String apiName = BBPSConstant.API_FETCH_INITIATING_CHANNEL;
|
|
String requestId = requestModel.getReqId();
|
|
String mid = requestModel.getMid();
|
|
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid);
|
|
String txnID = helper.generateTxnId(15);
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.INITIATING_CHANNEL;
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(),
|
|
BBPSConstant.HTTP_POST, helper.convertObjectToJson(requestModel));
|
|
helper.validateMerchant(mid);
|
|
try {
|
|
LOGGER.info("[{}] Calling Master API | URL={} | Method=GET", apiName, fullUrl);
|
|
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
LOGGER.info("Calling Master API: {}", fullUrl);
|
|
Map<String, String> apiResponse = httpService.getRequest(fullUrl);
|
|
LOGGER.info("Response" + apiResponse);
|
|
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY).toString();
|
|
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
// (int)
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
|
|
ChannelsListResponse responseWrapper = objectMapper.convertValue(dataMap, ChannelsListResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGenericResp();
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
|
|
}
|
|
}
|
|
|
|
public ResponseModel fetchPlanByCategories(PlanRequest requestModel) {
|
|
|
|
String apiName = BBPSConstant.API_FETCH_PLAN_BY_CATEGORIES;
|
|
String requestId = requestModel.getReqId();
|
|
String mid = requestModel.getMid();
|
|
LOGGER.info("[{}] START | reqId={} | mid={} | billerId={}", apiName, requestId, mid,
|
|
requestModel.getBillerId());
|
|
String txnID = helper.generateTxnId(15);
|
|
String url = String.format("%s%s?billerId=%s%s%s%s&page=%d&pagesize=%d", masterRegisterUrl,
|
|
BBPSConstant.PLANS_URL, requestModel.getBillerId(),
|
|
requestModel.getCategory() != null ? "&category=" + requestModel.getCategory() : "",
|
|
requestModel.getAmountInRupees() != null ? "&amountInRupees=" + requestModel.getAmountInRupees() : "",
|
|
requestModel.getCircle() != null ? "&circle=" + requestModel.getCircle() : "", requestModel.getPage(),
|
|
requestModel.getPagesize());
|
|
|
|
LOGGER.info("Calling Master API: {}", url);
|
|
|
|
// Convert request to JSON and create inbound & outbound logs
|
|
String requestJson = helper.convertObjectToJson(requestModel);
|
|
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, requestModel.getMid(),
|
|
BBPSConstant.HTTP_POST, requestJson);
|
|
helper.validateMerchant(mid);
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET,
|
|
null);
|
|
try {
|
|
LOGGER.info("[{}] Calling Master API | URL={} | Method=GET", apiName, url);
|
|
Map<String, String> apiResponse = httpService.getRequest(url);
|
|
|
|
String responseData = apiResponse.get(BBPSConstant.RESPONSE_DATA_KEY);
|
|
LOGGER.info("Response Data: {}", responseData);
|
|
|
|
// Update outbound log with response
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
|
new TypeReference<Map<String, Object>>() {
|
|
});
|
|
|
|
if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) {
|
|
// Failure response
|
|
helper.updateInboundLogFailure(inboundLog, responseData,
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)),
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)),
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))),
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
|
|
// Success response
|
|
PlanResponse responseWrapper = objectMapper.convertValue(dataMap, PlanResponse.class);
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
PlanResponses savePlanResponse = mapperHelper.savePlanResponse(responseWrapper, requestId, txnID);
|
|
LOGGER.info("[{}] Saved Plans | reqId={} | count={}", apiName, requestId, savePlanResponse);
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ResponseModel getTicketDispositions(DispositionRequest dispositionDetailRequest) {
|
|
String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS;
|
|
String requestId = dispositionDetailRequest.getReqId();
|
|
String mid = dispositionDetailRequest.getMid();
|
|
|
|
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid);
|
|
String txnID = helper.generateTxnId(15);
|
|
String fullUrl = masterRegisterUrl + BBPSConstant.TICKET_DISPOSTION_URL;
|
|
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName,
|
|
dispositionDetailRequest.getMid(), BBPSConstant.HTTP_GET, "N/A");
|
|
helper.validateMerchant(mid);
|
|
OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, fullUrl,
|
|
BBPSConstant.HTTP_GET, null);
|
|
|
|
try {
|
|
LOGGER.info("Calling external API: {}", fullUrl);
|
|
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
|
String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY);
|
|
|
|
LOGGER.debug("[{}] API Response | reqId={} | data={}", apiName, requestId, responseData);
|
|
helper.updateOutboundLogResponse(outboundLog, responseData);
|
|
|
|
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)));
|
|
throw new CustomException(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_MESSAGE_KEY)), // message
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY)), // status
|
|
Integer.parseInt(String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUSCODE_KEY))), // statusCode
|
|
// (int)
|
|
String.valueOf(dataMap.get(BBPSConstant.RESPONSE_REMARKS_KEY)));
|
|
}
|
|
|
|
TicketDispositionResponse responseWrapper = objectMapper.convertValue(dataMap,
|
|
TicketDispositionResponse.class);
|
|
|
|
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
|
|
|
ModelMapper mapper = new ModelMapper();
|
|
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
|
|
mapperHelper.saveTicketDisoptionDetails(responseWrapper.getDispositionsList(), requestId, txnID);
|
|
|
|
ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(),
|
|
Integer.parseInt(generalResp.getStatusCode()), responseWrapper);
|
|
|
|
helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus());
|
|
LOGGER.info("[{}] END | reqId={} | status={}", apiName, requestId, generalResp.getStatus());
|
|
return responseModel;
|
|
} catch (JsonProcessingException e) {
|
|
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
|
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
|
throw new CustomException("Invalid JSON received from API");
|
|
}
|
|
}
|
|
|
|
} |