|
1 | 1 | package com.back.b2st.domain.payment.controller; |
2 | 2 |
|
3 | 3 | import org.springframework.http.ResponseEntity; |
4 | | -import org.springframework.web.bind.annotation.PathVariable; |
5 | 4 | import org.springframework.web.bind.annotation.PostMapping; |
6 | 5 | import org.springframework.web.bind.annotation.RequestBody; |
7 | 6 | import org.springframework.web.bind.annotation.RequestMapping; |
8 | 7 | import org.springframework.web.bind.annotation.RestController; |
9 | 8 |
|
10 | | -import com.back.b2st.domain.payment.dto.request.PaymentCancelReq; |
11 | | -import com.back.b2st.domain.payment.dto.request.PaymentConfirmReq; |
12 | | -import com.back.b2st.domain.payment.dto.request.PaymentFailReq; |
13 | | -import com.back.b2st.domain.payment.dto.request.PaymentPrepareReq; |
14 | | -import com.back.b2st.domain.payment.dto.response.PaymentCancelRes; |
| 9 | +import com.back.b2st.domain.payment.dto.request.PaymentPayReq; |
15 | 10 | import com.back.b2st.domain.payment.dto.response.PaymentConfirmRes; |
16 | | -import com.back.b2st.domain.payment.dto.response.PaymentFailRes; |
17 | | -import com.back.b2st.domain.payment.dto.response.PaymentPrepareRes; |
18 | 11 | import com.back.b2st.domain.payment.entity.Payment; |
19 | | -import com.back.b2st.domain.payment.service.PaymentCancelService; |
20 | | -import com.back.b2st.domain.payment.service.PaymentConfirmService; |
21 | | -import com.back.b2st.domain.payment.service.PaymentFailService; |
22 | | -import com.back.b2st.domain.payment.service.PaymentPrepareService; |
23 | | -import com.back.b2st.domain.reservation.service.ReservationService; |
| 12 | +import com.back.b2st.domain.payment.service.PaymentOneClickService; |
24 | 13 | import com.back.b2st.global.annotation.CurrentUser; |
25 | 14 | import com.back.b2st.global.common.BaseResponse; |
26 | 15 | import com.back.b2st.security.UserPrincipal; |
|
37 | 26 | @RequestMapping("/api/payments") |
38 | 27 | public class PaymentController { |
39 | 28 |
|
40 | | - private final PaymentPrepareService paymentPrepareService; |
41 | | - private final PaymentConfirmService paymentConfirmService; |
42 | | - private final PaymentCancelService paymentCancelService; |
43 | | - private final PaymentFailService paymentFailService; |
44 | | - |
45 | | - private final ReservationService reservationService; |
| 29 | + private final PaymentOneClickService paymentOneClickService; |
46 | 30 |
|
47 | 31 | @Operation( |
48 | | - summary = "결제 준비", |
49 | | - description = "결제 정보를 생성하고 orderId를 반환합니다." |
| 32 | + summary = "원클릭 결제 (PG 미사용)", |
| 33 | + description = "결제 준비/승인/도메인 후처리를 한 번에 수행합니다.\n\n" |
| 34 | + + "- LOTTERY: entryId(UUID) 필수\n" |
| 35 | + + "- 그 외: domainId(Long) 필수" |
50 | 36 | ) |
51 | | - @PostMapping("/prepare") |
52 | | - public ResponseEntity<BaseResponse<PaymentPrepareRes>> prepare( |
| 37 | + @PostMapping("/pay") |
| 38 | + public ResponseEntity<BaseResponse<PaymentConfirmRes>> pay( |
53 | 39 | @Parameter(hidden = true) @CurrentUser UserPrincipal user, |
54 | | - @Valid @RequestBody PaymentPrepareReq request |
| 40 | + @Valid @RequestBody PaymentPayReq request |
55 | 41 | ) { |
56 | | - Payment payment = paymentPrepareService.prepare(user.getId(), request); |
57 | | - return ResponseEntity.ok(BaseResponse.created(PaymentPrepareRes.from(payment))); |
58 | | - } |
59 | | - |
60 | | - @Operation( |
61 | | - summary = "결제 승인", |
62 | | - description = "결제를 승인하고 도메인별 후처리를 수행합니다." |
63 | | - ) |
64 | | - @PostMapping("/confirm") |
65 | | - public ResponseEntity<BaseResponse<PaymentConfirmRes>> confirm( |
66 | | - @Parameter(hidden = true) @CurrentUser UserPrincipal user, |
67 | | - @Valid @RequestBody PaymentConfirmReq request |
68 | | - ) { |
69 | | - Payment payment = paymentConfirmService.confirm(user.getId(), request); |
| 42 | + Payment payment = paymentOneClickService.pay(user.getId(), request); |
70 | 43 | return ResponseEntity.ok(BaseResponse.success(PaymentConfirmRes.from(payment))); |
71 | 44 | } |
72 | | - |
73 | | - @Operation( |
74 | | - summary = "결제 취소", |
75 | | - description = "완료된 결제를 취소합니다.\n\n" |
76 | | - + "- 티켓 거래(TRADE) 결제는 취소/환불을 지원하지 않습니다.\n" |
77 | | - + "- 예매(RESERVATION) 결제는 취소/환불을 지원하지 않습니다." |
78 | | - ) |
79 | | - @PostMapping("/{orderId}/cancel") |
80 | | - public ResponseEntity<BaseResponse<PaymentCancelRes>> cancel( |
81 | | - @Parameter(description = "주문 ID", example = "ORDER-123") @PathVariable("orderId") String orderId, |
82 | | - @Valid @RequestBody PaymentCancelReq request, |
83 | | - @Parameter(hidden = true) @CurrentUser UserPrincipal user |
84 | | - ) { |
85 | | - Payment canceledPayment = paymentCancelService.cancel(user.getId(), orderId, request); |
86 | | - return ResponseEntity.ok(BaseResponse.success(PaymentCancelRes.from(canceledPayment))); |
87 | | - } |
88 | | - |
89 | | - @Operation( |
90 | | - summary = "결제 실패 처리", |
91 | | - description = "결제 실패 시 호출되며, 도메인별 실패 후처리를 수행합니다." |
92 | | - ) |
93 | | - @PostMapping("/{orderId}/fail") |
94 | | - public ResponseEntity<BaseResponse<PaymentFailRes>> fail( |
95 | | - @Parameter(description = "주문 ID", example = "ORDER-123") @PathVariable("orderId") String orderId, |
96 | | - @Valid @RequestBody PaymentFailReq request, |
97 | | - @Parameter(hidden = true) @CurrentUser UserPrincipal user |
98 | | - ) { |
99 | | - Payment payment = paymentFailService.fail(user.getId(), orderId, request.reason().name()); |
100 | | - return ResponseEntity.ok(BaseResponse.success(PaymentFailRes.from(payment))); |
101 | | - } |
102 | 45 | } |
0 commit comments