From 08d5509c1aa03138bd2d70df90b1d941c9bc4e1e Mon Sep 17 00:00:00 2001 From: Lincpay Tech Date: Mon, 24 Nov 2025 13:07:26 +0530 Subject: [PATCH] added basic strcture for the callbackapi --- .../bbps/controller/AgentController.java | 18 ++++++- .../bbps/service/AgentService.java | 6 +++ .../bbps/service/PaymentService.java | 10 ++-- .../bbps/serviceImpl/AgentServiceImpl.java | 47 ++++++++++++++++++- .../bbps/serviceImpl/PaymentServiceImpl.java | 18 +++++++ 5 files changed, 93 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java b/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java index 1fed6a0..a9edc93 100644 --- a/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java +++ b/src/main/java/com/billpaymentservice/bbps/controller/AgentController.java @@ -9,12 +9,15 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.billpaymentservice.bbps.dto.GeneralResp; import com.billpaymentservice.bbps.dto.ResponseModel; import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest; import com.billpaymentservice.bbps.dto.request.BillFetchByClientIdRequest; import com.billpaymentservice.bbps.dto.request.BillValidateByClientIdRequest; import com.billpaymentservice.bbps.dto.request.FetchBillRequest; import com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest; +import com.billpaymentservice.bbps.dto.response.BillDataResponse; +import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; import com.billpaymentservice.bbps.service.AgentService; @RestController @@ -86,5 +89,18 @@ public class AgentController { 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); + // 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); + // Return a response indicating successful receipt + return ResponseEntity.ok(genralResp); + } } diff --git a/src/main/java/com/billpaymentservice/bbps/service/AgentService.java b/src/main/java/com/billpaymentservice/bbps/service/AgentService.java index 3c5347b..1ebc1ce 100644 --- a/src/main/java/com/billpaymentservice/bbps/service/AgentService.java +++ b/src/main/java/com/billpaymentservice/bbps/service/AgentService.java @@ -6,6 +6,8 @@ import com.billpaymentservice.bbps.dto.request.BillFetchByClientIdRequest; import com.billpaymentservice.bbps.dto.request.BillValidateByClientIdRequest; import com.billpaymentservice.bbps.dto.request.FetchBillRequest; import com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest; +import com.billpaymentservice.bbps.dto.response.BillDataResponse; +import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse; public interface AgentService { @@ -21,4 +23,8 @@ public interface AgentService { ResponseModel fetchBillValidateByClientReqId( BillValidateByClientIdRequest billValidateByClientIdRequest); + ResponseModel processBillFetchCallback(BillDataResponse billDataResponse); + + ResponseModel processBillValidateCallback(FetchBillValidateResponse billDataResponse); + } diff --git a/src/main/java/com/billpaymentservice/bbps/service/PaymentService.java b/src/main/java/com/billpaymentservice/bbps/service/PaymentService.java index e724dd6..c932c0f 100644 --- a/src/main/java/com/billpaymentservice/bbps/service/PaymentService.java +++ b/src/main/java/com/billpaymentservice/bbps/service/PaymentService.java @@ -4,13 +4,17 @@ import com.billpaymentservice.bbps.dto.ResponseModel; import com.billpaymentservice.bbps.dto.request.BillPaymentRequest; import com.billpaymentservice.bbps.dto.request.TransactionStatusRequest; import com.billpaymentservice.bbps.dto.request.TrasactionStatusByClientReqIdRequest; +import com.billpaymentservice.bbps.dto.response.TransactionStatusResponse; public interface PaymentService { - public ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest); + ResponseModel initiatePayment(BillPaymentRequest billPaymentRequest); - public ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest); + ResponseModel checkTrasactionStatus(TransactionStatusRequest transactionStatusRequest); - ResponseModel checkTrasactionStatusByClientReqId(TrasactionStatusByClientReqIdRequest transactionStatusRequest); + ResponseModel checkTrasactionStatusByClientReqId(TrasactionStatusByClientReqIdRequest transactionStatusRequest); + + ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse); + } diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java index 988fc39..6db3df9 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/AgentServiceImpl.java @@ -368,7 +368,6 @@ public class AgentServiceImpl implements AgentService { billFetchByBillIdRequest.setReqId(reqId); LOGGER.info("Waiting for 2 seconds before fetching bill by ID..."); try { - Thread.sleep(12000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -648,9 +647,53 @@ public class AgentServiceImpl implements AgentService { throw new CustomException("Invalid JSON received from API"); } } +//================================== End Bill fetch and Bill Validate by Client Req Id==================================// +//===================================Callback Methods BillFetch and BillValidate ==================================// + + @Override + public ResponseModel processBillFetchCallback(BillDataResponse billDataResponse) { + + LOGGER.info("Recived Call Back from billDataResponse: {}", billDataResponse); + if(billDataResponse.getGenericResponse().getStatusCode().equals("200")) { + + } + else { + LOGGER.info("Bill Fetch Callback Failed with Status: {}", billDataResponse.getGenericResponse().getStatus()); + + } + + return new ResponseModel("CallBack Recieved Successfully", + "200", + 200, + ""); + + } + +@Override +public ResponseModel processBillValidateCallback(FetchBillValidateResponse billValidateResponse) { + LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", billValidateResponse); + if(billValidateResponse.getGenericResponse().getStatusCode().equals("200")) { + + } + else { + LOGGER.info("Bill Fetch Callback Failed with Status: {}", billValidateResponse.getGenericResponse().getStatus()); + + } + + return new ResponseModel("CallBack Recieved Successfully", + "200", + 200, + ""); + + +}} + + + /* + * @Override public ResponseModel * initiateBillValidate(FetchBillValidatestRequest fetchBillValidateRequest) { * @@ -838,4 +881,4 @@ public class AgentServiceImpl implements AgentService { */ -} + diff --git a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java index f0bbb9b..2746039 100644 --- a/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java +++ b/src/main/java/com/billpaymentservice/bbps/serviceImpl/PaymentServiceImpl.java @@ -398,6 +398,24 @@ public class PaymentServiceImpl implements PaymentService { throw new CustomException("Invalid JSON received from API"); } } + + @Override + public ResponseModel handlePaymentIntiateCallback(TransactionStatusResponse transactionStatusResponse) { + + LOGGER.info("Recived Call Back from FetchBillValidateResponse: {}", transactionStatusResponse); + if(transactionStatusResponse.getGeneralResp().getStatusCode().equals("200")) { + + } + else { + LOGGER.info("Bill Fetch Callback Failed with Status: {}", transactionStatusResponse.getGeneralResp().getStatus()); + + } + + return new ResponseModel("CallBack Recieved Successfully", + "200", + 200, + ""); + } } /* PollBack logic for the fetchTxnByTxnId API * @Override public ResponseModel fetchTxnByTxnId(BillFetchByBillIdRequest