78 lines
3.9 KiB
Java
78 lines
3.9 KiB
Java
package com.billpaymentservice.bbps.controller;
|
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
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.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.service.PaymentService;
|
|
import com.billpaymentservice.bbps.service.PaymentStartService;
|
|
import com.billpaymentservice.bbps.util.ApiDocCommonResponses;
|
|
import com.billpaymentservice.bbps.util.BBPSConstant;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.media.Content;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
|
|
@RestController
|
|
@RequestMapping("/agent/payment")
|
|
public class PaymentController {
|
|
|
|
/**
|
|
* Fetches bill details from external BBPS service
|
|
*/
|
|
|
|
private final PaymentService paymentService;
|
|
private final PaymentStartService paymentStartService;
|
|
|
|
public PaymentController(PaymentService paymentService, PaymentStartService paymentStartService) {
|
|
this.paymentService = paymentService;
|
|
this.paymentStartService = paymentStartService;
|
|
}
|
|
|
|
@PostMapping(value = "/intiatePayment")
|
|
@Operation(summary = "Initiate payment request", description = "This API initiates the payment process for the provided bill payment request.")
|
|
@ApiResponses(value = {
|
|
@ApiResponse(responseCode = BBPSConstant.OK_STR, description = "Payment initiated successfully", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseModel.class))) })
|
|
@ApiDocCommonResponses
|
|
public ResponseEntity<ResponseModel> requestBillFetch(
|
|
@Validated @RequestBody BillPaymentRequest billPaymentRequest) {
|
|
|
|
ResponseModel response = paymentService.initiatePayment(billPaymentRequest);
|
|
return ResponseEntity.ok(response);
|
|
}
|
|
|
|
@PostMapping(value = "/checkTransactionStatus")
|
|
@Operation(summary = "Check transaction status", description = "This API checks the current status of a bill payment transaction using transactionId or clientReqId.")
|
|
@ApiResponses(value = {
|
|
@ApiResponse(responseCode = BBPSConstant.OK_STR, description = "Transaction status fetched successfully", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseModel.class))) })
|
|
@ApiDocCommonResponses
|
|
public ResponseEntity<ResponseModel> checkTransactionStatus(
|
|
@Validated @RequestBody TransactionStatusRequest transactionStatusRequest) {
|
|
|
|
ResponseModel response = paymentService.checkTrasactionStatus(transactionStatusRequest);
|
|
return ResponseEntity.ok(response);
|
|
}
|
|
|
|
@PostMapping(value = "/checkTransactionStatusByClientReqId")
|
|
@Operation(summary = "Check transaction status by client request ID", description = "This API checks the payment transaction status using the client-generated request ID (clientReqId).")
|
|
@ApiResponses(value = {
|
|
@ApiResponse(responseCode = BBPSConstant.OK_STR, description = "Transaction status fetched successfully using clientReqId", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseModel.class))) })
|
|
@ApiDocCommonResponses
|
|
public ResponseEntity<ResponseModel> checkTransactionStatusByClientReqId(
|
|
@Validated @RequestBody TrasactionStatusByClientReqIdRequest transactionStatusRequest) {
|
|
|
|
ResponseModel response = paymentService.checkTrasactionStatusByClientReqId(transactionStatusRequest);
|
|
return ResponseEntity.ok(response);
|
|
}
|
|
|
|
} |