save billerdata to in database working code
This commit is contained in:
@@ -57,6 +57,13 @@ public class MasterDataController {
|
||||
return ResponseEntity.ok(masterDataService.getContactMaster(contactMasterRequest));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/getDispostionDetail", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<ResponseModel> getDispostionDetail(
|
||||
@Validated @RequestBody ContactMasterRequest contactMasterRequest ) {
|
||||
return ResponseEntity.ok(masterDataService.getDispositionDetails());
|
||||
}
|
||||
|
||||
|
||||
/** 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<ResponseModel> getBillerDetails(
|
||||
@@ -70,5 +77,6 @@ public class MasterDataController {
|
||||
public ResponseModel fetchMasterData(@Validated @RequestBody MasterRequest masterRequest) {
|
||||
return masterDataService.getMasterData(masterRequest);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
@@ -10,13 +11,12 @@ public class AgentFundTransfer {
|
||||
@NotBlank private String fundTxnReferenceId;
|
||||
@NotBlank private String fundTxnRemarks;
|
||||
@NotBlank private String fundTxnDate;
|
||||
|
||||
@NotNull private Double fundTxnAmt;
|
||||
|
||||
@NotBlank private String fundUTR;
|
||||
|
||||
private String fundRespRemarks;
|
||||
private String agentNpciId;
|
||||
private String txnRefId;
|
||||
|
||||
private String tenantId;
|
||||
@NotBlank private String fundStatus; // FUND_TRANSFER_SUCCESS or FUND_TRANSFER_FAILED
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import lombok.Setter;
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CustomParam {
|
||||
public class CustomParamDTO {
|
||||
private String customParamName;
|
||||
private String dataType;
|
||||
private boolean optional;
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class DeviceBlockTag {
|
||||
private String name;
|
||||
private String tagId;
|
||||
private String value;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
||||
public class DispositionsDTO {
|
||||
private String dispositionId;
|
||||
private String dispositionDescr;
|
||||
private String tenantId;
|
||||
}
|
||||
@@ -4,11 +4,13 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class GeneralResp {
|
||||
private String statusCode;
|
||||
private String status;
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
public class TransactionDAO {
|
||||
|
||||
@NotBlank private String txnId;
|
||||
@NotBlank private String refId;
|
||||
|
||||
private String txnNpciId;
|
||||
|
||||
@NotBlank private String orderId;
|
||||
@NotBlank private String billId;
|
||||
@NotBlank private String userType;
|
||||
@NotBlank private String userId;
|
||||
|
||||
@NotNull private Double txnAmount;
|
||||
@NotNull private Double totalTxnAmount;
|
||||
|
||||
@NotBlank private String billerId;
|
||||
@NotBlank private String billerCategory;
|
||||
@NotBlank private String billerName;
|
||||
|
||||
private String clientReqId;
|
||||
private String offUsPay;
|
||||
private String splitPay;
|
||||
private String quickPay;
|
||||
private String paymentMode;
|
||||
|
||||
private Double custConvFee;
|
||||
private String currency;
|
||||
private String status;
|
||||
private String requestedIp;
|
||||
private String customerMobNo;
|
||||
private String macAddress;
|
||||
|
||||
private Double splitPayAmount;
|
||||
private Double couCustConvFee;
|
||||
|
||||
private Boolean settlementVerification;
|
||||
private String fundTxnType;
|
||||
private String reason;
|
||||
|
||||
private List<String> amountTags;
|
||||
private List<String> customerParamsDAOS;
|
||||
private List<String> paymentInformation;
|
||||
|
||||
private List<CustomerParamDAO> customerParamsDAO;
|
||||
|
||||
private String planId;
|
||||
private String planType;
|
||||
|
||||
private LocalDateTime creationDate;
|
||||
private LocalDateTime modifiedDate;
|
||||
|
||||
private Long createdEpochDate;
|
||||
private Long modifiedEpochDate;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
|
||||
public class TransactionDTO {
|
||||
|
||||
@NotBlank private String txnId;
|
||||
@NotBlank private String refId;
|
||||
private String txnNpciId;
|
||||
private String paymentRefId;
|
||||
private String remitterName;
|
||||
|
||||
|
||||
@NotBlank private String orderId;
|
||||
@NotBlank private String billId;
|
||||
@NotBlank private String userType;
|
||||
@NotBlank private String userId;
|
||||
|
||||
@NotNull private Double txnAmount;
|
||||
@NotNull private Double totalTxnAmount;
|
||||
|
||||
@NotBlank private String billerId;
|
||||
@NotBlank private String billerCategory;
|
||||
@NotBlank private String billerName;
|
||||
|
||||
private String clientReqId;
|
||||
private String offUsPay;
|
||||
private String splitPay;
|
||||
private String quickPay;
|
||||
private String paymentMode;
|
||||
private String agentPaymentInformation;
|
||||
|
||||
private Double custConvFee;
|
||||
private String currency;
|
||||
private String status;
|
||||
private String requestedIp;
|
||||
private String customerMobNo;
|
||||
private String macAddress;
|
||||
|
||||
private Double splitPayAmount;
|
||||
private Double couCustConvFee;
|
||||
|
||||
private Boolean settlementVerification;
|
||||
private String fundTxnType;
|
||||
private String reason;
|
||||
|
||||
private List<String> amountTags;
|
||||
private List<String> customerParamsDAOS;
|
||||
private List<String> paymentInformation;
|
||||
private List<DeviceBlockTag> deviceBlockTags;
|
||||
|
||||
|
||||
private List<CustomerParamDAO> customerParamsDAO;
|
||||
|
||||
private String planId;
|
||||
private String planType;
|
||||
|
||||
// ✅ Date fields as String (for JSON compatibility)
|
||||
private String creationDate;
|
||||
private String modifiedDate;
|
||||
|
||||
private Long createdEpochDate;
|
||||
private Long modifiedEpochDate;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.billpaymentservice.bbps.dto.request;
|
||||
|
||||
public class DispositionRequest extends BaseClass {
|
||||
|
||||
}
|
||||
@@ -3,9 +3,11 @@ package com.billpaymentservice.bbps.dto.response;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class BillPaymentResponse {
|
||||
|
||||
private String txnId;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
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.CustomParamDTO;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.entites.CustomerParam;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
@@ -20,5 +19,5 @@ import lombok.Setter;
|
||||
public class CustomParamResp {
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private GeneralResp generalResp;
|
||||
private List<CustomParam> customParamResp;
|
||||
private List<CustomParamDTO> customParamResp;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.billpaymentservice.bbps.dto.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.DispositionsDTO;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class DispositionResponse {
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private GeneralResp generalResp;
|
||||
List<DispositionsDTO> dispositionsList;
|
||||
}
|
||||
+2
-2
@@ -2,7 +2,7 @@ package com.billpaymentservice.bbps.dto.response;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.AgentFundTransfer;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.dto.TransactionDAO;
|
||||
import com.billpaymentservice.bbps.dto.TransactionDTO;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Getter;
|
||||
@@ -13,7 +13,7 @@ import lombok.Setter;
|
||||
public class TransactionStatusResponse {
|
||||
|
||||
@JsonProperty("transactionDAO")
|
||||
private TransactionDAO transactionDAO;
|
||||
private TransactionDTO transactionDAO;
|
||||
|
||||
@JsonProperty("agentFundTransfer")
|
||||
private AgentFundTransfer agentFundTransfer;
|
||||
|
||||
@@ -5,10 +5,12 @@ import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@ToString
|
||||
@Table(name = "additional_info")
|
||||
public class AdditionalInfo {
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.billpaymentservice.bbps.entites;
|
||||
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.List;
|
||||
|
||||
import com.billpaymentservice.bbps.entites.BillerResponseParams;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@Entity
|
||||
@Table(name = "amount_option")
|
||||
@@ -15,9 +13,9 @@ import com.billpaymentservice.bbps.entites.BillerResponseParams;
|
||||
public class AmountOption {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "amount_option_id")
|
||||
private Long id;
|
||||
@JsonProperty("amountOptionId") // ✅ JSON field map karo
|
||||
private String amountOptionId; // ✅ String type, manual ID
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(
|
||||
@@ -31,4 +29,4 @@ public class AmountOption {
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "biller_response_id", nullable = false)
|
||||
private BillerResponseParams billerResponseParams;
|
||||
}
|
||||
}
|
||||
@@ -147,8 +147,10 @@ public class BillerDetails {
|
||||
@OneToMany(mappedBy = "biller", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<AdditionalInfo> billerAdditionalInfos;
|
||||
|
||||
@OneToMany(mappedBy = "biller", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<AdditionalInfo> billerAdditionalInfoPayments;
|
||||
/*
|
||||
* @OneToMany(mappedBy = "biller", cascade = CascadeType.ALL, orphanRemoval =
|
||||
* true) private List<AdditionalInfo> billerAdditionalInfoPayments;
|
||||
*/
|
||||
|
||||
@OneToMany(mappedBy = "biller", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<InterchangeFeeConf> interchangeFeeConves;
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import lombok.ToString;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import lombok.Getter;
|
||||
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@ToString
|
||||
@Table(name = "biller_plan_response_params")
|
||||
public class BillerPlanResponseParams {
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.billpaymentservice.bbps.entites;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "custom_param")
|
||||
public class CustomParam {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "custom_param_name")
|
||||
private String customParamName;
|
||||
|
||||
@Column(name = "data_type")
|
||||
private String dataType;
|
||||
|
||||
@Column(name = "optional")
|
||||
private Boolean optional;
|
||||
|
||||
@Column(name = "min_length")
|
||||
private Integer minLength;
|
||||
|
||||
@Column(name = "max_length")
|
||||
private Integer maxLength;
|
||||
|
||||
@Column(name = "regex")
|
||||
private String regex;
|
||||
|
||||
@Column(name = "visibility")
|
||||
private Boolean visibility;
|
||||
|
||||
|
||||
}
|
||||
@@ -3,12 +3,14 @@ package com.billpaymentservice.bbps.entites;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@ToString
|
||||
@Table(name = "customer_param_groups")
|
||||
public class CustomerParamGroups {
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.billpaymentservice.bbps.entites;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "disposition_details")
|
||||
@ToString
|
||||
public class DispositionDetails {
|
||||
|
||||
@Id
|
||||
@Column(name = "disposition_id", nullable = false, unique = true)
|
||||
private String dispositionId; // UUID type string
|
||||
|
||||
@Column(name = "disposition_descr", nullable = false)
|
||||
private String dispositionDescr;
|
||||
|
||||
@Column(name = "tenant_id")
|
||||
private String tenantId;
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
import lombok.ToString;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import lombok.Getter;
|
||||
@@ -15,6 +14,7 @@ import java.util.List;
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@ToString
|
||||
@Table(name = "interchange_fee")
|
||||
public class InterchangeFee {
|
||||
|
||||
|
||||
@@ -4,18 +4,20 @@ import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@ToString
|
||||
@Table(name = "payment_channel")
|
||||
public class PaymentChannel {
|
||||
|
||||
@Id
|
||||
@Id
|
||||
@Column(name = "payment_channel_limit_id")
|
||||
@JsonProperty("paymentChannelLimitId") // 👈 Map JSON field to this property
|
||||
private String id; // Primary key (manual, not auto-generated)
|
||||
private String paymentChannelLimitId; // Primary key (manual, not auto-generated)
|
||||
|
||||
@NotBlank(message = "Payment channel is required")
|
||||
@Column(name = "payment_channel", nullable = false)
|
||||
|
||||
@@ -2,15 +2,27 @@ package com.billpaymentservice.bbps.entites;
|
||||
|
||||
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.PositiveOrZero;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "biller_payment_modes")
|
||||
@ToString
|
||||
public class PaymentMode {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.billpaymentservice.bbps.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.billpaymentservice.bbps.entites.DispositionDetails;
|
||||
|
||||
public interface DispositionRepository extends JpaRepository<DispositionDetails,String> {
|
||||
|
||||
}
|
||||
@@ -19,4 +19,6 @@ public interface MasterDataService {
|
||||
|
||||
public ResponseModel getContactMaster(ContactMasterRequest contactMasterRequest);
|
||||
|
||||
public ResponseModel getDispositionDetails();
|
||||
|
||||
}
|
||||
|
||||
@@ -49,132 +49,145 @@ public class AgentServiceImpl implements AgentService {
|
||||
this.beneficiaryDetailsRepository=beneficiaryDetailsRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) {
|
||||
String url = agentDtaUrl+BBPSConstant.BILL_FETCH_INTI;
|
||||
System.out.println(url);
|
||||
|
||||
BharatConnectMaster headersData=beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key",headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
@Override
|
||||
public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) {
|
||||
String url = agentDtaUrl + BBPSConstant.BILL_FETCH_INTI;
|
||||
System.out.println(url);
|
||||
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
|
||||
ResponseModel responseModel = new ResponseModel();
|
||||
|
||||
ResponseModel responseModel = new ResponseModel();
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
// ✅ 1st API Call
|
||||
String json = objectMapper.writeValueAsString(fetchBillRequest);
|
||||
Map<String, String> responseMap = httpService.postRequest(url, json, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
|
||||
// ✅ Convert request to JSON
|
||||
String json = objectMapper.writeValueAsString(fetchBillRequest);
|
||||
log.info("📦 1st API Response: {}", responseData);
|
||||
|
||||
// ✅ Call the API using httpService
|
||||
Map<String, String> responseMap = httpService.postRequest(url, json, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
if (responseData == null || responseData.isEmpty()) {
|
||||
throw new CustomException("Empty response from BBPS server");
|
||||
}
|
||||
|
||||
log.info("📦 Bill Fetch API Response: {}", responseData);
|
||||
|
||||
if (responseData == null || responseData.isEmpty()) {
|
||||
throw new CustomException("Empty response from BBPS server");
|
||||
}
|
||||
|
||||
// ✅ Convert JSON string → Map
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
// ✅ Validate generalResp
|
||||
if (!dataMap.containsKey("genericResponse")) {
|
||||
throw new CustomException("Invalid response structure from BBPS");
|
||||
}
|
||||
|
||||
// ✅ Convert to your custom DTO
|
||||
FetchBillResponse fetchBillResponse = objectMapper.convertValue(dataMap, FetchBillResponse.class);
|
||||
GeneralResponse generalResponse = fetchBillResponse.getGenericResponse();
|
||||
//
|
||||
//start a new thread here
|
||||
helper.startPolling(fetchBillResponse,
|
||||
res -> {
|
||||
BillFetchByBillIdRequest pollReq = new BillFetchByBillIdRequest();
|
||||
pollReq.setBillId(res.getBillId());
|
||||
return fetchBillById(pollReq);
|
||||
},
|
||||
3, // interval in seconds
|
||||
15 // total time in seconds
|
||||
);
|
||||
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
if (!dataMap.containsKey("genericResponse")) {
|
||||
throw new CustomException("Invalid response structure from BBPS");
|
||||
}
|
||||
|
||||
// ✅ Build final ResponseModel
|
||||
responseModel = new ResponseModel(
|
||||
generalResponse.getMessage(),
|
||||
generalResponse.getStatus(),
|
||||
Integer.parseInt(generalResponse.getStatusCode()),
|
||||
fetchBillResponse
|
||||
);
|
||||
FetchBillResponse fetchBillResponse = objectMapper.convertValue(dataMap, FetchBillResponse.class);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
|
||||
responseModel.setStatus("500");
|
||||
responseModel.setMessage("Exception occurred");
|
||||
responseModel.setData(e.getMessage());
|
||||
}
|
||||
// ✅ IMMEDIATE 2nd API CALL (SYNCHRONOUS)
|
||||
BillFetchByBillIdRequest pollReq = new BillFetchByBillIdRequest();
|
||||
pollReq.setBillId(fetchBillResponse.getBillId());
|
||||
|
||||
// ✅ This will wait for the response
|
||||
ResponseModel secondApiResponse = fetchBillById(pollReq);
|
||||
|
||||
// ✅ Return directly the second API response
|
||||
return secondApiResponse;
|
||||
|
||||
return responseModel;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
|
||||
responseModel.setStatus("500");
|
||||
responseModel.setMessage("Exception occurred");
|
||||
responseModel.setData(e.getMessage());
|
||||
return responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest) {
|
||||
|
||||
@Override
|
||||
public ResponseModel fetchBillById(BillFetchByBillIdRequest billFetchByBillIdRequest) {
|
||||
|
||||
String billId = billFetchByBillIdRequest.getBillId();
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID+billId;
|
||||
System.out.print(fullUrl);
|
||||
|
||||
BharatConnectMaster headersData=beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key",headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl,headers);
|
||||
String responseData = responseMap.get("data");
|
||||
log.info("data is :{}", responseData);
|
||||
|
||||
String billId = billFetchByBillIdRequest.getBillId();
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + "1ced7566-1add-4e01-9ed6-04cd67ac9684";
|
||||
// String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID + billId;
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
System.out.print(fullUrl);
|
||||
|
||||
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;
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
int maxWaitTimeMs = 40000; // 40 seconds
|
||||
int intervalMs = 6000; // 3 seconds
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
while (true) {
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
log.info("data is :{}", responseData);
|
||||
|
||||
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")),
|
||||
String.valueOf(dataMap.get("status")),
|
||||
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))),
|
||||
String.valueOf(dataMap.get("remarks"))
|
||||
);
|
||||
}
|
||||
|
||||
BillDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillDataResponse.class);
|
||||
GeneralResp generalResp = responseWrapper.getGenericResponse();
|
||||
|
||||
String status = generalResp.getStatus();
|
||||
|
||||
// ✅ Agar status "IN_PROGRESS" hai to wait and retry
|
||||
if ("INPROGRESS".equalsIgnoreCase(status)) {
|
||||
if (System.currentTimeMillis() - startTime > maxWaitTimeMs) {
|
||||
// 40 sec ke baad bhi IN_PROGRESS -> Timeout exception
|
||||
throw new CustomException("Timeout waiting for bill fetch completion",
|
||||
"FAILED", 408, "Bill fetch still in progress after 40 seconds");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(intervalMs);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new CustomException("Thread interrupted during retry");
|
||||
}
|
||||
|
||||
log.info("Bill still in progress... retrying after {} seconds", (intervalMs / 1000));
|
||||
continue; // retry again
|
||||
}
|
||||
|
||||
// ✅ Agar status IN_PROGRESS nahi hai (e.g., SUCCESS / FAILED), return result
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,17 +5,16 @@ import java.util.HashMap;
|
||||
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.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.BillerDTO;
|
||||
import com.billpaymentservice.bbps.dto.DispositionsDTO;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.dto.MasterApiResponse;
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
@@ -29,12 +28,19 @@ import com.billpaymentservice.bbps.dto.response.BillerResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.CategoryResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.ContactMasterResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.CustomParamResp;
|
||||
import com.billpaymentservice.bbps.dto.response.DispositionResponse;
|
||||
import com.billpaymentservice.bbps.entites.AmountOption;
|
||||
import com.billpaymentservice.bbps.entites.BBPSMerchantValidation;
|
||||
import com.billpaymentservice.bbps.entites.BillPayment;
|
||||
import com.billpaymentservice.bbps.entites.BillerDetails;
|
||||
import com.billpaymentservice.bbps.entites.BillerResponseParams;
|
||||
import com.billpaymentservice.bbps.entites.DispositionDetails;
|
||||
import com.billpaymentservice.bbps.entites.InterchangeFee;
|
||||
import com.billpaymentservice.bbps.entites.InterchangeFeeDetail;
|
||||
import com.billpaymentservice.bbps.exception.AppException;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.BillerDataRepository;
|
||||
import com.billpaymentservice.bbps.repository.DispositionRepository;
|
||||
import com.billpaymentservice.bbps.repository.MerchantRepository;
|
||||
import com.billpaymentservice.bbps.service.MasterDataService;
|
||||
import com.billpaymentservice.bbps.util.BBPSConstant;
|
||||
@@ -55,6 +61,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
|
||||
private MerchantRepository merchantRegisterRepo;
|
||||
private HttpClientApi httpClientApi;
|
||||
private final DispositionRepository dispositionRepository;
|
||||
private Helper helper;
|
||||
private final BillerDataRepository billerDataRespository;
|
||||
|
||||
@@ -68,70 +75,109 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
HttpService httpService,
|
||||
HttpClientApi httpClientApi,
|
||||
Helper helper,
|
||||
BillerDataRepository billerDataRespository
|
||||
BillerDataRepository billerDataRespository,
|
||||
DispositionRepository dispositionRepository
|
||||
) {
|
||||
this.merchantRegisterRepo = merchantRegisterRepo;
|
||||
this.httpService = httpService;
|
||||
this.httpClientApi = httpClientApi;
|
||||
this.helper = helper;
|
||||
this.billerDataRespository=billerDataRespository;
|
||||
this.dispositionRepository=dispositionRepository;
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public ResponseModel getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
|
||||
|
||||
String billerId = billerDetailRequest.getBillerId();
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL+billerId;
|
||||
|
||||
String billerId = billerDetailRequest.getBillerId();
|
||||
String fullUrl = masterRegisterUrl + BBPSConstant.BILLER_DATA_FETCH_URL+billerId;
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
||||
String responseData = responseMap.get("data");
|
||||
log.info("data is :{}", responseData);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
||||
String responseData = responseMap.get("data");
|
||||
log.info("data is :{}", responseData);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
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("message")), // message
|
||||
String.valueOf(dataMap.get("status")), // status
|
||||
Integer.parseInt(String.valueOf(dataMap.get("statusCode"))), // statusCode (int)
|
||||
String.valueOf(dataMap.get("remarks")) );
|
||||
}
|
||||
|
||||
try {
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
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")) );
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
// Manually set parent reference
|
||||
if (entity.getBillerPaymentModes() != null) {
|
||||
entity.getBillerPaymentModes().forEach(m -> m.setBiller(entity));
|
||||
}
|
||||
if (entity.getBillerPaymentChannels() != null) {
|
||||
entity.getBillerPaymentChannels().forEach(c -> c.setBiller(entity));
|
||||
}
|
||||
if (entity.getBillerCustomerParams() != null) {
|
||||
entity.getBillerCustomerParams().forEach(p -> p.setBiller(entity));
|
||||
}
|
||||
if (entity.getBillerAdditionalInfos() != null) {
|
||||
entity.getBillerAdditionalInfos().forEach(a -> a.setBiller(entity));
|
||||
}
|
||||
if (entity.getInterchangeFees() != null) {
|
||||
for (InterchangeFee fee : entity.getInterchangeFees()) {
|
||||
fee.setBiller(entity); // link InterchangeFee → BillerDetails
|
||||
|
||||
if (fee.getInterchangeFeeDetails() != null) {
|
||||
for (InterchangeFeeDetail detail : fee.getInterchangeFeeDetails()) {
|
||||
detail.setInterchangeFee(fee); // link InterchangeFeeDetail → InterchangeFee
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(entity);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
billerDataRespository.save(entity);
|
||||
}
|
||||
else {
|
||||
LOGGER.warn("No biller found in response to save.");
|
||||
}
|
||||
|
||||
if (entity.getInterchangeFeeConves() != null) {
|
||||
entity.getInterchangeFeeConves().forEach(fc -> fc.setBiller(entity));
|
||||
}
|
||||
|
||||
|
||||
ResponseModel responseModel=new ResponseModel( generalResp.getMessage(),
|
||||
generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()),
|
||||
responseWrapper);
|
||||
|
||||
return responseModel;
|
||||
// For OneToOne relationships
|
||||
if (entity.getCustomerParamGroups() != null)
|
||||
entity.getCustomerParamGroups().setBiller(entity);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
if (entity.getBillerPlanResponseParams() != null)
|
||||
entity.getBillerPlanResponseParams().setBiller(entity);
|
||||
|
||||
// 🔥🔥🔥 YEH MISSING CODE ADD KARO 🔥🔥🔥
|
||||
if (entity.getBillerResponseParams() != null) {
|
||||
BillerResponseParams responseParams = entity.getBillerResponseParams();
|
||||
responseParams.setBiller(entity); // Parent reference
|
||||
|
||||
// 🔥 AMOUNT OPTIONS KE RELATIONSHIPS SET KARO
|
||||
if (responseParams.getAmountOptions() != null) {
|
||||
for (AmountOption option : responseParams.getAmountOptions()) {
|
||||
option.setBillerResponseParams(responseParams); // YEH MISSING THA
|
||||
}
|
||||
}
|
||||
}
|
||||
billerDataRespository.save(entity);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,4 +320,55 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
|
||||
return new ResponseModel();
|
||||
}
|
||||
@Override
|
||||
public ResponseModel getDispositionDetails() {
|
||||
String fullUrl=masterRegisterUrl+BBPSConstant.DISPOSTION_URL;
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl);
|
||||
String responseData = responseMap.get("data");
|
||||
|
||||
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("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);
|
||||
|
||||
return responseModel;
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
|
||||
// ✅ Convert to your custom DTO
|
||||
BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class);
|
||||
System.out.print(billPaymentResponse);
|
||||
GeneralResp generalResponse = billPaymentResponse.getGenericResponse();
|
||||
//
|
||||
// start a new thread here
|
||||
@@ -109,15 +110,16 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
* return fetchBillById(pollReq); }, 3, // interval in seconds 15 // total time
|
||||
* in seconds );
|
||||
*/
|
||||
|
||||
ModelMapper mapper = new ModelMapper();
|
||||
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
|
||||
BillPayment entity = mapper.map(billPaymentResponse, BillPayment.class);
|
||||
paymentRepository.save(entity);
|
||||
|
||||
// ✅ Build final ResponseModel
|
||||
responseModel = new ResponseModel(generalResponse.getMessage(), generalResponse.getStatus(),
|
||||
Integer.parseInt(generalResponse.getStatusCode()), billPaymentResponse);
|
||||
|
||||
TransactionStatusRequest transactionStatusRequest=new TransactionStatusRequest();
|
||||
//call the checkTransactionStatus
|
||||
transactionStatusRequest.setTxnId(billPaymentResponse.getTxnId());
|
||||
System.out.println(transactionStatusRequest);
|
||||
responseModel= checkTrasactionStatus(transactionStatusRequest);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("❌ Exception in initiateBillFetch(): {}", e.getMessage(), e);
|
||||
responseModel.setStatus("500");
|
||||
@@ -131,49 +133,88 @@ public class PaymentServiceImpl implements PaymentService {
|
||||
@Override
|
||||
public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) {
|
||||
|
||||
String url=paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL+transactionStatusRequest.getTxnId();
|
||||
|
||||
BharatConnectMaster headersData=beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key",headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(url,headers);
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("data is :{}", responseData);
|
||||
|
||||
String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId();
|
||||
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
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")) );
|
||||
}
|
||||
|
||||
TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TransactionStatusResponse.class);
|
||||
|
||||
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
||||
|
||||
ResponseModel responseModel=new ResponseModel( generalResp.getMessage(),
|
||||
generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()),
|
||||
responseWrapper);
|
||||
|
||||
return responseModel;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
// ✅ Polling configuration
|
||||
long startTime = System.currentTimeMillis();
|
||||
long maxWaitTimeMs = 40000; // 40 seconds timeout
|
||||
long intervalMs = 5000; // retry every 5 seconds
|
||||
|
||||
while (true) {
|
||||
Map<String, String> responseMap = httpService.getRequest(url, headers);
|
||||
String responseData = responseMap.get("data");
|
||||
LOGGER.info("Transaction status response data: {}", responseData);
|
||||
|
||||
try {
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
// If genericResponse key missing, throw exception
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
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"))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Convert into proper DTO
|
||||
TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TransactionStatusResponse.class);
|
||||
|
||||
GeneralResp generalResp = responseWrapper.getGeneralResp();
|
||||
|
||||
String status = generalResp.getStatus();
|
||||
LOGGER.info("Current transaction status: {}", status);
|
||||
|
||||
// ✅ If IN_PROGRESS → wait & retry
|
||||
if ("INPROGRESS".equalsIgnoreCase(status)) {
|
||||
|
||||
if (System.currentTimeMillis() - startTime > maxWaitTimeMs) {
|
||||
// Timeout after 40 sec
|
||||
throw new CustomException(
|
||||
"Timeout waiting for transaction completion",
|
||||
"FAILED",
|
||||
408,
|
||||
"Transaction still in progress after 40 seconds"
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(intervalMs);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new CustomException("Thread interrupted during retry");
|
||||
}
|
||||
|
||||
LOGGER.info("Transaction still IN_PROGRESS... retrying after {} seconds", (intervalMs / 1000));
|
||||
continue; // retry
|
||||
}
|
||||
|
||||
// ✅ If status is SUCCESS / FAILED / etc. → return response
|
||||
ResponseModel responseModel = new ResponseModel(
|
||||
generalResp.getMessage(),
|
||||
generalResp.getStatus(),
|
||||
Integer.parseInt(generalResp.getStatusCode()),
|
||||
responseWrapper
|
||||
);
|
||||
|
||||
return responseModel;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -32,5 +32,6 @@ public class BBPSConstant {
|
||||
public static final String BILL_FETCH_BY_ID="/couapp/bills/fetch/byId?billId=";
|
||||
public static final String PAYMENT_URL="/agent/bills/payment";
|
||||
public static final String CHECK_TRANSACTION_URL="/transactions/payment/byTxnId?txnId=";
|
||||
public static final String DISPOSTION_URL="/disposition";
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ server.port=9090
|
||||
# JPA & Hibernate
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
spring.jpa.properties.hibernate.default_schema=public
|
||||
|
||||
|
||||
# DataSource
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/BBPS
|
||||
|
||||
Reference in New Issue
Block a user