added fetchBillByBillId
This commit is contained in:
@@ -6,6 +6,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.FetchBillRequest;
|
||||
import com.billpaymentservice.bbps.service.AgentService;
|
||||
|
||||
@@ -33,4 +34,20 @@ public class AgentController {
|
||||
ResponseModel response = agentService.initiateBillFetch(fetchBillRequest);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches bill details from external BBPS service
|
||||
*/
|
||||
@PostMapping(
|
||||
value = "/fetchBillById",
|
||||
consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE
|
||||
)
|
||||
public ResponseEntity<ResponseModel> fetchBillById(
|
||||
@Validated @RequestBody BillFetchByBillIdRequest billFetchByBillIdRequest) {
|
||||
|
||||
ResponseModel response = agentService.fetchBillById(billFetchByBillIdRequest);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AdditionalInfoBill {
|
||||
private String additionalInfoId;
|
||||
private String name;
|
||||
private String value;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BillerResponseBill {
|
||||
private String billId;
|
||||
private String amount;
|
||||
private String billDate;
|
||||
private String billNumber;
|
||||
private String billPeriod;
|
||||
private String custConvFee;
|
||||
private String couCustConvFee;
|
||||
private String dueDate;
|
||||
private String customerName;
|
||||
private boolean amountOption;
|
||||
private Object tagList; // null in response, so keeping Object
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CustomerParamBill {
|
||||
private String name;
|
||||
private String value;
|
||||
private String type;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.billpaymentservice.bbps.dto.request;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BillFetchByBillIdRequest extends BaseClass {
|
||||
|
||||
@NotNull
|
||||
private String billId;
|
||||
private String tenantId; // //M
|
||||
private String digiledgeKey; // M
|
||||
private String agentId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.billpaymentservice.bbps.dto.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.AdditionalInfoBill;
|
||||
import com.billpaymentservice.bbps.dto.BillerResponseBill;
|
||||
import com.billpaymentservice.bbps.dto.CustomerParamBill;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResponse;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class BillDataResponse {
|
||||
|
||||
private GeneralResp genericResponse;
|
||||
private String billId;
|
||||
private String refId;
|
||||
private String billerId;
|
||||
private String status;
|
||||
private String actionType;
|
||||
private String userId;
|
||||
|
||||
private BillerResponseBill billerResponse; // nested object
|
||||
private List<AdditionalInfoBill> additionalInfo; // array of objects
|
||||
private List<CustomerParamBill> customerParams; // array of objects
|
||||
|
||||
private String creationDate;
|
||||
private String modifiedDate;
|
||||
private long createdEpochDate;
|
||||
private long modifiedEpochDate;
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.billpaymentservice.bbps.service;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.FetchBillRequest;
|
||||
|
||||
public interface AgentService {
|
||||
|
||||
public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest);
|
||||
|
||||
public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest);
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class HttpService {
|
||||
}
|
||||
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
|
||||
// ✅ MAKE THE REQUEST
|
||||
ResponseEntity<String> restResponse = restClient.post()
|
||||
.uri(url)
|
||||
@@ -71,24 +71,78 @@ public class HttpService {
|
||||
return response;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getRequest(String url) {
|
||||
public HashMap<String, String> getRequest(String url, HttpHeaders customHeaders) {
|
||||
HashMap<String, String> response = new HashMap<>();
|
||||
|
||||
try {
|
||||
log.info("🌐 Bank GET Request to URL: {}", url);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
if (customHeaders != null) {
|
||||
headers.addAll(customHeaders);
|
||||
}
|
||||
|
||||
log.info("🌐 Sending GET request to: {}", url);
|
||||
log.info("📦 Headers: {}", headers);
|
||||
|
||||
ResponseEntity<String> restResponse = restClient.get()
|
||||
.uri(url)
|
||||
.retrieve()
|
||||
.toEntity(String.class);
|
||||
.uri(url)
|
||||
.headers(h -> h.addAll(headers))
|
||||
.retrieve()
|
||||
.toEntity(String.class);
|
||||
|
||||
response.put("respCode", String.valueOf(restResponse.getStatusCode().value()));
|
||||
response.put("data", restResponse.getBody());
|
||||
|
||||
log.info("✅ GET Response: {}", restResponse.getStatusCode());
|
||||
|
||||
} catch (HttpClientErrorException | HttpServerErrorException httpException) {
|
||||
response.put("data", "Exception : " + httpException.getResponseBodyAsString());
|
||||
log.error("❌ HTTP Error: {}", httpException.getMessage(), httpException);
|
||||
response.put("respCode", String.valueOf(httpException.getStatusCode().value()));
|
||||
response.put("data", httpException.getResponseBodyAsString());
|
||||
} catch (Exception e) {
|
||||
response.put("data", "Exception :" + e.getMessage());
|
||||
log.error("❌ Exception during GET call to {} -> {}", url, e.getMessage());
|
||||
log.error("❌ Exception during GET call: {}", e.getMessage(), e);
|
||||
response.put("respCode", "500");
|
||||
response.put("data", "Exception: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 🟢 You missed this line earlier
|
||||
return response;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getRequest(String url) {
|
||||
HashMap<String, String> response = new HashMap<>();
|
||||
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
log.info("🌐 Sending GET request to: {}", url);
|
||||
log.info("📦 Headers: {}", headers);
|
||||
|
||||
ResponseEntity<String> restResponse = restClient.get()
|
||||
.uri(url)
|
||||
.headers(h -> h.addAll(headers))
|
||||
.retrieve()
|
||||
.toEntity(String.class);
|
||||
|
||||
response.put("respCode", String.valueOf(restResponse.getStatusCode().value()));
|
||||
response.put("data", restResponse.getBody());
|
||||
|
||||
log.info("✅ GET Response: {}", restResponse.getStatusCode());
|
||||
|
||||
} catch (HttpClientErrorException | HttpServerErrorException httpException) {
|
||||
log.error("❌ HTTP Error: {}", httpException.getMessage(), httpException);
|
||||
response.put("respCode", String.valueOf(httpException.getStatusCode().value()));
|
||||
response.put("data", httpException.getResponseBodyAsString());
|
||||
} catch (Exception e) {
|
||||
log.error("❌ Exception during GET call: {}", e.getMessage(), e);
|
||||
response.put("respCode", "500");
|
||||
response.put("data", "Exception: " + e.getMessage());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -29,5 +29,6 @@ public class BBPSConstant {
|
||||
public static final String BILLER_DATA_FETCH_URL="/billersById?billerId=";
|
||||
public static final String CUSTOMPARAM_URL="/customerParam?billerId=";
|
||||
public static final String BILL_FETCH_INTI="/couapp/bills/fetch";
|
||||
public static final String BILL_FETCH_BY_ID="/couapp/bills/fetch/byId?billId=";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user