44import org .springframework .http .HttpStatus ;
55import org .springframework .http .ResponseEntity ;
66import org .springframework .web .bind .annotation .GetMapping ;
7- import org .springframework .web .bind .annotation .PathVariable ;
87import org .springframework .web .bind .annotation .PostMapping ;
98import org .springframework .web .bind .annotation .RequestBody ;
109import org .springframework .web .bind .annotation .RequestMapping ;
1110import org .springframework .web .bind .annotation .RequestParam ;
1211import org .springframework .web .bind .annotation .RestController ;
1312
14- import com .threestar .trainus .domain .payment .dto .CancelPaymentRequestDto ;
1513import com .threestar .trainus .domain .payment .dto .ConfirmPaymentRequestDto ;
16- import com .threestar .trainus .domain .payment .dto .PaymentClient ;
1714import com .threestar .trainus .domain .payment .dto .PaymentRequestDto ;
1815import com .threestar .trainus .domain .payment .dto .PaymentResponseDto ;
1916import com .threestar .trainus .domain .payment .dto .SaveAmountRequestDto ;
20- import com .threestar .trainus .domain .payment .dto .TossPaymentResponseDto ;
21- import com .threestar .trainus .domain .payment .dto .failure . FailurePaymentResponseDto ;
22- import com .threestar .trainus .domain .payment .dto .failure . PaymentFailureHistoryPageDto ;
23- import com .threestar .trainus .domain .payment .dto .failure . PaymentFailurePageWrapperDto ;
17+ import com .threestar .trainus .domain .payment .dto .cancel . CancelPaymentRequestDto ;
18+ import com .threestar .trainus .domain .payment .dto .cancel . CancelPaymentResponseDto ;
19+ import com .threestar .trainus .domain .payment .dto .cancel . PaymentCancelHistoryPageDto ;
20+ import com .threestar .trainus .domain .payment .dto .cancel . PaymentCancelPageWrapperDto ;
2421import com .threestar .trainus .domain .payment .dto .success .PaymentSuccessHistoryPageDto ;
2522import com .threestar .trainus .domain .payment .dto .success .PaymentSuccessPageWrapperDto ;
2623import com .threestar .trainus .domain .payment .dto .success .SuccessfulPaymentResponseDto ;
2724import com .threestar .trainus .domain .payment .mapper .PaymentMapper ;
2825import com .threestar .trainus .domain .payment .service .PaymentService ;
26+ import com .threestar .trainus .global .annotation .LoginUser ;
2927import com .threestar .trainus .global .unit .BaseResponse ;
3028import com .threestar .trainus .global .unit .PagedResponse ;
3129
3230import io .swagger .v3 .oas .annotations .Operation ;
3331import io .swagger .v3 .oas .annotations .tags .Tag ;
3432import jakarta .servlet .http .HttpSession ;
33+ import jakarta .validation .Valid ;
3534import lombok .RequiredArgsConstructor ;
3635import lombok .extern .slf4j .Slf4j ;
3736
4241@ RequiredArgsConstructor
4342public class PaymentController {
4443
45- private final PaymentClient tossPaymentClient ;
4644 private final PaymentService paymentService ;
4745
4846 @ Value ("${spring.page.size.limit}" )
4947 private int pageSizeLimit ;
5048
5149 @ PostMapping ("/prepare" )
5250 @ Operation (summary = "결제 준비" , description = "실제 결제 전 최종 가격 적용 후 결제 준비" )
53- public ResponseEntity <BaseResponse <PaymentResponseDto >> preparePayment (HttpSession session ,
54- @ RequestBody PaymentRequestDto request ) {
55- Long userId = ( Long ) session . getAttribute ( "LOGIN_USER" );
51+ public ResponseEntity <BaseResponse <PaymentResponseDto >> preparePayment (
52+ @ Valid @ RequestBody PaymentRequestDto request ,
53+ @ LoginUser Long userId ) {
5654 PaymentResponseDto response = paymentService .preparePayment (request , userId );
5755 return BaseResponse .ok ("결제 정보 준비 완료" , response , HttpStatus .OK );
5856 }
5957
6058 @ PostMapping ("/saveAmount" )
6159 @ Operation (summary = "결제 검증 데이터 저장" , description = "결제 무결성 검증을 위한 데이터 저장" )
6260 public ResponseEntity <BaseResponse <Void >> saveAmount (HttpSession session ,
63- @ RequestBody SaveAmountRequestDto request ) {
61+ @ Valid @ RequestBody SaveAmountRequestDto request ) {
6462 session .setAttribute (request .orderId (), request .amount ());
6563 return BaseResponse .ok ("Payment temp save Successful" , null , HttpStatus .OK );
6664 }
6765
6866 @ PostMapping ("/verifyAmount" )
6967 @ Operation (summary = "결제 검증 데이터 확인" , description = "결제 무결성 검증을 위한 데이터 확인" )
7068 public ResponseEntity <BaseResponse <Void >> verifyAmount (HttpSession session ,
71- @ RequestBody SaveAmountRequestDto request ) {
69+ @ Valid @ RequestBody SaveAmountRequestDto request ) {
7270 Integer amount = (Integer )session .getAttribute (request .orderId ());
7371 try {
7472 if (amount == null || !amount .equals (request .amount ())) {
@@ -83,27 +81,23 @@ public ResponseEntity<BaseResponse<Void>> verifyAmount(HttpSession session,
8381 @ PostMapping ("/confirm" )
8482 @ Operation (summary = "결제 진행" , description = "결제 진행" )
8583 public ResponseEntity <BaseResponse <SuccessfulPaymentResponseDto >> confirm (
86- @ RequestBody ConfirmPaymentRequestDto request ) {
87- TossPaymentResponseDto tossResponse = tossPaymentClient .confirmPayment (request );
88- SuccessfulPaymentResponseDto payResult = paymentService .processConfirm (tossResponse );
89- return BaseResponse .ok ("결제 성공" , payResult , HttpStatus .OK );
84+ @ Valid @ RequestBody ConfirmPaymentRequestDto request ) {
85+ return BaseResponse .ok ("결제 성공" , paymentService .processConfirm (request ), HttpStatus .OK );
9086 }
9187
9288 @ PostMapping ("/cancel" )
9389 @ Operation (summary = "결제 취소" , description = "결제 취소" )
94- public ResponseEntity <BaseResponse <FailurePaymentResponseDto >> cancel (
95- @ RequestBody CancelPaymentRequestDto request ) {
96- TossPaymentResponseDto tossResponse = tossPaymentClient .cancelPayment (request );
97- FailurePaymentResponseDto payResult = paymentService .processCancel (tossResponse , request .cancelReason ());
98- return BaseResponse .ok ("결제 취소 성공" , payResult , HttpStatus .OK );
90+ public ResponseEntity <BaseResponse <CancelPaymentResponseDto >> cancel (
91+ @ Valid @ RequestBody CancelPaymentRequestDto request ) {
92+ return BaseResponse .ok ("결제 취소 성공" , paymentService .processCancel (request ), HttpStatus .OK );
9993 }
10094
10195 @ GetMapping ("/view/success" )
10296 @ Operation (summary = "완료 결제 조회" , description = "완료된 결제 내역 조회" )
103- public ResponseEntity <PagedResponse <PaymentSuccessPageWrapperDto >> readAll (HttpSession session ,
97+ public ResponseEntity <PagedResponse <PaymentSuccessPageWrapperDto >> readAll (
10498 @ RequestParam ("page" ) int page ,
105- @ RequestParam ("pageSize" ) int pageSize ) {
106- Long userId = ( Long ) session . getAttribute ( "LOGIN_USER" );
99+ @ RequestParam ("pageSize" ) int pageSize ,
100+ @ LoginUser Long userId ) {
107101 int correctPage = Math .max (page , 1 );
108102 int correctPageSize = Math .max (1 , Math .min (pageSize , pageSizeLimit ));
109103 PaymentSuccessHistoryPageDto paymentSuccessHistoryPageDto = paymentService .viewAllSuccessTransaction (userId ,
@@ -115,24 +109,16 @@ public ResponseEntity<PagedResponse<PaymentSuccessPageWrapperDto>> readAll(HttpS
115109
116110 @ GetMapping ("/view/cancel" )
117111 @ Operation (summary = "취소 결제 조회" , description = "취소된 결제 내역 조회" )
118- public ResponseEntity <PagedResponse <PaymentFailurePageWrapperDto >> readAllFailure (HttpSession session ,
112+ public ResponseEntity <PagedResponse <PaymentCancelPageWrapperDto >> readAllFailure (HttpSession session ,
119113 @ RequestParam ("page" ) int page ,
120- @ RequestParam ("pageSize" ) int pageSize ) {
121- Long userId = ( Long ) session . getAttribute ( "LOGIN_USER" );
114+ @ RequestParam ("pageSize" ) int pageSize ,
115+ @ LoginUser Long userId ) {
122116 int correctPage = Math .max (page , 1 );
123117 int correctPageSize = Math .max (1 , Math .min (pageSize , pageSizeLimit ));
124- PaymentFailureHistoryPageDto paymentFailureHistoryPageDto = paymentService .viewAllFailureTransaction (userId ,
118+ PaymentCancelHistoryPageDto paymentCancelHistoryPageDto = paymentService .viewAllFailureTransaction (userId ,
125119 correctPage , correctPageSize );
126- PaymentFailurePageWrapperDto payments = PaymentMapper .toPaymentFailurePageWrapperDto (
127- paymentFailureHistoryPageDto );
128- return PagedResponse .ok ("취소 결제 조회 성공" , payments , paymentFailureHistoryPageDto .count (), HttpStatus .OK );
120+ PaymentCancelPageWrapperDto payments = PaymentMapper .toPaymentFailurePageWrapperDto (
121+ paymentCancelHistoryPageDto );
122+ return PagedResponse .ok ("취소 결제 조회 성공" , payments , paymentCancelHistoryPageDto .count (), HttpStatus .OK );
129123 }
130-
131- @ GetMapping ("/{paymentKey}" )
132- @ Operation (summary = "상세 결제 조회" , description = "상세 결제 내역 조회" )
133- public ResponseEntity <BaseResponse <TossPaymentResponseDto >> readDetailPayment (
134- @ PathVariable ("paymentKey" ) String paymentKey ) {
135- return BaseResponse .ok ("상세 결제 조회 완료" , tossPaymentClient .viewDetailPayment (paymentKey ), HttpStatus .OK );
136- }
137-
138124}
0 commit comments