implemented customerParam Api

This commit is contained in:
himanshu
2025-10-27 18:02:52 +05:30
parent 01394580f3
commit 4d501f7b4a
11 changed files with 238 additions and 48 deletions
@@ -17,9 +17,13 @@ import org.springframework.web.bind.annotation.RestController;
import com.billpaymentservice.bbps.dto.MasterApiResponse;
import com.billpaymentservice.bbps.dto.request.BillerDetailRequest;
import com.billpaymentservice.bbps.dto.request.ContactMasterRequest;
import com.billpaymentservice.bbps.dto.request.CustomerParamRequest;
import com.billpaymentservice.bbps.dto.request.MerchantRequestModel;
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
import com.billpaymentservice.bbps.dto.response.BillerResponse;
import com.billpaymentservice.bbps.dto.response.ContactMasterResponse;
import com.billpaymentservice.bbps.dto.response.CustomParamResp;
import com.billpaymentservice.bbps.service.MasterDataService;
import jakarta.servlet.http.HttpServletRequest;
@@ -35,45 +39,33 @@ public class MasterDataController {
public MasterDataController(MasterDataService masterDataService) {
this.masterDataService = masterDataService;
}
/**Get Details of the biller by billId **/
@PostMapping(value = "/getBillerDetails", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<BillerDataResponse> getBillerDetails(
@Validated @RequestBody BillerDetailRequest billerDetailRequest) {
log.info("Received biller details request for billerId: {}", billerDetailRequest.getBillerId());
BillerDataResponse response = masterDataService.getBillerByBillerId(billerDetailRequest);
HttpStatus status;
String statusCode = response.getGeneralResp() != null ? response.getGeneralResp().getStatusCode() : "500";
switch (statusCode) {
case "200":
status = HttpStatus.OK;
break;
case "404":
status = HttpStatus.NOT_FOUND;
break;
case "500":
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
default:
status = HttpStatus.BAD_REQUEST;
break;
}
log.info("Returning response for billerId: {} with HTTP status: {}", billerDetailRequest.getBillerId(), status);
return new ResponseEntity<>(response, status);
return ResponseEntity.ok(masterDataService.getBillerByBillerId(billerDetailRequest));
}
/**Get Master Contact**/
@PostMapping(value = "/getContactMasterResponse", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ContactMasterResponse> getContactMaster(
@Validated @RequestBody ContactMasterRequest contactMasterRequest ) {
@PostMapping("/getBillerById")
public String getBillerById(@RequestBody BillerDetailRequest billerRequestRequest) {
masterDataService.getBillerByBillerId(billerRequestRequest);
return "Abc";
return ResponseEntity.ok(masterDataService.getContactMaster(contactMasterRequest));
}
/** Get CustomerParam by billerId.The parameter is different from the data we are getting in the billerDetail **/
@PostMapping(value = "/getCustomerParamDetails", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CustomParamResp> getBillerDetails(
@Validated @RequestBody CustomerParamRequest customerParamRequest) {
log.info("Received biller details request for billerId: {}",customerParamRequest.getBillerId() );
return ResponseEntity.ok(masterDataService.getCustomerParamByBillerId(customerParamRequest));
}
/** Get All Masters API Fetch All Category from BBPS URL **/
@GetMapping("/getAllMasters")
public ResponseEntity<List<MasterApiResponse>> fetchMasterData(
@@ -0,0 +1,23 @@
package com.billpaymentservice.bbps.dto;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class CustomParam {
private String customParamName;
private String dataType;
private boolean optional;
private int minLength;
private int maxLength;
private String regex;
private boolean visibility;
private List<String> values;
}
@@ -1,5 +1,9 @@
package com.billpaymentservice.bbps.dto;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonAlias;
import lombok.Getter;
import lombok.Setter;
@@ -8,6 +12,7 @@ import lombok.Setter;
public class CustomerParam {
private String paramConfigId;
private String paramName;
private String dataTypeDAO;
private String dataTypeModel;
private boolean optional;
@@ -15,6 +20,7 @@ public class CustomerParam {
private int maxLength;
private String regex;
private boolean visibility;
// 👇 Add this new line
private List<String> values;
// getters and setters
}
@@ -0,0 +1,22 @@
package com.billpaymentservice.bbps.dto.request;
import com.billpaymentservice.bbps.dto.DeviceDetail;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class BaseClass {
private String mid;
private String secretKey;
private String txnId;
private DeviceDetail deviceDetial;
}
@@ -0,0 +1,19 @@
package com.billpaymentservice.bbps.dto.request;
import com.billpaymentservice.bbps.entites.BaseClass;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CustomerParamRequest extends BaseClass {
@NotNull
private String billerId;
}
@@ -0,0 +1,22 @@
package com.billpaymentservice.bbps.dto.response;
import java.util.List;
import com.billpaymentservice.bbps.dto.ContactMaster;
import com.billpaymentservice.bbps.dto.CustomParam;
import com.billpaymentservice.bbps.dto.CustomerParam;
import com.billpaymentservice.bbps.dto.GeneralResp;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class CustomParamResp {
private GeneralResp generalResp;
private List<CustomParam> customParamResp;
}
@@ -6,9 +6,13 @@ import org.springframework.http.ResponseEntity;
import com.billpaymentservice.bbps.dto.MasterApiResponse;
import com.billpaymentservice.bbps.dto.request.BillerDetailRequest;
import com.billpaymentservice.bbps.dto.request.ContactMasterRequest;
import com.billpaymentservice.bbps.dto.request.CustomerParamRequest;
import com.billpaymentservice.bbps.dto.request.MerchantRequestModel;
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
import com.billpaymentservice.bbps.dto.response.BillerResponse;
import com.billpaymentservice.bbps.dto.response.ContactMasterResponse;
import com.billpaymentservice.bbps.dto.response.CustomParamResp;
import jakarta.servlet.http.HttpServletRequest;
@@ -21,4 +25,8 @@ public interface MasterDataService {
public ResponseEntity<BillerResponse> fetchMasterDataCategoryWise(MerchantRequestModel requestModel, String category, int pageStart, int pageEnd);
public CustomParamResp getCustomerParamByBillerId(CustomerParamRequest customerParamRequest);
public ContactMasterResponse getContactMaster(ContactMasterRequest contactMasterRequest);
}
@@ -15,15 +15,20 @@ import org.springframework.stereotype.Service;
import com.billpaymentservice.bbps.dto.MasterApiResponse;
import com.billpaymentservice.bbps.dto.request.BillerDetailRequest;
import com.billpaymentservice.bbps.dto.request.ContactMasterRequest;
import com.billpaymentservice.bbps.dto.request.CustomerParamRequest;
import com.billpaymentservice.bbps.dto.request.MerchantRequestModel;
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
import com.billpaymentservice.bbps.dto.response.BillerResponse;
import com.billpaymentservice.bbps.dto.response.ContactMasterResponse;
import com.billpaymentservice.bbps.dto.response.CustomParamResp;
import com.billpaymentservice.bbps.entites.BBPSMerchantValidation;
import com.billpaymentservice.bbps.exception.AppException;
import com.billpaymentservice.bbps.exception.CustomException;
import com.billpaymentservice.bbps.repository.MerchantRepository;
import com.billpaymentservice.bbps.service.MasterDataService;
import com.billpaymentservice.bbps.util.BBPSConstant;
import com.billpaymentservice.bbps.util.Helper;
import com.billpaymentservice.bbps.util.ResponseParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -39,33 +44,36 @@ public class MasterDataServiceImpl implements MasterDataService {
@Value("${master.data.url}")
private String masterRegisterUrl;
@Autowired
private MerchantRepository merchantRegisterRepo;
@Autowired
private HttpClientApi httpClientApi;
@Autowired
private ResponseParser responseParser;
private Helper helper;
private static final Logger log = LoggerFactory.getLogger(MasterDataServiceImpl.class);
private final HttpService httpService;
private final ObjectMapper objectMapper = new ObjectMapper();
@Value("${bbps.billerDataFetch.url}")
private String billerDataFetchUrl;
// Inject HttpService
public MasterDataServiceImpl(HttpService httpService) {
this.httpService = httpService;
}
public MasterDataServiceImpl(MerchantRepository merchantRegisterRepo,
HttpService httpService,
HttpClientApi httpClientApi,
Helper helper,
ResponseParser responseParser) {
this.merchantRegisterRepo = merchantRegisterRepo;
this.httpService = httpService;
this.httpClientApi = httpClientApi;
this.helper = helper;
this.responseParser = responseParser;
}
@Override
public BillerDataResponse getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
String billerId = billerDetailRequest.getBillerId();
String url = billerDataFetchUrl + billerId;
String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL+billerId;
Map<String, String> responseMap = httpService.getRequest(url);
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
log.info("data is :{}", responseData);
@@ -186,4 +194,40 @@ public class MasterDataServiceImpl implements MasterDataService {
return ResponseEntity.ok(responseModel);
}
@Override
public CustomParamResp getCustomerParamByBillerId(CustomerParamRequest customerParamRequest) {
String billerId = customerParamRequest.getBillerId();
String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMPARAM_URL+billerId;
Map<String, String> responseMap = httpService.getRequest(fullUrl);
String responseData = responseMap.get("data");
log.info("data is :{}", responseData);
ObjectMapper objectMapper = new ObjectMapper();
try {
Map<String, Object> dataMap = objectMapper.readValue(responseData,
new TypeReference<Map<String, Object>>() {
});
if (!dataMap.containsKey("generalResp")) {
throw new CustomException(String.valueOf(dataMap.get("statusCode")),
String.valueOf(dataMap.get("status")), String.valueOf(dataMap.get("message")),
String.valueOf(dataMap.get("remarks")));
}
CustomParamResp responseWrapper = objectMapper.convertValue(dataMap, CustomParamResp.class);
return responseWrapper;
} catch (JsonProcessingException e) {
log.error("Error parsing responseData JSON: {}", e.getMessage());
throw new CustomException("Invalid JSON received from API");
}
}
@Override
public ContactMasterResponse getContactMaster(ContactMasterRequest contactMasterRequest) {
return null;
}
}
@@ -25,5 +25,8 @@ public class BBPSConstant {
public static final String BILLER_URL = "/billers";
public static final String MASTER_CATEGORY_URL = "/categories-master?tenantId=FE41";
public static final String BILLER_DATA_FETCH_URL="/billersById?billerId=";
public static final String CUSTOMPARAM_URL="/customerParam?billerId=";
}
@@ -0,0 +1,51 @@
package com.billpaymentservice.bbps.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.billpaymentservice.bbps.dto.request.MerchantRequestModel;
import com.billpaymentservice.bbps.entites.BBPSMerchantValidation;
import com.billpaymentservice.bbps.exception.CustomException;
import com.billpaymentservice.bbps.repository.MerchantRepository;
@Component
public class Helper {
private static final Logger LOGGER = LoggerFactory.getLogger(Helper.class);
@Autowired
private MerchantRepository merchantRegisterRepo;
/**
* Validates whether the merchant exists and is active.
*
* @param requestModel MerchantRequestModel containing merchant details
* @return true if merchant exists and is active
* @throws CustomException if merchant is invalid or inactive
*/
public boolean isMerchantValidAndActive(MerchantRequestModel requestModel) {
if (requestModel == null || requestModel.getMid() == null) {
LOGGER.warn("MerchantRequestModel or MID is null");
throw new CustomException("Invalid request: MID is required");
}
// Fetch merchant details
BBPSMerchantValidation merchantValidation = merchantRegisterRepo.findByMid(requestModel.getMid());
if (merchantValidation == null) {
LOGGER.warn("Merchant not found for MID: {}", requestModel.getMid());
throw new CustomException("Merchant not found");
}
if (!Boolean.TRUE.equals(merchantValidation.isActive())) {
LOGGER.warn("Merchant inactive for MID: {}", requestModel.getMid());
throw new CustomException("Merchant inactive");
}
LOGGER.info("Merchant is valid and active for MID: {}", requestModel.getMid());
return true;
}
}
+3 -3
View File
@@ -11,7 +11,7 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
# DataSource
spring.datasource.url=jdbc:postgresql://localhost:5432/TestingDB
spring.datasource.username=postgres
spring.datasource.password=UAT@DB_2025
spring.datasource.password=thakur@123
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
@@ -26,12 +26,12 @@ spring.datasource.hikari.auto-commit=true
# Logging levels
logging.level.io.github.resilience4j.retry=DEBUG
# BBPS URLs
bbps.billerDataFetch.url=https://bbps-staging.digiledge.in/agent/cou-master/masters/billersById?billerId=
# BBPS URLs
master.data.url = https://bbps-staging.digiledge.in/agent/cou-master/masters
# Resilience4j Retry
resilience4j.retry.instances.callbackService.max-attempts=1
resilience4j.retry.instances.callbackService.wait-duration=2s