added fetchBillByBillId
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResponse;
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.FetchBillRequest;
|
||||
import com.billpaymentservice.bbps.dto.response.BillDataResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.FetchBillResponse;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.service.AgentService;
|
||||
import com.billpaymentservice.bbps.util.BBPSConstant;
|
||||
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;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -15,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
@@ -24,12 +31,16 @@ import org.springframework.web.client.RestClient;
|
||||
@RequiredArgsConstructor
|
||||
public class AgentServiceImpl implements AgentService {
|
||||
|
||||
@Value("${agent.data.url}")
|
||||
private String agentDtaUrl;
|
||||
|
||||
private final RestClient restClient;
|
||||
private final HttpService httpService;// ✅ injected from config
|
||||
|
||||
@Override
|
||||
public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) {
|
||||
String url = "https://bbps-staging.digiledge.in/agent/bill-payment-new/couapp/bills/fetch";
|
||||
String url = agentDtaUrl+BBPSConstant.BILL_FETCH_INTI;
|
||||
System.out.println(url);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", fetchBillRequest.getDigiledgeKey());
|
||||
@@ -86,4 +97,53 @@ public class AgentServiceImpl implements AgentService {
|
||||
return responseModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest) {
|
||||
|
||||
String billId = billFetchByBillIdRequest.getBillId();
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID+billId;
|
||||
System.out.print(fullUrl);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", billFetchByBillIdRequest.getDigiledgeKey());
|
||||
headers.set("agentId", billFetchByBillIdRequest.getAgentId());
|
||||
headers.set("tenantId", billFetchByBillIdRequest.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl,headers);
|
||||
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("genericResponse")) {
|
||||
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")) );
|
||||
}
|
||||
|
||||
BillDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillDataResponse.class);
|
||||
|
||||
GeneralResp generalResp = responseWrapper.getGenericResponse();
|
||||
|
||||
ResponseModel responseModel=new ResponseModel( generalResp.getMessage(),
|
||||
generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()),
|
||||
responseWrapper);
|
||||
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user