diff --git a/src/main/java/com/billpaymentservice/bbps/config/SecurityConfig.java b/src/main/java/com/billpaymentservice/bbps/config/SecurityConfig.java index 15f9c4b..a35a36d 100644 --- a/src/main/java/com/billpaymentservice/bbps/config/SecurityConfig.java +++ b/src/main/java/com/billpaymentservice/bbps/config/SecurityConfig.java @@ -39,7 +39,9 @@ public class SecurityConfig { "/swagger-resources/**", "/webjars/**", "/error") - .permitAll().requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() + .permitAll() + .requestMatchers("/payment/callback/startPayment") + .permitAll().requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() .anyRequest().authenticated()) .exceptionHandling(ex -> ex.authenticationEntryPoint(jwtAuthenticationEntryPoint)) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)); diff --git a/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java b/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java index a9edc93..54ec063 100644 --- a/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java +++ b/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java @@ -73,33 +73,34 @@ public class AgentController { ResponseModel response = agentService.initiateBillValidateByBillId(billRequest); return ResponseEntity.ok(response); } - + @PostMapping(value = "/fetchBillByClientReqId", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity fetchBillByClientReqId( - @Validated @RequestBody BillFetchByClientIdRequest billFetchByClientIdRequest) { + @Validated @RequestBody BillFetchByClientIdRequest billFetchByClientIdRequest) { ResponseModel response = agentService.fetchBillByClientReqId(billFetchByClientIdRequest); return ResponseEntity.ok(response); } - + @PostMapping(value = "/fetchBillValidateByClientReqId", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity fetchBillValidateByClientReqId( - @Validated @RequestBody BillValidateByClientIdRequest billValidateByClientIdRequest) { + @Validated @RequestBody BillValidateByClientIdRequest billValidateByClientIdRequest) { ResponseModel response = agentService.fetchBillValidateByClientReqId(billValidateByClientIdRequest); return ResponseEntity.ok(response); } - - @PostMapping(value="/callback/billFetch", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity handleBillFetchCallback(@RequestBody BillDataResponse billDataResponse) { - ResponseModel genralResp=agentService.processBillFetchCallback(billDataResponse); + + @PostMapping(value = "/callback/billFetch", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity handleBillFetchCallback(@RequestBody BillDataResponse billDataResponse) { + ResponseModel genralResp = agentService.processBillFetchCallback(billDataResponse); // Return a response indicating successful receipt return ResponseEntity.ok(genralResp); } - - @PostMapping(value="/callback/billValidate", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity handleBillValidateCallback(@RequestBody FetchBillValidateResponse fetchBillValidateResponse) { - ResponseModel genralResp=agentService.processBillValidateCallback(fetchBillValidateResponse); + + @PostMapping(value = "/callback/billValidate", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity handleBillValidateCallback( + @RequestBody FetchBillValidateResponse fetchBillValidateResponse) { + ResponseModel genralResp = agentService.processBillValidateCallback(fetchBillValidateResponse); // Return a response indicating successful receipt return ResponseEntity.ok(genralResp); } diff --git a/src/main/java/com/billpaymentservice/bbps/dto/auth/AuthResponse.java b/src/main/java/com/billpaymentservice/bbps/dto/auth/AuthResponse.java index af3dbec..15a3e6e 100644 --- a/src/main/java/com/billpaymentservice/bbps/dto/auth/AuthResponse.java +++ b/src/main/java/com/billpaymentservice/bbps/dto/auth/AuthResponse.java @@ -13,19 +13,20 @@ import lombok.Setter; @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) public class AuthResponse { - private boolean success; - private String message; - private boolean userExists; - private UserDto user; - private String token; + private boolean success; + private String message; + private boolean userExists; + private Object user; + private String token; - public AuthResponse(boolean success, String message, boolean userExists, UserDto user) { - this.success = success; - this.message = message; - this.userExists = userExists; - this.user = user; - } - public AuthResponse(boolean success, String message, String token) { + public AuthResponse(boolean success, String message, String token, Object user) { + this.success = success; + this.message = message; + this.token = token; + this.user = user; + } + + public AuthResponse(boolean success, String message, String token) { this.success = success; this.message = message; this.token = token; diff --git a/src/main/java/com/billpaymentservice/bbps/dto/auth/UserDto.java b/src/main/java/com/billpaymentservice/bbps/dto/auth/UserDto.java index 003f3b0..3765679 100644 --- a/src/main/java/com/billpaymentservice/bbps/dto/auth/UserDto.java +++ b/src/main/java/com/billpaymentservice/bbps/dto/auth/UserDto.java @@ -10,7 +10,7 @@ import lombok.Setter; @NoArgsConstructor @AllArgsConstructor public class UserDto { - private Long id; + private String userId; private String mobile; private String name; private String email; diff --git a/src/main/java/com/billpaymentservice/bbps/dto/request/AllMasterOptionsRequest.java b/src/main/java/com/billpaymentservice/bbps/dto/request/AllMasterOptionsRequest.java index 00147bc..7cdbb19 100644 --- a/src/main/java/com/billpaymentservice/bbps/dto/request/AllMasterOptionsRequest.java +++ b/src/main/java/com/billpaymentservice/bbps/dto/request/AllMasterOptionsRequest.java @@ -1,5 +1,7 @@ package com.billpaymentservice.bbps.dto.request; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; @@ -7,4 +9,10 @@ import lombok.Setter; @Setter public class AllMasterOptionsRequest extends BaseClass { + private Integer pageNo = 0; + + @NotNull(message = "pageEnd is required") + @Min(value = 1, message = "pageEnd must be greater than 0") + private Integer pageSize; + } diff --git a/src/main/java/com/billpaymentservice/bbps/dto/request/PaymentHistoryRequest.java b/src/main/java/com/billpaymentservice/bbps/dto/request/PaymentHistoryRequest.java index f6621b9..6b6f5dc 100644 --- a/src/main/java/com/billpaymentservice/bbps/dto/request/PaymentHistoryRequest.java +++ b/src/main/java/com/billpaymentservice/bbps/dto/request/PaymentHistoryRequest.java @@ -1,5 +1,7 @@ package com.billpaymentservice.bbps.dto.request; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; @@ -7,4 +9,10 @@ import lombok.Setter; @Setter public class PaymentHistoryRequest extends BaseClass { + private Integer pageNo = 0; + + @NotNull(message = "pageEnd is required") + @Min(value = 1, message = "pageEnd must be greater than 0") + private Integer pageSize; + } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/AmountOptionDetails.java b/src/main/java/com/billpaymentservice/bbps/entites/AmountOptionDetails.java index df22ecd..8e95e06 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/AmountOptionDetails.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/AmountOptionDetails.java @@ -35,4 +35,7 @@ public class AmountOptionDetails { @Column(name = "txn_id") private String txnId; + @Column(name = "user_id") + private String userId; + } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/BillInitiate.java b/src/main/java/com/billpaymentservice/bbps/entites/BillInitiate.java index 504bbcd..6684e49 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/BillInitiate.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/BillInitiate.java @@ -1,4 +1,5 @@ package com.billpaymentservice.bbps.entites; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; @@ -13,14 +14,17 @@ import lombok.NoArgsConstructor; @Entity @Table(name = "bill_initiate") public class BillInitiate { - @Id - @Column(name = "req_id") - private String reqId; - - @Column(name = "bill_id", nullable = false) - private String billId; - - @Column(name = "txn_id") - private String txnId; - + @Id + @Column(name = "req_id") + private String reqId; + + @Column(name = "bill_id", nullable = false) + private String billId; + + @Column(name = "txn_id") + private String txnId; + + @Column(name = "client_user_id") + private String clientUserId; + } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/BillMaster.java b/src/main/java/com/billpaymentservice/bbps/entites/BillMaster.java index 67f70a9..f60d49c 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/BillMaster.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/BillMaster.java @@ -1,7 +1,9 @@ package com.billpaymentservice.bbps.entites; + import java.util.List; import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -23,27 +25,28 @@ import lombok.Setter; @NoArgsConstructor public class BillMaster { - @Id - private String billId; // primary key + @Id + private String billId; // primary key - private String reqId; // client se aaya hua - private String txnId; // system-generated - private String refId; - private String billerId; - private String status; - private String actionType; - private String userId; - @OneToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "biller_response_id") - private BillerResponse billerResponse; - @OneToMany(mappedBy = "billMaster", cascade = CascadeType.ALL) - private List additionalInfo; - @OneToMany(mappedBy = "billMaster", cascade = CascadeType.ALL) - private List customerParams; - private String creationDate; - private String modifiedDate; - private Long createdEpochDate; - private Long modifiedEpochDate; + private String reqId; // client se aaya hua + private String txnId; // system-generated + private String refId; + private String billerId; + private String status; + private String actionType; + private String clientUserId; + private String userId; + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "biller_response_id") + private BillerResponse billerResponse; + @OneToMany(mappedBy = "billMaster", cascade = CascadeType.ALL) + private List additionalInfo; + @OneToMany(mappedBy = "billMaster", cascade = CascadeType.ALL) + private List customerParams; + private String creationDate; + private String modifiedDate; + private Long createdEpochDate; + private Long modifiedEpochDate; - // getters and setters + // getters and setters } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/BillValidation.java b/src/main/java/com/billpaymentservice/bbps/entites/BillValidation.java index d4a01dd..f03cb4b 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/BillValidation.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/BillValidation.java @@ -1,6 +1,5 @@ package com.billpaymentservice.bbps.entites; - import java.util.List; import jakarta.persistence.*; @@ -15,47 +14,56 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public class BillValidation { - @Id - @Column(name = "bill_id", nullable = false, length = 100) - private String billId; + @Id + @Column(name = "bill_id", nullable = false, length = 100) + private String billId; - @Column(name = "ref_id", length = 100) - private String refId; + @Column(name = "ref_id", length = 100) + private String refId; - @Column(name = "biller_id", length = 100) - private String billerId; + @Column(name = "biller_id", length = 100) + private String billerId; - @Column(name = "status", length = 100) - private String status; + @Column(name = "status", length = 100) + private String status; - @Column(name = "action_type", length = 100) - private String actionType; + @Column(name = "action_type", length = 100) + private String actionType; - @Column(name = "user_id", length = 100) - private String userId; + @Column(name = "user_id", length = 100) + private String userId; - @Column(name = "biller_response", columnDefinition = "TEXT") - private String billerResponse; + @Column(name = "biller_response", columnDefinition = "TEXT") + private String billerResponse; - @OneToMany(mappedBy = "bill", cascade = CascadeType.ALL, fetch = FetchType.LAZY) - private List additionalInfo; + @OneToMany(mappedBy = "bill", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List additionalInfo; - // 👇 Proper nested customer params (OneToMany) - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "bill") - private List customerParams; + // 👇 Proper nested customer params (OneToMany) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "bill") + private List customerParams; - @Column(name = "plan_info_daos", columnDefinition = "TEXT") - private String planInfoDaos; + @Column(name = "plan_info_daos", columnDefinition = "TEXT") + private String planInfoDaos; - @Column(name = "creation_date", length = 50) - private String creationDate; + @Column(name = "creation_date", length = 50) + private String creationDate; - @Column(name = "modified_date", length = 50) - private String modifiedDate; + @Column(name = "modified_date", length = 50) + private String modifiedDate; - @Column(name = "created_epoch_date", length = 50) - private String createdEpochDate; + @Column(name = "created_epoch_date", length = 50) + private String createdEpochDate; - @Column(name = "modified_epoch_date", length = 50) - private String modifiedEpochDate; + @Column(name = "modified_epoch_date", length = 50) + private String modifiedEpochDate; + + @Column(name = "txn_id") + private String txnId; + + @Column(name = "req_id") + private String reqId; + + @Column(name = "client_user_id") + private String clientUserId; } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/CategoryResponseList.java b/src/main/java/com/billpaymentservice/bbps/entites/CategoryResponseList.java index 0418e3a..a3a8a4c 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/CategoryResponseList.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/CategoryResponseList.java @@ -30,4 +30,7 @@ public class CategoryResponseList extends Auditable { @Column(name = "txn_id") private String txnId; + @Column(name = "user_id") + private String userId; + } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/ComplainStatus.java b/src/main/java/com/billpaymentservice/bbps/entites/ComplainStatus.java index 1b980f9..d6a64aa 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/ComplainStatus.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/ComplainStatus.java @@ -68,4 +68,7 @@ public class ComplainStatus extends Auditable { @Column(name = "txn_id") private String txnId; + + @Column(name = "user_id") + private String userId; } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/ComplaintHistory.java b/src/main/java/com/billpaymentservice/bbps/entites/ComplaintHistory.java index 3661c47..9fed60c 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/ComplaintHistory.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/ComplaintHistory.java @@ -23,25 +23,27 @@ public class ComplaintHistory extends Auditable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long id; - @Column(name="history_id") + @Column(name = "history_id") private String historyId; - - @Column(name="ticket_id") + + @Column(name = "ticket_id") private String ticketId; - - @Column(name="time") + + @Column(name = "time") private String time; - - @Column(name="history_status") + + @Column(name = "history_status") private String historyStatus; - + @Column(name = "txn_id") private String txnId; @Column(name = "req_id") private String reqId; - + + @Column(name = "user_id") + private String userId; } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/ComplaintResponseEntity.java b/src/main/java/com/billpaymentservice/bbps/entites/ComplaintResponseEntity.java index bcecfbd..a3cad8e 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/ComplaintResponseEntity.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/ComplaintResponseEntity.java @@ -10,10 +10,12 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import lombok.Getter; import lombok.Setter; +import lombok.ToString; @Entity @Getter @Setter +@ToString @Table(name = "complaint_responses") public class ComplaintResponseEntity extends Auditable { diff --git a/src/main/java/com/billpaymentservice/bbps/entites/ComplaintStatusDetails.java b/src/main/java/com/billpaymentservice/bbps/entites/ComplaintStatusDetails.java index b54549a..2b07d00 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/ComplaintStatusDetails.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/ComplaintStatusDetails.java @@ -15,18 +15,21 @@ import lombok.Setter; @Getter @Setter @Table(name = "view_ticket_status") -public class ComplaintStatusDetails extends Auditable{ +public class ComplaintStatusDetails extends Auditable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - + @Column(name = "req_id") private String reqId; @Column(name = "txn_id") private String systemTxnId; - + + @Column(name = "user_id") + private String userId; + @Column(name = "total_elements") private String totalElements; diff --git a/src/main/java/com/billpaymentservice/bbps/entites/CustomerParamGroupById.java b/src/main/java/com/billpaymentservice/bbps/entites/CustomerParamGroupById.java index 577dd4d..6055f55 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/CustomerParamGroupById.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/CustomerParamGroupById.java @@ -56,4 +56,6 @@ public class CustomerParamGroupById extends Auditable { @Column(name = "txn_id") private String txnId; + @Column(name = "user_id") + private String userId; } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/DispositionDetails.java b/src/main/java/com/billpaymentservice/bbps/entites/DispositionDetails.java index a1e2126..b3ecd8b 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/DispositionDetails.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/DispositionDetails.java @@ -15,13 +15,22 @@ import lombok.ToString; @ToString public class DispositionDetails { - @Id - @Column(name = "disposition_id", nullable = false, unique = true) - private String dispositionId; // UUID type string + @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 = "disposition_descr", nullable = false) + private String dispositionDescr; - @Column(name = "tenant_id") - private String tenantId; + @Column(name = "tenant_id") + private String tenantId; + + @Column(name = "req_id") + private String reqId; + + @Column(name = "txn_id") + private String txnId; + + @Column(name = "user_id") + private String userId; } \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/entites/PaymentInitiate.java b/src/main/java/com/billpaymentservice/bbps/entites/PaymentInitiate.java index b2e1a84..6ead1a4 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/PaymentInitiate.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/PaymentInitiate.java @@ -8,7 +8,6 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; - @Data @AllArgsConstructor @NoArgsConstructor @@ -16,22 +15,25 @@ import lombok.NoArgsConstructor; @Table(name = "payment_initiate") public class PaymentInitiate { - @Id - @Column(name = "req_id") - private String reqId; + @Id + @Column(name = "req_id") + private String reqId; - @Column(name = "bank_txn_Id", nullable = false) - private String bankTxnId; - - @Column(name = "client_user_id") - private String clientUserId; - - @Column(name = "mid") - private String mid; + @Column(name = "bank_txn_Id", nullable = false) + private String bankTxnId; - @Column(name = "txn_id") - private String txnId; + @Column(name = "client_user_id") + private String clientUserId; - @Column(name = "status") - private String status; + @Column(name = "mid") + private String mid; + + @Column(name = "txn_id") + private String txnId; + + @Column(name = "status") + private String status; + + @Column(name = "user_id") + private String userId; } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/PlanResponses.java b/src/main/java/com/billpaymentservice/bbps/entites/PlanResponses.java index 8fd0500..9defaf9 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/PlanResponses.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/PlanResponses.java @@ -47,4 +47,7 @@ public class PlanResponses extends Auditable { @Column(name = "txn_id") private String txnId; + @Column(name = "user_id") + private String userId; + } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/TicketDispositionDetails.java b/src/main/java/com/billpaymentservice/bbps/entites/TicketDispositionDetails.java index fe743ca..1b52917 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/TicketDispositionDetails.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/TicketDispositionDetails.java @@ -41,4 +41,6 @@ public class TicketDispositionDetails extends Auditable { @Column(name = "txn_id") private String txnId; + @Column(name = "user_id") + private String userId; } diff --git a/src/main/java/com/billpaymentservice/bbps/entites/ViewAllComplaintTicketStatusDetails.java b/src/main/java/com/billpaymentservice/bbps/entites/ViewAllComplaintTicketStatusDetails.java index e222c69..3d92701 100644 --- a/src/main/java/com/billpaymentservice/bbps/entites/ViewAllComplaintTicketStatusDetails.java +++ b/src/main/java/com/billpaymentservice/bbps/entites/ViewAllComplaintTicketStatusDetails.java @@ -27,6 +27,9 @@ public class ViewAllComplaintTicketStatusDetails extends Auditable { @Column(name = "txn_id") private String systemTxnId; + @Column(name = "user_id") + private String userId; + @Column(name = "total_elements") private String totalElements; diff --git a/src/main/java/com/billpaymentservice/bbps/repository/ComplaintResponseRepository.java b/src/main/java/com/billpaymentservice/bbps/repository/ComplaintResponseRepository.java index 784a82f..dcbf0c3 100644 --- a/src/main/java/com/billpaymentservice/bbps/repository/ComplaintResponseRepository.java +++ b/src/main/java/com/billpaymentservice/bbps/repository/ComplaintResponseRepository.java @@ -1,7 +1,7 @@ package com.billpaymentservice.bbps.repository; -import java.util.List; - +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -12,6 +12,9 @@ import com.billpaymentservice.bbps.entites.ComplaintResponseEntity; @Repository public interface ComplaintResponseRepository extends JpaRepository { +// @Query("SELECT c FROM ComplaintResponseEntity c WHERE c.userId = :userId") +// List findByUserIdCustom(@Param("userId") String userId); + @Query("SELECT c FROM ComplaintResponseEntity c WHERE c.userId = :userId") - List findByUserIdCustom(@Param("userId") String userId); + Page findByUserIdCustom(@Param("userId") String userId, Pageable pageable); } diff --git a/src/main/java/com/billpaymentservice/bbps/repository/TransactionMasterRepository.java b/src/main/java/com/billpaymentservice/bbps/repository/TransactionMasterRepository.java index b72550f..d4d7dee 100644 --- a/src/main/java/com/billpaymentservice/bbps/repository/TransactionMasterRepository.java +++ b/src/main/java/com/billpaymentservice/bbps/repository/TransactionMasterRepository.java @@ -6,14 +6,24 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import com.billpaymentservice.bbps.entites.TransactionMaster; public interface TransactionMasterRepository extends JpaRepository { - @Query("SELECT t FROM TransactionMaster t WHERE t.mid = :mid OR t.clientUserId = :clientUserId") - List findByMidOrClientUserId(@Param("mid") String mid, - @Param("clientUserId") String clientUserId); +// @Query("SELECT t FROM TransactionMaster t WHERE t.mid = :mid OR t.clientUserId = :clientUserId") +// List findByMidOrClientUserId(@Param("mid") String mid, +// @Param("clientUserId") String clientUserId); +// + @Query("SELECT t FROM TransactionMaster t WHERE t.mid = :mid") + Page findByMid(@Param("mid") String mid, Pageable pageable); + + @Query("SELECT t FROM TransactionMaster t WHERE t.mid = :mid AND t.clientUserId = :clientUserId") + Page findByMidOrClientUserId(@Param("mid") String mid, + @Param("clientUserId") String clientUserId, Pageable pageable); + @Query("SELECT t FROM TransactionMaster t WHERE t.txnId = :txnId") List findByTxnId(@Param("txnId") String txnId); diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java index a22994f..0f57d1e 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java @@ -120,6 +120,7 @@ public class AgentServiceImpl implements AgentService { billMaster.setBillId((String) dataMap.get("billId")); billMaster.setReqId(fetchBillRequest.getReqId()); billMaster.setTxnId(txnId); + billMaster.setClientUserId(fetchBillRequest.getClientUserId()); billMasterRepository.save(billMaster); LOGGER.info("BillMaster saved for billId: {}", billMaster.getBillId()); @@ -131,6 +132,7 @@ public class AgentServiceImpl implements AgentService { billInitiate.setBillId((String) dataMap.get("billId")); billInitiate.setReqId(fetchBillRequest.getReqId()); billInitiate.setTxnId(txnId); + billInitiate.setClientUserId(fetchBillRequest.getClientUserId()); billIntiateRepository.save(billInitiate); LOGGER.info("BillInitiate entry saved for billId: {}", billInitiate.getBillId()); @@ -394,7 +396,7 @@ public class AgentServiceImpl implements AgentService { helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); System.out.println("responseWrapper:" + responseWrapper); - mapperHelper.saveBillValidation(responseWrapper, billRequest); + mapperHelper.saveBillValidation(responseWrapper, billRequest,txnId); return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()), responseWrapper); } catch (JsonProcessingException e) { @@ -412,7 +414,7 @@ public class AgentServiceImpl implements AgentService { String reqId = billRequest.getReqId(); String billId = billRequest.getBillId(); String mid = billRequest.getMid(); - String requestJson = helper.convertObjectToJson(billRequest); + String requestJson = helper.convertObjectToJson(billRequest); LOGGER.info("[{}] START | reqId={} | mid={} | billId={}", apiName, billRequest, mid, billId); String txnId = helper.generateTxnId(15); String fullUrl = agentDtaUrl + BBPSConstant.BILL_VALIDATE_ID_URL + billRequest.getBillId(); @@ -452,7 +454,7 @@ public class AgentServiceImpl implements AgentService { GeneralResp generalResp = responseWrapper.getGenericResponse(); helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - mapperHelper.saveBillValidation(responseWrapper, billRequest); + mapperHelper.saveBillValidation(responseWrapper, billRequest,txnId); LOGGER.info("Bill validation saved successfully for billId: {}", billId); LOGGER.info("[{}] END | reqId={} | status={}", apiName, reqId, generalResp.getStatus()); return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), @@ -484,8 +486,8 @@ public class AgentServiceImpl implements AgentService { String requestJson = helper.convertObjectToJson(billValidateByClientIdRequest); LOGGER.info("[{}] START | reqId={} | mid={} | clientReqId={}", apiName, reqId, mid, billValidateByClientIdRequest.getClientReqId()); - InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, - billValidateByClientIdRequest.getMid(), BBPSConstant.HTTP_GET,requestJson); + InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, + billValidateByClientIdRequest.getMid(), BBPSConstant.HTTP_GET, requestJson); helper.validateMerchant(billValidateByClientIdRequest.getMid()); Optional billInitiate = billIntiateRepository.findByReqId(clientReqId); diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AuthServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AuthServiceImpl.java index d6eb102..0753ff2 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AuthServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AuthServiceImpl.java @@ -142,8 +142,8 @@ public class AuthServiceImpl implements AuthService { Optional existing = userRepository.findByMobile(request.getMobile()); if (existing.isPresent()) { UserEntity u = existing.get(); - UserDto dto = new UserDto(u.getId(), u.getMobile(), u.getName(), u.getEmail()); - AuthResponse ar = new AuthResponse(false, "User already exists", true, dto); + UserDto dto = new UserDto(u.getUserId(), u.getMobile(), u.getName(), u.getEmail()); + AuthResponse ar = new AuthResponse(false, "User already exists", null, dto); return ResponseModel.builder().message(ar.getMessage()).status("Failure").statusCode(409).data(ar) .build(); } @@ -151,9 +151,11 @@ public class AuthServiceImpl implements AuthService { UserEntity userEntity = helper.createNewUser(request); userRepository.save(userEntity); String token = jwtUtil.generateToken(userEntity.getMobile()); - UserDto dto = new UserDto(userEntity.getId(), userEntity.getMobile(), userEntity.getName(), - userEntity.getEmail()); - AuthResponse ar = new AuthResponse(true, "user registed sucessfully", token); +// UserDto dto = new UserDto(userEntity.getUserId(), userEntity.getMobile(), userEntity.getName(), +// userEntity.getEmail()); + Object userDetailsDTO = helper.mapUserToUserDetailsDTO(userEntity); + AuthResponse ar = new AuthResponse(true, "user registered successfully", token, userDetailsDTO); + return ResponseModel.builder().message(ar.getMessage()).status("Success").statusCode(201).data(ar).build(); } catch (ExpiredJwtException e) { LOGGER.error("Token has expired: {}", e.getMessage()); diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java index 1af5ec0..9d9e77e 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/ComplainServiceImpl.java @@ -8,6 +8,9 @@ import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; @@ -216,8 +219,8 @@ public class ComplainServiceImpl implements ComplainService { String complaintId = request.getTicketId(); String mid = request.getMid(); String ticketId = request.getTicketId(); - - LOGGER.info("[{}] START | reqId={} | mid={} | ticketId={}", apiName, reqId, mid, ticketId); + String userId = request.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | ticketId={} | userId={}", apiName, reqId, mid, ticketId, userId); String fullUrl = agentDtaUrl + BBPSConstant.COMPALINT_STATUS; String txnId = helper.generateTxnId(15); @@ -277,7 +280,7 @@ public class ComplainServiceImpl implements ComplainService { TicketCheckStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TicketCheckStatusResponse.class); - String saveComplaintStatus = mapperHelper.saveComplaintStatus(responseWrapper, reqId, txnId); + String saveComplaintStatus = mapperHelper.saveComplaintStatus(responseWrapper, reqId, txnId, userId); LOGGER.info("[{}] Save Status | ticketId={} | status={}", apiName, ticketId, saveComplaintStatus); helper.updateInboundLogSuccess(inboundLog, responseData, responseWrapper.getStatus()); @@ -298,8 +301,8 @@ public class ComplainServiceImpl implements ComplainService { String reqId = request.getReqId(); String ticketId = request.getTicketId(); String mid = request.getMid(); - - LOGGER.info("[{}] START | reqId={} | mid={} | ticketId={}", apiName, reqId, mid, ticketId); + String userId = request.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | ticketId={} | userId={}", apiName, reqId, mid, ticketId, userId); String fullUrl = agentDtaUrl + BBPSConstant.COMPLAINT_HISTORY + request.getTicketId(); String txnId = helper.generateTxnId(15); @@ -345,7 +348,7 @@ public class ComplainServiceImpl implements ComplainService { LOGGER.info("Current Complaint ReOpen Status: {}", status); helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - String saveComplaintHistory = mapperHelper.saveComplaintHistory(responseWrapper, reqId, txnId); + String saveComplaintHistory = mapperHelper.saveComplaintHistory(responseWrapper, reqId, txnId, userId); LOGGER.info("[{}] Complaint history saved | ticketId={} | entryId={}", apiName, ticketId, saveComplaintHistory); return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), @@ -364,7 +367,8 @@ public class ComplainServiceImpl implements ComplainService { String reqId = request.getReqId(); String ticketId = request.getTicketId(); String mid = request.getMid(); - LOGGER.info("[{}] START | reqId={} | mid={} | ticketId={}", apiName, reqId, mid, ticketId); + String userId = request.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | ticketId={} | userId={}", apiName, reqId, mid, ticketId, userId); String txnId = helper.generateTxnId(15); String fullUrl = agentDtaUrl + BBPSConstant.VIEW_COMPLAINT_BY_ID + request.getTicketId(); @@ -408,7 +412,7 @@ public class ComplainServiceImpl implements ComplainService { LOGGER.info("Current Complaint ReOpen Status: {}", status); helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - String saveComplaint = mapperHelper.saveComplainStatusDetail(responseWrapper, reqId, txnId); + String saveComplaint = mapperHelper.saveComplainStatusDetail(responseWrapper, reqId, txnId, userId); LOGGER.info("[{}] Complaint details saved | ticketId={} | id={}", apiName, ticketId, saveComplaint); return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), @@ -540,8 +544,9 @@ public class ComplainServiceImpl implements ComplainService { String reqId = request.getReqId(); String mid = request.getMid(); String statusType = request.getStatusType(); - - LOGGER.info("[{}] START | reqId={} | mid={} | statusType={}", apiName, reqId, mid, statusType); + String userId = request.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | statusType={} | userId={}", apiName, reqId, mid, statusType, + userId); String txnId = helper.generateTxnId(15); String fullUrl = complainDataUrl + BBPSConstant.VIEW_ALL_COMPLAINTS_BASE + "?pageNo=" + request.getPageNo() + "&pageSize=" + request.getPageSize() + "&statusType=" + request.getStatusType() + "&ticketType=" @@ -586,7 +591,7 @@ public class ComplainServiceImpl implements ComplainService { String status = generalResp.getStatus(); LOGGER.info("Current Complaint ReOpen Status: {}", status); - String saveComplaint = mapperHelper.saveAllComplaints(responseWrapper, reqId, txnId); + String saveComplaint = mapperHelper.saveAllComplaints(responseWrapper, reqId, txnId, userId); LOGGER.info("[{}] Complaint records saved into DB | count={}", apiName, saveComplaint); return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), @@ -632,7 +637,12 @@ public class ComplainServiceImpl implements ComplainService { // Log the call to external API LOGGER.info("[{}] Calling external API | URL={}", apiName, apiName); - List complaintUserData = complaintResponseRepository.findByUserIdCustom(userId); + // List complaintUserData = + // complaintResponseRepository.findByUserIdCustom(userId); + + Pageable pageable = PageRequest.of(request.getPageNo(), request.getPageSize()); + Page complaintUserData = complaintResponseRepository.findByUserIdCustom(userId, + pageable); // Check if complaints were found if (complaintUserData == null || complaintUserData.isEmpty()) { @@ -642,15 +652,17 @@ public class ComplainServiceImpl implements ComplainService { } // Log the number of complaints fetched - LOGGER.info("[{}] Complaints found for userId={} | count={}", apiName, userId, complaintUserData.size()); + LOGGER.info("[{}] Complaints found for userId={} | count={}", apiName, userId, + complaintUserData.getContent().size()); // Update outbound log with the count - String count = String.valueOf(complaintUserData.size()); + String count = String.valueOf(complaintUserData.getContent().size()); helper.updateOutboundLogResponse(outboundLog, count); // Return successful response with complaints data return new ResponseModel(BBPSConstant.ALL_COMPLAINT_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE, - BBPSConstant.HTTP_OK_INT, complaintUserData, complaintUserData.size()); + BBPSConstant.HTTP_OK_INT, complaintUserData.getContent(), // Only the list of complaints (data) + complaintUserData.getContent().size()); } catch (CustomException e) { // Rethrow custom exception for handling at the controller level diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java index d50ee9a..66ac465 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/MasterDataServiceImpl.java @@ -220,7 +220,7 @@ public class MasterDataServiceImpl implements MasterDataService { mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); BillerDetails entity = mapper.map(responseWrapper.getBillerDAO(), BillerDetails.class); EntityRelationshipUtil.linkBillerRelationships(entity);// linking nesting entity foreign key - //mapperHelper.saveOrUpdateBillerData(entity); + // mapperHelper.saveOrUpdateBillerData(entity); ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()), responseWrapper); @@ -439,7 +439,8 @@ public class MasterDataServiceImpl implements MasterDataService { String requestId = dispositionDetailRequest.getReqId(); String mid = dispositionDetailRequest.getMid(); String requestJson = helper.convertObjectToJson(dispositionDetailRequest); - LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid); + String userId = dispositionDetailRequest.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | userId={}", apiName, requestId, mid, userId); String txnID = helper.generateTxnId(15); String fullUrl = masterRegisterUrl + BBPSConstant.DISPOSTION_URL; InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, @@ -474,15 +475,23 @@ public class MasterDataServiceImpl implements MasterDataService { GeneralResp generalResp = responseWrapper.getGeneralResp(); ModelMapper mapper = new ModelMapper(); mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); - List entities = responseWrapper.getDispositionsList().stream() - .map(dto -> mapper.map(dto, DispositionDetails.class)).collect(Collectors.toList()); + // Assuming responseWrapper contains the data you need to map to + // DispositionDetails + List entities = responseWrapper.getDispositionsList().stream().map(dto -> { + DispositionDetails disposition = mapper.map(dto, DispositionDetails.class); + disposition.setReqId(requestId); + disposition.setTxnId(txnID); + disposition.setUserId(userId); + + return disposition; + }).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."); + if (entities != null && !entities.isEmpty()) { + dispositionRepository.saveAll(entities); // Save the list of entities + } else { + LOGGER.warn("No dispositions found in response to save."); } ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), @@ -506,9 +515,9 @@ public class MasterDataServiceImpl implements MasterDataService { 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()); + String userId = requestModel.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | billerId={} | userId={}", apiName, requestId, mid, + requestModel.getBillerId(), userId); helper.validateMerchant(mid); String txnID = helper.generateTxnId(15); String fullUrl = masterRegisterUrl + BBPSConstant.CUSTOMER_PARAM_GROUP + requestModel.getBillerId(); @@ -543,7 +552,7 @@ public class MasterDataServiceImpl implements MasterDataService { GeneralResp generalResp = responseWrapper.getGeneralResp(); CustomerParamGroupsDTO responseDTO = mapperHelper - .saveCustomerParamGroups(responseWrapper.getCustomerParamGroupResp(), requestId, txnID); + .saveCustomerParamGroups(responseWrapper.getCustomerParamGroupResp(), requestId, txnID, userId); LOGGER.info("[{}] Saved {} Customer Param Group records | reqId={}", apiName, responseDTO.toString(), requestId); @@ -569,9 +578,9 @@ public class MasterDataServiceImpl implements MasterDataService { 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 userId = requestModel.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | billerId={} | userId={}", apiName, requestId, mid, + requestModel.getBillerId(), userId); String txnID = helper.generateTxnId(15); String fullUrl = masterRegisterUrl + BBPSConstant.AMOUNT_OPTIONS + requestModel.getBillerId(); @@ -607,8 +616,8 @@ public class MasterDataServiceImpl implements MasterDataService { AmountOptionsResponse responseWrapper = objectMapper.convertValue(dataMap, AmountOptionsResponse.class); - String saveAmountOptionsResponse = mapperHelper.saveAmountOptionsResponse(responseWrapper, requestId, - txnID); + String saveAmountOptionsResponse = mapperHelper.saveAmountOptionsResponse(responseWrapper, requestId, txnID, + userId); LOGGER.info("[{}] Save Result | reqId={} | result={}", apiName, requestId, saveAmountOptionsResponse); GeneralResp generalResp = responseWrapper.getGeneralResp(); @@ -635,8 +644,9 @@ public class MasterDataServiceImpl implements MasterDataService { 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()); + String userId = requestModel.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | billerId={} | userId={}", apiName, requestId, mid, + requestModel.getBillerId(), userId); helper.validateMerchant(requestModel.getMid()); String txnID = helper.generateTxnId(15); String fullUrl = masterRegisterUrl + BBPSConstant.PLAN_CATEGORIES + requestModel.getBillerId(); @@ -672,7 +682,7 @@ public class MasterDataServiceImpl implements MasterDataService { PlaneCategoriesResponse responseWrapper = objectMapper.convertValue(dataMap, PlaneCategoriesResponse.class); String saveCategoryItems = mapperHelper.saveCategoryItems(responseWrapper.getCategoryRespList(), requestId, - txnID); + txnID, userId); LOGGER.info("[{}] Saved category items | reqId={} | count={}", apiName, requestId, saveCategoryItems); GeneralResp generalResp = responseWrapper.getGeneralResp(); @@ -754,8 +764,9 @@ public class MasterDataServiceImpl implements MasterDataService { 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 userId = requestModel.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | billerId={} | userId={}", apiName, requestId, mid, + requestModel.getBillerId(), userId); 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(), @@ -802,7 +813,7 @@ public class MasterDataServiceImpl implements MasterDataService { PlanResponse responseWrapper = objectMapper.convertValue(dataMap, PlanResponse.class); GeneralResp generalResp = responseWrapper.getGeneralResp(); - PlanResponses savePlanResponse = mapperHelper.savePlanResponse(responseWrapper, requestId, txnID); + PlanResponses savePlanResponse = mapperHelper.savePlanResponse(responseWrapper, requestId, txnID, userId); LOGGER.info("[{}] Saved Plans | reqId={} | count={}", apiName, requestId, savePlanResponse); ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), @@ -824,8 +835,8 @@ public class MasterDataServiceImpl implements MasterDataService { String apiName = BBPSConstant.API_GET_TICKET_DISPOSITIONS; String requestId = dispositionDetailRequest.getReqId(); String mid = dispositionDetailRequest.getMid(); - - LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid); + String userId = dispositionDetailRequest.getClientUserId(); + LOGGER.info("[{}] START | reqId={} | mid={} | userId={}", apiName, requestId, mid, userId); String txnID = helper.generateTxnId(15); String fullUrl = masterRegisterUrl + BBPSConstant.TICKET_DISPOSTION_URL; InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, @@ -862,7 +873,7 @@ public class MasterDataServiceImpl implements MasterDataService { ModelMapper mapper = new ModelMapper(); mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); - mapperHelper.saveTicketDisoptionDetails(responseWrapper.getDispositionsList(), requestId, txnID); + mapperHelper.saveTicketDisoptionDetails(responseWrapper.getDispositionsList(), requestId, txnID, userId); ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), Integer.parseInt(generalResp.getStatusCode()), responseWrapper); diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java index 99585aa..6b016ab 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java @@ -45,355 +45,361 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Service public class PaymentServiceImpl implements PaymentService { - @Value("${payment.data.url}") - private String paymentUrl; - - private final BharatConnectMasterRepository beneficiaryDetailsRepository; - private final HttpService httpService; - private final Helper helper; - private final PaymentRepository paymentRepository; - private final InboundTraceLogRepository inboundTraceLogRepository; - private final OutboundTraceLogRepository outboundTraceLogRepository; - private final PaymentIntiateRepository paymentIntiateRepository; - private final TransactionMasterRepository transactionMasterRepository; - private final AgentFundTransferRepository agentFundTransferRepository; - private final BillerMapperHelper mapperHelper; - // Shared reusable instances - private final ObjectMapper objectMapper; - private final ModelMapper modelMapper; - - private static final Logger LOGGER = LoggerFactory.getLogger(PaymentServiceImpl.class); - - public PaymentServiceImpl(BharatConnectMasterRepository beneficiaryDetailsRepository, HttpService httpService, - Helper helper, PaymentRepository paymentRepository, InboundTraceLogRepository inboundTraceLogRepository, - OutboundTraceLogRepository outboundTraceLogRepository, PaymentIntiateRepository paymentIntiateRepository, - TransactionMasterRepository transactionMasterRepository, - AgentFundTransferRepository agentFundTransferRepository, - BillerMapperHelper mapperHelper) { - this.beneficiaryDetailsRepository = beneficiaryDetailsRepository; - this.httpService = httpService; - this.helper = helper; - this.paymentRepository = paymentRepository; - this.inboundTraceLogRepository = inboundTraceLogRepository; - this.outboundTraceLogRepository = outboundTraceLogRepository; - this.paymentIntiateRepository = paymentIntiateRepository; - this.transactionMasterRepository = transactionMasterRepository; - this.agentFundTransferRepository = agentFundTransferRepository; - this.mapperHelper = mapperHelper; - - this.objectMapper = new ObjectMapper(); - this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - - this.modelMapper = new ModelMapper(); - this.modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); - } - - @Override - public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) { - String apiName = BBPSConstant.API_INITIATE_PAYMENT; - String txnId = helper.generateTxnId(15); - String requestId = billPaymentRequest.getReqId(); - String url = paymentUrl + BBPSConstant.PAYMENT_URL; - billPaymentRequest.setClientReqId(txnId); - LOGGER.info("Initiating payment for reqId={} and txnId={}", requestId, txnId); - - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); - HttpHeaders headers = helper.buildHeaders(headersData); - - BillPaymentForwardRequest forwardReq = mapperHelper.billPaymentForwardRequest(billPaymentRequest); - String forwardjson = helper.convertObjectToJson(forwardReq); - String requestJson = helper.convertObjectToJson(billPaymentRequest); - - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); - LOGGER.debug("Inbound log created for api={} | reqId={} | txnId={}", apiName, requestId, txnId); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_POST, forwardjson); - LOGGER.debug("Outbound log created for api={} | reqId={} | txnId={}", apiName, requestId, txnId); - - try { - LOGGER.info("Calling BBPS payment URL: {}", url); - Map responseMap = httpService.postRequest(url, forwardjson, headers); - String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); - LOGGER.info("Payment API Response: {}", responseData); - - helper.updateOutboundLogResponse(outboundLog, responseData); - LOGGER.debug("Outbound log response updated for txnId={}", txnId); - - if (responseData == null || responseData.isEmpty()) { - helper.updateInboundLogFailure(inboundLog, BBPSConstant.EMPTY_RESPONSE_FROM_BBPS, BBPSConstant.FAILED_STR); - LOGGER.warn("Empty response received from BBPS for txnId={}", txnId); - throw new CustomException(BBPSConstant.EMPTY_RESPONSE_FROM_BBPS); - } - - Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { - helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_STRUCTURE); - LOGGER.warn("Invalid response structure received for txnId={}", txnId); - throw new CustomException(BBPSConstant.INVALID_STRUCTURE); - } - - BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class); - GeneralResp generalResponse = billPaymentResponse.getGenericResponse(); - - BillPayment entity = modelMapper.map(billPaymentResponse, BillPayment.class); - paymentRepository.save(entity); - LOGGER.info("BillPayment entity saved successfully for txnId={}", txnId); - - helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus()); - PaymentInitiate paymentInitiate = new PaymentInitiate(); - paymentInitiate.setTxnId(txnId); - paymentInitiate.setReqId(requestId); - paymentInitiate.setMid(billPaymentRequest.getMid()); - paymentInitiate.setClientUserId(billPaymentRequest.getClientUserId()); - paymentInitiate.setBankTxnId(billPaymentResponse.getTxnId()); - paymentInitiate.setStatus(billPaymentResponse.getStatus()); - paymentIntiateRepository.save(paymentInitiate); - LOGGER.info("PaymentInitiate entry saved successfully for txnId={}", txnId); - - TransactionStatusRequest transactionStatusRequest = new TransactionStatusRequest(); - transactionStatusRequest.setTxnId(billPaymentResponse.getTxnId()); - transactionStatusRequest.setReqId(requestId); - transactionStatusRequest.setMid(billPaymentRequest.getMid()); - transactionStatusRequest.setClientUserId(billPaymentRequest.getClientUserId()); - - - try { - Thread.sleep((long) BBPSConstant.PAYMENT_STATUS_DELAY_MS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage()); - } - LOGGER.info("Checking transaction status for txnId={}", billPaymentResponse.getTxnId()); - LOGGER.info("[{}] END | reqId={} | txnId={}", apiName, requestId, txnId); - return checkTrasactionStatus(transactionStatusRequest, inboundLog); - - } catch (JsonProcessingException e) { - LOGGER.error("JSON Parsing Error in initiatePayment: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); - throw new CustomException("Invalid JSON received from API"); - } - } - - public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest, InboundTraceLog inboundLog) { - String apiName = BBPSConstant.API_CHECK_TRANSACTION_STATUS; - String txnId = helper.generateTxnId(15); - String requestId = transactionStatusRequest.getReqId(); - - // START log for internal transaction status check - LOGGER.info("[{}] START (internal) | checkTxnId={} | reqId={} | bankTxnId={}", apiName, txnId, requestId, transactionStatusRequest.getTxnId()); - - String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); - - LOGGER.info("Checking transaction status (internal) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); - - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); - HttpHeaders headers = helper.buildHeaders(headersData); - - OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_GET, null); - LOGGER.debug("Outbound log created for internal status check | txnId={} | reqId={}", txnId, requestId); - - Map responseMap = httpService.getRequest(url, headers); - String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); - LOGGER.info("Transaction status response: {}", responseData); - - helper.updateOutboundLogResponse(outboundLog, responseData); - LOGGER.debug("Outbound log response updated for internal status check | txnId={}", txnId); - - try { - Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { - helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); - LOGGER.warn("Invalid transaction status response for txnId={}", transactionStatusRequest.getTxnId()); - 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")) - ); - } - - TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TransactionStatusResponse.class); - GeneralResp generalResp = responseWrapper.getGeneralResp(); - LOGGER.info("Transaction status received: {}", generalResp.getStatus()); - - TransactionMaster transactionMaster = modelMapper.map(responseWrapper.getTransactionDAO(), TransactionMaster.class); - transactionMaster.setTxnId(txnId); - transactionMaster.setReqId(transactionStatusRequest.getReqId()); - transactionMaster.setMid(transactionStatusRequest.getMid()); - transactionMaster.setClientUserId(transactionStatusRequest.getClientUserId()); - EntityRelationshipUtil.linkTransactionMasterRelationships(transactionMaster); - transactionMasterRepository.save(transactionMaster); - LOGGER.info("TransactionMaster saved successfully for txnId={}", txnId); - - AgentFundTransfer agentFundTransfer = modelMapper.map(responseWrapper.getAgentFundTransfer(), AgentFundTransfer.class); - agentFundTransfer.setTxnId(txnId); - agentFundTransfer.setReqId(transactionStatusRequest.getReqId()); - agentFundTransfer.setTransactionMasterId(transactionMaster.getBankTxnId()); - agentFundTransferRepository.save(agentFundTransfer); - LOGGER.info("AgentFundTransfer entry saved successfully for txnId={}", txnId); - - ResponseModel responseModel = new ResponseModel( - generalResp.getMessage(), - generalResp.getStatus(), - Integer.parseInt(generalResp.getStatusCode()), - responseWrapper - ); - - helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - LOGGER.info("[{}] END (internal) | checkTxnId={} | reqId={} | status={}", apiName, txnId, requestId, generalResp.getStatus()); - return responseModel; - - } catch (JsonProcessingException e) { - LOGGER.error("Error parsing transaction status JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); - throw new CustomException("Invalid JSON received from API"); - } - } - - @Override - public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) { - helper.validateMerchant(transactionStatusRequest.getMid()); - String txnID = helper.generateTxnId(15); - String apiName = BBPSConstant.API_CHECK_TRANSACTION_PUBLIC; - String requestId = transactionStatusRequest.getReqId(); - LOGGER.info("[{}] START (public) | reqId={} | mid={} | checkBankTxnId={}", apiName, requestId, transactionStatusRequest.getMid(), transactionStatusRequest.getTxnId()); - String requestJson = helper.convertObjectToJson(transactionStatusRequest); - String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); - - LOGGER.info("Checking transaction status (public) for txnId={} and reqId={}", transactionStatusRequest.getTxnId(), requestId); - - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); - HttpHeaders headers = helper.buildHeaders(headersData); - - InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); - LOGGER.debug("Inbound log created for public status check | reqId={} | txnId={}", requestId, txnID); - OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, null); - LOGGER.debug("Outbound log created for public status check | reqId={} | txnId={}", requestId, txnID); - - Map responseMap = httpService.getRequest(url, headers); - String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); - LOGGER.info("Transaction status response data: {}", responseData); - helper.updateOutboundLogResponse(outboundLog, responseData); - LOGGER.debug("Outbound log response updated for public status check | reqId={} | txnId={}", requestId, txnID); - - try { - Map dataMap = objectMapper.readValue(responseData, new TypeReference>() {}); - if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { - helper.updateInboundLogFailure(inboundLog, responseData, String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); - LOGGER.warn("Invalid transaction status response for txnId={} from BBPS", transactionStatusRequest.getTxnId()); - 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")) - ); - } - - TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, TransactionStatusResponse.class); - GeneralResp generalResp = responseWrapper.getGeneralResp(); - - String status = generalResp.getStatus(); - LOGGER.info("Current transaction status: {}", status); - - ResponseModel responseModel = new ResponseModel( - generalResp.getMessage(), - generalResp.getStatus(), - Integer.parseInt(generalResp.getStatusCode()), - responseWrapper - ); - - helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - LOGGER.info("[{}] END (public) | reqId={} | txnId={} | status={}", apiName, requestId, txnID, generalResp.getStatus()); - return responseModel; - - } catch (JsonProcessingException e) { - LOGGER.error("Error parsing responseData JSON: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); - throw new CustomException("Invalid JSON received from API"); - } - } - - @Override - public ResponseModel checkTrasactionStatusByClientReqId(TrasactionStatusByClientReqIdRequest transactionStatusRequest) { - helper.validateMerchant(transactionStatusRequest.getMid()); - - String txnID = helper.generateTxnId(15); - String apiName = BBPSConstant.API_CHECK_BY_CLIENT_REQ_ID; - String requestId = transactionStatusRequest.getReqId(); - String clientReqId = transactionStatusRequest.getClientReqId(); - String requestJson = helper.convertObjectToJson(transactionStatusRequest); - - LOGGER.info("[{}] START | reqId={} | mid={} | clientReqId={}", apiName, requestId, transactionStatusRequest.getMid(), clientReqId); - - Optional paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId); - if (paymentInitiate.isEmpty()) { - throw new CustomException(BBPSConstant.NO_BILL_FOUND); - } - - String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_BY_CLIENT_REQ_ID_URL + paymentInitiate.get().getTxnId(); - - BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); - HttpHeaders headers = helper.buildHeaders(headersData); - - InboundTraceLog inboundLog = helper.createInboundLog( - requestId, txnID, apiName, transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); - LOGGER.debug("Inbound log created for clientReqId check | reqId={} | txnId={}", requestId, txnID); - - OutboundTraceLog outboundLog = helper.createOutboundLog( - txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, null); - LOGGER.debug("Outbound log created for clientReqId check | reqId={} | txnId={}", requestId, txnID); - - try { - LOGGER.info("Calling BBPS Transaction Status API URL={}", url); - Map responseMap = httpService.getRequest(url, headers); - - String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); - LOGGER.info("Transaction Status Response: {}", responseData); - - helper.updateOutboundLogResponse(outboundLog, responseData); - LOGGER.debug("Outbound log response updated for clientReqId check | reqId={} | txnId={}", requestId, txnID); - - Map dataMap = objectMapper.readValue( - responseData, new TypeReference>() {}); - - if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { - helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); - - LOGGER.warn("Invalid transaction status response for clientReqId={} | Response={}", - clientReqId, responseData); - - 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")) - ); - } - - TransactionStatusResponse responseWrapper = - objectMapper.convertValue(dataMap, TransactionStatusResponse.class); - - GeneralResp generalResp = responseWrapper.getGeneralResp(); - - LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus()); - - helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); - LOGGER.info("[{}] END | reqId={} | clientReqId={} | status={}", apiName, requestId, clientReqId, generalResp.getStatus()); - return new ResponseModel( - generalResp.getMessage(), - generalResp.getStatus(), - Integer.parseInt(generalResp.getStatusCode()), - responseWrapper - ); + @Value("${payment.data.url}") + private String paymentUrl; + + private final BharatConnectMasterRepository beneficiaryDetailsRepository; + private final HttpService httpService; + private final Helper helper; + private final PaymentRepository paymentRepository; + private final InboundTraceLogRepository inboundTraceLogRepository; + private final OutboundTraceLogRepository outboundTraceLogRepository; + private final PaymentIntiateRepository paymentIntiateRepository; + private final TransactionMasterRepository transactionMasterRepository; + private final AgentFundTransferRepository agentFundTransferRepository; + private final BillerMapperHelper mapperHelper; + // Shared reusable instances + private final ObjectMapper objectMapper; + private final ModelMapper modelMapper; + + private static final Logger LOGGER = LoggerFactory.getLogger(PaymentServiceImpl.class); + + public PaymentServiceImpl(BharatConnectMasterRepository beneficiaryDetailsRepository, HttpService httpService, + Helper helper, PaymentRepository paymentRepository, InboundTraceLogRepository inboundTraceLogRepository, + OutboundTraceLogRepository outboundTraceLogRepository, PaymentIntiateRepository paymentIntiateRepository, + TransactionMasterRepository transactionMasterRepository, + AgentFundTransferRepository agentFundTransferRepository, BillerMapperHelper mapperHelper) { + this.beneficiaryDetailsRepository = beneficiaryDetailsRepository; + this.httpService = httpService; + this.helper = helper; + this.paymentRepository = paymentRepository; + this.inboundTraceLogRepository = inboundTraceLogRepository; + this.outboundTraceLogRepository = outboundTraceLogRepository; + this.paymentIntiateRepository = paymentIntiateRepository; + this.transactionMasterRepository = transactionMasterRepository; + this.agentFundTransferRepository = agentFundTransferRepository; + this.mapperHelper = mapperHelper; + + this.objectMapper = new ObjectMapper(); + this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + this.modelMapper = new ModelMapper(); + this.modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); + } + + @Override + public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest) { + String apiName = BBPSConstant.API_INITIATE_PAYMENT; + String txnId = helper.generateTxnId(15); + String requestId = billPaymentRequest.getReqId(); + String userId = billPaymentRequest.getClientReqId(); + String url = paymentUrl + BBPSConstant.PAYMENT_URL; + billPaymentRequest.setClientReqId(txnId); + LOGGER.info("Initiating payment for reqId={} and txnId={} and userId={}", requestId, txnId, userId); + + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); + HttpHeaders headers = helper.buildHeaders(headersData); + + BillPaymentForwardRequest forwardReq = mapperHelper.billPaymentForwardRequest(billPaymentRequest); + String forwardjson = helper.convertObjectToJson(forwardReq); + String requestJson = helper.convertObjectToJson(billPaymentRequest); + + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, billPaymentRequest.getMid(), + BBPSConstant.HTTP_POST, requestJson); + LOGGER.debug("Inbound log created for api={} | reqId={} | txnId={}", apiName, requestId, txnId); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_POST, + forwardjson); + LOGGER.debug("Outbound log created for api={} | reqId={} | txnId={}", apiName, requestId, txnId); + + try { + LOGGER.info("Calling BBPS payment URL: {}", url); + Map responseMap = httpService.postRequest(url, forwardjson, headers); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); + LOGGER.info("Payment API Response: {}", responseData); + + helper.updateOutboundLogResponse(outboundLog, responseData); + LOGGER.debug("Outbound log response updated for txnId={}", txnId); + + if (responseData == null || responseData.isEmpty()) { + helper.updateInboundLogFailure(inboundLog, BBPSConstant.EMPTY_RESPONSE_FROM_BBPS, + BBPSConstant.FAILED_STR); + LOGGER.warn("Empty response received from BBPS for txnId={}", txnId); + throw new CustomException(BBPSConstant.EMPTY_RESPONSE_FROM_BBPS); + } + + Map dataMap = objectMapper.readValue(responseData, + new TypeReference>() { + }); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERIC_KEY)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_STRUCTURE); + LOGGER.warn("Invalid response structure received for txnId={}", txnId); + throw new CustomException(BBPSConstant.INVALID_STRUCTURE); + } + + BillPaymentResponse billPaymentResponse = objectMapper.convertValue(dataMap, BillPaymentResponse.class); + GeneralResp generalResponse = billPaymentResponse.getGenericResponse(); + + BillPayment entity = modelMapper.map(billPaymentResponse, BillPayment.class); + paymentRepository.save(entity); + LOGGER.info("BillPayment entity saved successfully for txnId={}", txnId); + + helper.updateInboundLogSuccess(inboundLog, responseData, generalResponse.getStatus()); + PaymentInitiate paymentInitiate = new PaymentInitiate(); + paymentInitiate.setTxnId(txnId); + paymentInitiate.setUserId(userId); + paymentInitiate.setReqId(requestId); + paymentInitiate.setMid(billPaymentRequest.getMid()); + paymentInitiate.setClientUserId(billPaymentRequest.getClientUserId()); + paymentInitiate.setBankTxnId(billPaymentResponse.getTxnId()); + paymentInitiate.setStatus(billPaymentResponse.getStatus()); + paymentIntiateRepository.save(paymentInitiate); + LOGGER.info("PaymentInitiate entry saved successfully for txnId={}", txnId); + + TransactionStatusRequest transactionStatusRequest = new TransactionStatusRequest(); + transactionStatusRequest.setTxnId(billPaymentResponse.getTxnId()); + transactionStatusRequest.setReqId(requestId); + transactionStatusRequest.setMid(billPaymentRequest.getMid()); + transactionStatusRequest.setClientUserId(billPaymentRequest.getClientUserId()); + + try { + Thread.sleep((long) BBPSConstant.PAYMENT_STATUS_DELAY_MS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + LOGGER.warn("Thread interrupted during payment delay: {}", e.getMessage()); + } + LOGGER.info("Checking transaction status for txnId={}", billPaymentResponse.getTxnId()); + LOGGER.info("[{}] END | reqId={} | txnId={}", apiName, requestId, txnId); + return checkTrasactionStatus(transactionStatusRequest, inboundLog); + + } catch (JsonProcessingException e) { + LOGGER.error("JSON Parsing Error in initiatePayment: {}", e.getMessage(), e); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); + throw new CustomException("Invalid JSON received from API"); + } + } + + public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest, + InboundTraceLog inboundLog) { + String apiName = BBPSConstant.API_CHECK_TRANSACTION_STATUS; + String txnId = helper.generateTxnId(15); + String requestId = transactionStatusRequest.getReqId(); + + // START log for internal transaction status check + LOGGER.info("[{}] START (internal) | checkTxnId={} | reqId={} | bankTxnId={}", apiName, txnId, requestId, + transactionStatusRequest.getTxnId()); + + String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); + + LOGGER.info("Checking transaction status (internal) for txnId={} and reqId={}", + transactionStatusRequest.getTxnId(), requestId); + + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); + HttpHeaders headers = helper.buildHeaders(headersData); + + OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, url, BBPSConstant.HTTP_GET, + null); + LOGGER.debug("Outbound log created for internal status check | txnId={} | reqId={}", txnId, requestId); + + Map responseMap = httpService.getRequest(url, headers); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); + LOGGER.info("Transaction status response: {}", responseData); + + helper.updateOutboundLogResponse(outboundLog, responseData); + LOGGER.debug("Outbound log response updated for internal status check | txnId={}", txnId); + + try { + Map dataMap = objectMapper.readValue(responseData, + new TypeReference>() { + }); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); + LOGGER.warn("Invalid transaction status response for txnId={}", transactionStatusRequest.getTxnId()); + 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"))); + } + + TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, + TransactionStatusResponse.class); + GeneralResp generalResp = responseWrapper.getGeneralResp(); + LOGGER.info("Transaction status received: {}", generalResp.getStatus()); + + TransactionMaster transactionMaster = modelMapper.map(responseWrapper.getTransactionDAO(), + TransactionMaster.class); + transactionMaster.setTxnId(txnId); + transactionMaster.setReqId(transactionStatusRequest.getReqId()); + transactionMaster.setMid(transactionStatusRequest.getMid()); + transactionMaster.setClientUserId(transactionStatusRequest.getClientUserId()); + EntityRelationshipUtil.linkTransactionMasterRelationships(transactionMaster); + transactionMasterRepository.save(transactionMaster); + LOGGER.info("TransactionMaster saved successfully for txnId={}", txnId); + + AgentFundTransfer agentFundTransfer = modelMapper.map(responseWrapper.getAgentFundTransfer(), + AgentFundTransfer.class); + agentFundTransfer.setTxnId(txnId); + agentFundTransfer.setReqId(transactionStatusRequest.getReqId()); + agentFundTransfer.setTransactionMasterId(transactionMaster.getBankTxnId()); + agentFundTransferRepository.save(agentFundTransfer); + LOGGER.info("AgentFundTransfer entry saved successfully for txnId={}", txnId); + + ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), + Integer.parseInt(generalResp.getStatusCode()), responseWrapper); + + helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); + LOGGER.info("[{}] END (internal) | checkTxnId={} | reqId={} | status={}", apiName, txnId, requestId, + generalResp.getStatus()); + return responseModel; + + } catch (JsonProcessingException e) { + LOGGER.error("Error parsing transaction status JSON: {}", e.getMessage(), e); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); + throw new CustomException("Invalid JSON received from API"); + } + } + + @Override + public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest) { + helper.validateMerchant(transactionStatusRequest.getMid()); + String txnID = helper.generateTxnId(15); + String apiName = BBPSConstant.API_CHECK_TRANSACTION_PUBLIC; + String requestId = transactionStatusRequest.getReqId(); + LOGGER.info("[{}] START (public) | reqId={} | mid={} | checkBankTxnId={}", apiName, requestId, + transactionStatusRequest.getMid(), transactionStatusRequest.getTxnId()); + String requestJson = helper.convertObjectToJson(transactionStatusRequest); + String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_URL + transactionStatusRequest.getTxnId(); + + LOGGER.info("Checking transaction status (public) for txnId={} and reqId={}", + transactionStatusRequest.getTxnId(), requestId); + + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); + HttpHeaders headers = helper.buildHeaders(headersData); + + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, + transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); + LOGGER.debug("Inbound log created for public status check | reqId={} | txnId={}", requestId, txnID); + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, + null); + LOGGER.debug("Outbound log created for public status check | reqId={} | txnId={}", requestId, txnID); + + Map responseMap = httpService.getRequest(url, headers); + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); + LOGGER.info("Transaction status response data: {}", responseData); + helper.updateOutboundLogResponse(outboundLog, responseData); + LOGGER.debug("Outbound log response updated for public status check | reqId={} | txnId={}", requestId, txnID); + + try { + Map dataMap = objectMapper.readValue(responseData, + new TypeReference>() { + }); + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, + String.valueOf(dataMap.get(BBPSConstant.RESPONSE_STATUS_KEY))); + LOGGER.warn("Invalid transaction status response for txnId={} from BBPS", + transactionStatusRequest.getTxnId()); + 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"))); + } + + TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, + TransactionStatusResponse.class); + GeneralResp generalResp = responseWrapper.getGeneralResp(); + + String status = generalResp.getStatus(); + LOGGER.info("Current transaction status: {}", status); + + ResponseModel responseModel = new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), + Integer.parseInt(generalResp.getStatusCode()), responseWrapper); + + helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); + LOGGER.info("[{}] END (public) | reqId={} | txnId={} | status={}", apiName, requestId, txnID, + generalResp.getStatus()); + return responseModel; + + } catch (JsonProcessingException e) { + LOGGER.error("Error parsing responseData JSON: {}", e.getMessage(), e); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); + throw new CustomException("Invalid JSON received from API"); + } + } + + @Override + public ResponseModel checkTrasactionStatusByClientReqId( + TrasactionStatusByClientReqIdRequest transactionStatusRequest) { + helper.validateMerchant(transactionStatusRequest.getMid()); + + String txnID = helper.generateTxnId(15); + String apiName = BBPSConstant.API_CHECK_BY_CLIENT_REQ_ID; + String requestId = transactionStatusRequest.getReqId(); + String clientReqId = transactionStatusRequest.getClientReqId(); + String requestJson = helper.convertObjectToJson(transactionStatusRequest); + + LOGGER.info("[{}] START | reqId={} | mid={} | clientReqId={}", apiName, requestId, + transactionStatusRequest.getMid(), clientReqId); + + Optional paymentInitiate = paymentIntiateRepository.findByReqId(clientReqId); + if (paymentInitiate.isEmpty()) { + throw new CustomException(BBPSConstant.NO_BILL_FOUND); + } + + String url = paymentUrl + BBPSConstant.CHECK_TRANSACTION_BY_CLIENT_REQ_ID_URL + + paymentInitiate.get().getTxnId(); + + BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID); + HttpHeaders headers = helper.buildHeaders(headersData); + + InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnID, apiName, + transactionStatusRequest.getMid(), BBPSConstant.HTTP_POST, requestJson); + LOGGER.debug("Inbound log created for clientReqId check | reqId={} | txnId={}", requestId, txnID); + + OutboundTraceLog outboundLog = helper.createOutboundLog(txnID, requestId, apiName, url, BBPSConstant.HTTP_GET, + null); + LOGGER.debug("Outbound log created for clientReqId check | reqId={} | txnId={}", requestId, txnID); + + try { + LOGGER.info("Calling BBPS Transaction Status API URL={}", url); + Map responseMap = httpService.getRequest(url, headers); + + String responseData = responseMap.get(BBPSConstant.RESPONSE_DATA_KEY); + LOGGER.info("Transaction Status Response: {}", responseData); + + helper.updateOutboundLogResponse(outboundLog, responseData); + LOGGER.debug("Outbound log response updated for clientReqId check | reqId={} | txnId={}", requestId, txnID); + + Map dataMap = objectMapper.readValue(responseData, + new TypeReference>() { + }); + + if (!dataMap.containsKey(BBPSConstant.RESPONSE_GENERAL_RESP)) { + helper.updateInboundLogFailure(inboundLog, responseData, BBPSConstant.INVALID_RESPONSE); + + LOGGER.warn("Invalid transaction status response for clientReqId={} | Response={}", clientReqId, + responseData); + + 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"))); + } + + TransactionStatusResponse responseWrapper = objectMapper.convertValue(dataMap, + TransactionStatusResponse.class); + + GeneralResp generalResp = responseWrapper.getGeneralResp(); + + LOGGER.info("Transaction Status for clientReqId={} => {}", clientReqId, generalResp.getStatus()); + + helper.updateInboundLogSuccess(inboundLog, responseData, generalResp.getStatus()); + LOGGER.info("[{}] END | reqId={} | clientReqId={} | status={}", apiName, requestId, clientReqId, + generalResp.getStatus()); + return new ResponseModel(generalResp.getMessage(), generalResp.getStatus(), + Integer.parseInt(generalResp.getStatusCode()), responseWrapper); - } catch (JsonProcessingException e) { - LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e); - helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); + } catch (JsonProcessingException e) { + LOGGER.error("Error parsing JSON in transaction status API: {}", e.getMessage(), e); + helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR); - throw new CustomException("Invalid JSON received from API"); - } - } + throw new CustomException("Invalid JSON received from API"); + } + } - - - } \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/TxnHistoryServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/TxnHistoryServiceImpl.java index c4745bd..93ecd54 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/TxnHistoryServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/TxnHistoryServiceImpl.java @@ -4,7 +4,9 @@ import java.util.List; import java.util.stream.Collectors; import org.springframework.stereotype.Service; - +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import com.billpaymentservice.bbps.dto.ResponseModel; import com.billpaymentservice.bbps.dto.TransactionHistoryMasterDTO; import com.billpaymentservice.bbps.dto.TransactionHistoryParticularDetailsDTO; @@ -57,22 +59,34 @@ public class TxnHistoryServiceImpl implements TxnHistoryService { BBPSConstant.HTTP_GET, null); try { - List dataResult = transactionMasterRepository.findByMidOrClientUserId(mid, clientUserId); + Page dataResult; + if (clientUserId.isEmpty() || clientUserId == null) { + Pageable pageable = PageRequest.of(paymentHistoryRequest.getPageNo(), + paymentHistoryRequest.getPageSize()); + dataResult = transactionMasterRepository.findByMid(mid, pageable); + } else { + Pageable pageable = PageRequest.of(paymentHistoryRequest.getPageNo(), + paymentHistoryRequest.getPageSize()); + dataResult = transactionMasterRepository.findByMidOrClientUserId(mid, clientUserId, pageable); + + } + // List dataResult = + // transactionMasterRepository.findByMidOrClientUserId(mid, clientUserId); if (dataResult == null || dataResult.isEmpty()) { log.info("[{}] Response Fetch From DB | reqId={} | data={}", apiName, requestId, dataResult); throw new CustomException("No Transcation Found This Mid", "FAILED", BBPSConstant.BADREQUEST, null); } - Integer responseData = dataResult.size(); - log.info("[{}] Response Fetch From DB | reqId={} | data={}", apiName, requestId, responseData); + log.info("[{}] Response Fetch From DB | reqId={} | data={}", apiName, requestId, + dataResult.getTotalElements()); List responseDatas = dataResult.stream() .map(mapperHelper::billerRemainingDetails).collect(Collectors.toList()); - helper.updateOutboundLogResponse(outboundLog, String.valueOf(responseData)); + helper.updateOutboundLogResponse(outboundLog, String.valueOf(dataResult.getTotalElements())); - return new ResponseModel(BBPSConstant.ALL_MASTER_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE, + return new ResponseModel(BBPSConstant.ALL_HISTORY_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE, BBPSConstant.HTTP_OK_INT, responseDatas, responseDatas.size()); } catch (CustomException e) { @@ -123,7 +137,7 @@ public class TxnHistoryServiceImpl implements TxnHistoryService { helper.updateOutboundLogResponse(outboundLog, String.valueOf(responseData)); return new ResponseModel(BBPSConstant.ALL_MASTER_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE, - BBPSConstant.HTTP_OK_INT, transactionDTO,null,responseData); + BBPSConstant.HTTP_OK_INT, transactionDTO, null, responseData); } catch (CustomException e) { // Log and rethrow the custom exception diff --git a/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java b/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java index f764cf0..9c268c8 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java +++ b/src/main/java/com/billpaymentservice/bbps/util/BBPSConstant.java @@ -146,6 +146,7 @@ public class BBPSConstant { public static final String NULL_DATA_FROM_DB = "NULL_DATA_FROM_DB"; public static final String NO_MASTER_FIELDS_FOUND = "No master fields found"; public static final String ALL_MASTER_FIELDS_FETCH = "All master fields fetched successfully"; + public static final String ALL_HISTORY_FIELDS_FETCH = "All history fields fetched successfully"; public static final String ALL_COMPLAINT_FIELDS_FETCH = "All complaint fields fetched successfully"; public static final String SOMETHING_WENT_WRONG = "Something went wrong"; public static final String USER_ID_IS_EMPTY = "User id is empty"; @@ -155,8 +156,8 @@ public class BBPSConstant { public static final long BILL_VALIDATE_DELAY_MS = 12000L; // used after initiate bill validate public static final long PAYMENT_STATUS_DELAY_MS = 9000L; // used after initiate payment - public static final String enckey = "zk52olsyr9fl95h50eus8bhtyhoo5lp7"; - public static final String mid = "Test-By-Aditya-1001"; - public static final String callbackurl = "https://checkout.solwio.in/PGPayU/payu/callback"; - public static final String companyName = "techwork technology"; + public static final String enckey = "g5c4lr0tgjjqhu0bfgmhjf26ab0z8ktk"; + public static final String mid = "MIDBBPS001THA"; + public static final String callbackurl = "https://11.godemo.in/BBPS/payment/callback/startPayment"; + public static final String companyName = "testing.com"; } \ No newline at end of file diff --git a/src/main/java/com/billpaymentservice/bbps/util/BillerMapperHelper.java b/src/main/java/com/billpaymentservice/bbps/util/BillerMapperHelper.java index 648c983..d540118 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/BillerMapperHelper.java +++ b/src/main/java/com/billpaymentservice/bbps/util/BillerMapperHelper.java @@ -239,7 +239,8 @@ public class BillerMapperHelper { return billerRepo.saveAll(entities); } - public CustomerParamGroupsDTO saveCustomerParamGroups(CustomerParamGroupsDTO dtos, String requestId, String txnId) { + public CustomerParamGroupsDTO saveCustomerParamGroups(CustomerParamGroupsDTO dtos, String requestId, String txnId, + String userId) { if (dtos == null || dtos.getGroups() == null || dtos.getGroups().isEmpty()) { return new CustomerParamGroupsDTO(); // Return empty DTO if no groups exist } @@ -248,8 +249,10 @@ public class BillerMapperHelper { // Loop through the top-level groups and save them (including nested groups) for (GroupDTO groupDTO : dtos.getGroups()) { - CustomerParamGroupById entity = saveGroupWithChildren(groupDTO, null, requestId, txnId); // null is for root - // (no + CustomerParamGroupById entity = saveGroupWithChildren(groupDTO, null, requestId, txnId, userId); // null is + // for + // root + // (no // parent group) entities.add(entity); // Add the saved entity to the list @@ -263,7 +266,7 @@ public class BillerMapperHelper { } private CustomerParamGroupById saveGroupWithChildren(GroupDTO groupDTO, CustomerParamGroupById parentGroup, - String requestId, String txnId) { + String requestId, String txnId, String userId) { // Create a new entity for the group CustomerParamGroupById groupEntity = new CustomerParamGroupById(); @@ -273,6 +276,7 @@ public class BillerMapperHelper { groupEntity.setParentGroup(parentGroup); // Link to the parent group (if exists) groupEntity.setRequestId(requestId); groupEntity.setTxnId(txnId); + groupEntity.setUserId(userId); groupEntity.setCreateDateTime(new Date()); // Save group parameters (if any) if (groupDTO.getParams() != null && !groupDTO.getParams().isEmpty()) { @@ -290,8 +294,8 @@ public class BillerMapperHelper { if (groupDTO.getGroups() != null && !groupDTO.getGroups().isEmpty()) { List childEntities = new ArrayList<>(); for (GroupDTO childGroupDTO : groupDTO.getGroups()) { - CustomerParamGroupById childEntity = saveGroupWithChildren(childGroupDTO, groupEntity, requestId, - txnId); // Pass + CustomerParamGroupById childEntity = saveGroupWithChildren(childGroupDTO, groupEntity, requestId, txnId, + userId); // Pass // current // group // as @@ -346,7 +350,8 @@ public class BillerMapperHelper { } // Method to save AmountOptionsResponse and AmountOption entities - public String saveAmountOptionsResponse(AmountOptionsResponse responseWrapper, String requestId, String txnId) { + public String saveAmountOptionsResponse(AmountOptionsResponse responseWrapper, String requestId, String txnId, + String userId) { // Convert AmountOptionsResponseDTO to AmountOptionsResponse entity if (responseWrapper == null) { @@ -358,14 +363,10 @@ public class BillerMapperHelper { // Map AmountOptionDTO list to AmountOptionDetails entities List amountOptionDetailsList = mapAmountOptionDTOToEntity( - responseWrapper.getAmountOptionDAOS(), requestId, txnId); - - // Set the mapped AmountOptionDetails list to AmountOptionByBillerId entity + responseWrapper.getAmountOptionDAOS(), requestId, txnId, userId); entity.setAmountOptionDetails(amountOptionDetailsList); entity.setCreateDateTime(new Date()); - // Save AmountOptionByBillerId entity (this will also save related - // AmountOptionDetails entities) amountOptionByBillerIdRepository.save(entity); // Saves the entity and cascades to AmountOptionDetails // Return success message @@ -373,7 +374,7 @@ public class BillerMapperHelper { } private List mapAmountOptionDTOToEntity(List amountOptionDTOs, - String requestId, String txnId) { + String requestId, String txnId, String userId) { // If the list is null or empty, return an empty list of entities if (amountOptionDTOs == null || amountOptionDTOs.isEmpty()) { @@ -397,13 +398,14 @@ public class BillerMapperHelper { amountOptionDetails.setAmountOptionId(dto.getAmountOptionId()); amountOptionDetails.setRequestId(requestId); amountOptionDetails.setTxnId(txnId); + amountOptionDetails.setUserId(userId); // Return the mapped AmountOptionDetails entity return amountOptionDetails; })).collect(Collectors.toList()); // Collect them into a list and return } - public PlanResponses savePlanResponse(PlanResponse planResponse, String reqId, String txnId) { + public PlanResponses savePlanResponse(PlanResponse planResponse, String reqId, String txnId, String userId) { PlanResponses response = new PlanResponses(); response.setRequestId(reqId); response.setPageNo(planResponse.getPageNo()); @@ -411,6 +413,7 @@ public class BillerMapperHelper { response.setTotalElements(planResponse.getTotalElements()); response.setTotalPages(planResponse.getTotalPages()); response.setTxnId(txnId); + response.setUserId(userId); response.setCreateDateTime(new Date()); PlansList plansList = new PlansList(); @@ -472,7 +475,7 @@ public class BillerMapperHelper { return planResponseRepository.save(response); } - public String saveCategoryItems(List categoryRespList, String requestId, String txnId) { + public String saveCategoryItems(List categoryRespList, String requestId, String txnId, String userId) { int savedCount = 0; // To track how many items were saved if (categoryRespList == null || categoryRespList.isEmpty()) { @@ -485,13 +488,14 @@ public class BillerMapperHelper { category.setRequestId(txnId); category.setRequestId(requestId); category.setCreateDateTime(new Date()); + category.setUserId(userId); categoryResponseListRepository.save(category); savedCount++; } return savedCount + " items were successfully saved."; } - public String saveComplaintStatus(TicketCheckStatusResponse response, String reqId, String txnId) { + public String saveComplaintStatus(TicketCheckStatusResponse response, String reqId, String txnId, String userId) { if (response == null || response.getTicketDetails() == null) { throw new CustomException("Invalid response received!", "FAILURE", 500, "Response Null"); @@ -531,6 +535,7 @@ public class BillerMapperHelper { entity.setNpciTicketStatus(dto.getNpciTicketStatus()); entity.setCreatedTime(dto.getCreatedTime()); entity.setCreateDateTime(new Date()); + entity.setUserId(userId); try { ComplainStatus saved = complaintStatusRepository.save(entity); @@ -541,7 +546,8 @@ public class BillerMapperHelper { } } - public String saveComplaintHistory(ComplaintHistoryStatusResponse responseWrapper, String reqId, String txnId) { + public String saveComplaintHistory(ComplaintHistoryStatusResponse responseWrapper, String reqId, String txnId, + String userId) { if (responseWrapper == null || responseWrapper.getTicketHistories() == null || responseWrapper.getTicketHistories().isEmpty()) { return "No complaint history data found to save."; @@ -560,6 +566,7 @@ public class BillerMapperHelper { entity.setReqId(reqId); entity.setTxnId(txnId); entity.setCreateDateTime(new Date()); + entity.setUserId(userId); complaintHistoryRepository.save(entity); savedCount++; @@ -656,7 +663,8 @@ public class BillerMapperHelper { return finalJson; } - public String saveComplainStatusDetail(ViewComplainByIdResponse responseWrapper, String reqId, String txnId) { + public String saveComplainStatusDetail(ViewComplainByIdResponse responseWrapper, String reqId, String txnId, + String userId) { ModelMapper mapper = new ModelMapper(); mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); @@ -674,6 +682,7 @@ public class BillerMapperHelper { entity.setPage(String.valueOf(responseWrapper.getPage())); entity.setPageSize(String.valueOf(responseWrapper.getPageSize())); entity.setCreateDateTime(new Date()); + entity.setUserId(userId); } @@ -794,7 +803,7 @@ public class BillerMapperHelper { } public String saveTicketDisoptionDetails(List dispositionsList, String requestId, - String txnId) { + String txnId, String userId) { if (dispositionsList == null || dispositionsList.isEmpty()) { return "No disposition data received."; @@ -820,7 +829,7 @@ public class BillerMapperHelper { entity.setCreateDateTime(new Date()); entity.setTxnId(txnId); entity.setReqId(requestId); - + entity.setUserId(userId); ticketDispositionRepository.save(entity); savedCount++; } @@ -833,7 +842,8 @@ public class BillerMapperHelper { } } - public String saveAllComplaints(ViewAllComplaintsTicketsResponse responseWrapper, String reqId, String txnId) { + public String saveAllComplaints(ViewAllComplaintsTicketsResponse responseWrapper, String reqId, String txnId, + String userId) { ModelMapper mapper = new ModelMapper(); mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); @@ -851,6 +861,7 @@ public class BillerMapperHelper { entity.setTotalPages(String.valueOf(responseWrapper.getTotalPages())); entity.setTotalElements(String.valueOf(responseWrapper.getTotalElements())); entity.setCreateDateTime(new Date()); + entity.setUserId(userId); } @@ -907,6 +918,7 @@ public class BillerMapperHelper { billMaster.setUserId(responseWrapper.getUserId()); billMaster.setReqId(billFetchByBillIdRequest.getReqId()); billMaster.setTxnId(txnId); + billMaster.setClientUserId(billFetchByBillIdRequest.getClientUserId()); // BILLER RESPONSE BillerResponse billerResponse = new BillerResponse(); @@ -961,7 +973,8 @@ public class BillerMapperHelper { billMasterRepository.save(billMaster); } - public void saveBillValidation(FetchBillValidateResponse responseWrapper, BillFetchByBillIdRequest billRequest) { + public void saveBillValidation(FetchBillValidateResponse responseWrapper, BillFetchByBillIdRequest billRequest, + String txnId) { System.out.println("responseWrapper"); ModelMapper modelMapper = new ModelMapper(); @@ -988,6 +1001,9 @@ public class BillerMapperHelper { return ai; }).collect(Collectors.toList()); billEntity.setAdditionalInfo(additionalInfos); + billEntity.setClientUserId(billRequest.getClientUserId()); + billEntity.setTxnId(txnId); + billEntity.setRefId(billRequest.getReqId()); } // ✅ Save everything (cascade handles child) @@ -1198,7 +1214,8 @@ public class BillerMapperHelper { } } - public String saveComplaintResponseEntity(ComplaintResponse responseWrapper, String requestId, String txnId,String userId) { + public String saveComplaintResponseEntity(ComplaintResponse responseWrapper, String requestId, String txnId, + String userId) { // 1. Convert ComplaintResponse DTO to ComplaintResponseEntity ComplaintResponseEntity complaintResponseEntity = new ComplaintResponseEntity(); diff --git a/src/main/java/com/billpaymentservice/bbps/util/Helper.java b/src/main/java/com/billpaymentservice/bbps/util/Helper.java index ff51436..1022e8e 100644 --- a/src/main/java/com/billpaymentservice/bbps/util/Helper.java +++ b/src/main/java/com/billpaymentservice/bbps/util/Helper.java @@ -3,7 +3,7 @@ package com.billpaymentservice.bbps.util; import java.security.SecureRandom; import java.time.LocalDateTime; import java.util.Date; -import java.util.UUID; +import java.util.Random; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -210,15 +210,20 @@ public class Helper { } private String generateUniqueUserId() { - String userId = UUID.randomUUID().toString(); // Generate UUID + Random random = new Random(); + + // Generate a random 6-digit number (between 100000 and 999999) + String userId = String.format("USER%06d", random.nextInt(900000) + 100000); // Format as USER-XXXXXX // Check if the userId already exists in the database (theoretically rare but // can happen) while (userRepository.existsByUserId(userId)) { // If it exists, generate a new one - userId = UUID.randomUUID().toString(); + userId = String.format("USER-%06d", random.nextInt(900000) + 100000); // Generate new 6-digit number with + // prefix } return userId; } + } \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 4eaafbc..aaf1e10 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -20,9 +20,9 @@ swagger.server.description=Local Development Server # DataSource spring.datasource.url=jdbc:postgresql://localhost:5432/BBPS spring.datasource.username=postgres -#spring.datasource.password=UAT@DB_2025 +spring.datasource.password=UAT@DB_2025 -spring.datasource.password=himanshu@123 +#spring.datasource.password=himanshu@123 spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.type=com.zaxxer.hikari.HikariDataSource