-
Notifications
You must be signed in to change notification settings - Fork 2
feat : 결제 관련 응답 수정 및 서비스 단 검증 조건 추가 #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
65080de
feat: lesson 관련 메서드 업데이트
ense333 910b65e
feat: 레슨 취소 관련 서비스 추가
ense333 3613fbf
feat: 취소 관련 dto 추가
ense333 0e2c664
feat: 올바른 결제 가능한 유저인지 체크 추가
ense333 edb3533
feat: 응답 간에 paymentKey 삭제 및 파일 명 cancel로 변경
ense333 c89d21d
feat: 성공 응답 간에 paymentKey 삭제
ense333 09bcdaa
feat: 결제 관련 엔티티 변수 추가
ense333 6f91ac5
feat: 컨트롤러, 서비스, mapper, repository 수정
ense333 d76574a
feat: 결제 관련 에러코드 추가
ense333 43a7136
feat: mock 데이터 lessonParticipant 추가
ense333 6ef8c15
fix: conflict 해결
ense333 8ee5cbd
Feat: 쿠폰 관련 서비스 메서드 추가
ense333 6b88ae0
feat: 레슨 관련 조건 추가
ense333 17f7c26
Feat: 결제 관련 조건 추가 및 구조 리팩토링
ense333 e766e3b
feat: 결제 controller에 valid, LoginUser 어노테이션 적용
ense333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,34 +4,33 @@ | |
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| 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.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.threestar.trainus.domain.payment.dto.CancelPaymentRequestDto; | ||
| import com.threestar.trainus.domain.payment.dto.ConfirmPaymentRequestDto; | ||
| import com.threestar.trainus.domain.payment.dto.PaymentClient; | ||
| import com.threestar.trainus.domain.payment.dto.PaymentRequestDto; | ||
| import com.threestar.trainus.domain.payment.dto.PaymentResponseDto; | ||
| import com.threestar.trainus.domain.payment.dto.SaveAmountRequestDto; | ||
| import com.threestar.trainus.domain.payment.dto.TossPaymentResponseDto; | ||
| import com.threestar.trainus.domain.payment.dto.failure.FailurePaymentResponseDto; | ||
| import com.threestar.trainus.domain.payment.dto.failure.PaymentFailureHistoryPageDto; | ||
| import com.threestar.trainus.domain.payment.dto.failure.PaymentFailurePageWrapperDto; | ||
| import com.threestar.trainus.domain.payment.dto.cancel.CancelPaymentRequestDto; | ||
| import com.threestar.trainus.domain.payment.dto.cancel.CancelPaymentResponseDto; | ||
| import com.threestar.trainus.domain.payment.dto.cancel.PaymentCancelHistoryPageDto; | ||
| import com.threestar.trainus.domain.payment.dto.cancel.PaymentCancelPageWrapperDto; | ||
| import com.threestar.trainus.domain.payment.dto.success.PaymentSuccessHistoryPageDto; | ||
| import com.threestar.trainus.domain.payment.dto.success.PaymentSuccessPageWrapperDto; | ||
| import com.threestar.trainus.domain.payment.dto.success.SuccessfulPaymentResponseDto; | ||
| import com.threestar.trainus.domain.payment.mapper.PaymentMapper; | ||
| import com.threestar.trainus.domain.payment.service.PaymentService; | ||
| import com.threestar.trainus.global.annotation.LoginUser; | ||
| import com.threestar.trainus.global.unit.BaseResponse; | ||
| import com.threestar.trainus.global.unit.PagedResponse; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.servlet.http.HttpSession; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
|
|
@@ -42,33 +41,32 @@ | |
| @RequiredArgsConstructor | ||
| public class PaymentController { | ||
|
|
||
| private final PaymentClient tossPaymentClient; | ||
| private final PaymentService paymentService; | ||
|
|
||
| @Value("${spring.page.size.limit}") | ||
| private int pageSizeLimit; | ||
|
|
||
| @PostMapping("/prepare") | ||
| @Operation(summary = "결제 준비", description = "실제 결제 전 최종 가격 적용 후 결제 준비") | ||
| public ResponseEntity<BaseResponse<PaymentResponseDto>> preparePayment(HttpSession session, | ||
| @RequestBody PaymentRequestDto request) { | ||
| Long userId = (Long)session.getAttribute("LOGIN_USER"); | ||
| public ResponseEntity<BaseResponse<PaymentResponseDto>> preparePayment( | ||
| @Valid @RequestBody PaymentRequestDto request, | ||
| @LoginUser Long userId) { | ||
| PaymentResponseDto response = paymentService.preparePayment(request, userId); | ||
| return BaseResponse.ok("결제 정보 준비 완료", response, HttpStatus.OK); | ||
| } | ||
|
|
||
| @PostMapping("/saveAmount") | ||
| @Operation(summary = "결제 검증 데이터 저장", description = "결제 무결성 검증을 위한 데이터 저장") | ||
| public ResponseEntity<BaseResponse<Void>> saveAmount(HttpSession session, | ||
| @RequestBody SaveAmountRequestDto request) { | ||
| @Valid @RequestBody SaveAmountRequestDto request) { | ||
| session.setAttribute(request.orderId(), request.amount()); | ||
| return BaseResponse.ok("Payment temp save Successful", null, HttpStatus.OK); | ||
| } | ||
|
|
||
| @PostMapping("/verifyAmount") | ||
| @Operation(summary = "결제 검증 데이터 확인", description = "결제 무결성 검증을 위한 데이터 확인") | ||
| public ResponseEntity<BaseResponse<Void>> verifyAmount(HttpSession session, | ||
| @RequestBody SaveAmountRequestDto request) { | ||
| @Valid @RequestBody SaveAmountRequestDto request) { | ||
| Integer amount = (Integer)session.getAttribute(request.orderId()); | ||
| try { | ||
| if (amount == null || !amount.equals(request.amount())) { | ||
|
|
@@ -83,27 +81,23 @@ public ResponseEntity<BaseResponse<Void>> verifyAmount(HttpSession session, | |
| @PostMapping("/confirm") | ||
| @Operation(summary = "결제 진행", description = "결제 진행") | ||
| public ResponseEntity<BaseResponse<SuccessfulPaymentResponseDto>> confirm( | ||
| @RequestBody ConfirmPaymentRequestDto request) { | ||
| TossPaymentResponseDto tossResponse = tossPaymentClient.confirmPayment(request); | ||
| SuccessfulPaymentResponseDto payResult = paymentService.processConfirm(tossResponse); | ||
| return BaseResponse.ok("결제 성공", payResult, HttpStatus.OK); | ||
| @Valid @RequestBody ConfirmPaymentRequestDto request) { | ||
| return BaseResponse.ok("결제 성공", paymentService.processConfirm(request), HttpStatus.OK); | ||
| } | ||
|
|
||
| @PostMapping("/cancel") | ||
| @Operation(summary = "결제 취소", description = "결제 취소") | ||
| public ResponseEntity<BaseResponse<FailurePaymentResponseDto>> cancel( | ||
| @RequestBody CancelPaymentRequestDto request) { | ||
| TossPaymentResponseDto tossResponse = tossPaymentClient.cancelPayment(request); | ||
| FailurePaymentResponseDto payResult = paymentService.processCancel(tossResponse, request.cancelReason()); | ||
| return BaseResponse.ok("결제 취소 성공", payResult, HttpStatus.OK); | ||
| public ResponseEntity<BaseResponse<CancelPaymentResponseDto>> cancel( | ||
| @Valid @RequestBody CancelPaymentRequestDto request) { | ||
| return BaseResponse.ok("결제 취소 성공", paymentService.processCancel(request), HttpStatus.OK); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 더 깔끔한 응답 형태 반환인 것 같습니다! 참고해보겠습니다 |
||
| } | ||
|
|
||
| @GetMapping("/view/success") | ||
| @Operation(summary = "완료 결제 조회", description = "완료된 결제 내역 조회") | ||
| public ResponseEntity<PagedResponse<PaymentSuccessPageWrapperDto>> readAll(HttpSession session, | ||
| public ResponseEntity<PagedResponse<PaymentSuccessPageWrapperDto>> readAll( | ||
| @RequestParam("page") int page, | ||
| @RequestParam("pageSize") int pageSize) { | ||
| Long userId = (Long)session.getAttribute("LOGIN_USER"); | ||
| @RequestParam("pageSize") int pageSize, | ||
| @LoginUser Long userId) { | ||
| int correctPage = Math.max(page, 1); | ||
| int correctPageSize = Math.max(1, Math.min(pageSize, pageSizeLimit)); | ||
| PaymentSuccessHistoryPageDto paymentSuccessHistoryPageDto = paymentService.viewAllSuccessTransaction(userId, | ||
|
|
@@ -115,24 +109,16 @@ public ResponseEntity<PagedResponse<PaymentSuccessPageWrapperDto>> readAll(HttpS | |
|
|
||
| @GetMapping("/view/cancel") | ||
| @Operation(summary = "취소 결제 조회", description = "취소된 결제 내역 조회") | ||
| public ResponseEntity<PagedResponse<PaymentFailurePageWrapperDto>> readAllFailure(HttpSession session, | ||
| public ResponseEntity<PagedResponse<PaymentCancelPageWrapperDto>> readAllFailure(HttpSession session, | ||
| @RequestParam("page") int page, | ||
| @RequestParam("pageSize") int pageSize) { | ||
| Long userId = (Long)session.getAttribute("LOGIN_USER"); | ||
| @RequestParam("pageSize") int pageSize, | ||
| @LoginUser Long userId) { | ||
| int correctPage = Math.max(page, 1); | ||
| int correctPageSize = Math.max(1, Math.min(pageSize, pageSizeLimit)); | ||
| PaymentFailureHistoryPageDto paymentFailureHistoryPageDto = paymentService.viewAllFailureTransaction(userId, | ||
| PaymentCancelHistoryPageDto paymentCancelHistoryPageDto = paymentService.viewAllFailureTransaction(userId, | ||
| correctPage, correctPageSize); | ||
| PaymentFailurePageWrapperDto payments = PaymentMapper.toPaymentFailurePageWrapperDto( | ||
| paymentFailureHistoryPageDto); | ||
| return PagedResponse.ok("취소 결제 조회 성공", payments, paymentFailureHistoryPageDto.count(), HttpStatus.OK); | ||
| PaymentCancelPageWrapperDto payments = PaymentMapper.toPaymentFailurePageWrapperDto( | ||
| paymentCancelHistoryPageDto); | ||
| return PagedResponse.ok("취소 결제 조회 성공", payments, paymentCancelHistoryPageDto.count(), HttpStatus.OK); | ||
| } | ||
|
|
||
| @GetMapping("/{paymentKey}") | ||
| @Operation(summary = "상세 결제 조회", description = "상세 결제 내역 조회") | ||
| public ResponseEntity<BaseResponse<TossPaymentResponseDto>> readDetailPayment( | ||
| @PathVariable("paymentKey") String paymentKey) { | ||
| return BaseResponse.ok("상세 결제 조회 완료", tossPaymentClient.viewDetailPayment(paymentKey), HttpStatus.OK); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/threestar/trainus/domain/payment/dto/cancel/CancelDetail.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.threestar.trainus.domain.payment.dto.cancel; | ||
|
|
||
| public record CancelDetail( | ||
| String cancelReason, | ||
| String canceledAt, | ||
| int cancelAmount, | ||
| int refundableAmount | ||
| ) { | ||
| } |
4 changes: 2 additions & 2 deletions
4
.../payment/dto/CancelPaymentRequestDto.java → ...t/dto/cancel/CancelPaymentRequestDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...to/failure/FailurePaymentResponseDto.java → .../dto/cancel/CancelPaymentResponseDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| package com.threestar.trainus.domain.payment.dto.failure; | ||
| package com.threestar.trainus.domain.payment.dto.cancel; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record FailurePaymentResponseDto( | ||
| public record CancelPaymentResponseDto( | ||
| String lessonName, | ||
| String cancelReason, | ||
| LocalDateTime startAt, | ||
| LocalDateTime endAt, | ||
| LocalDateTime paymentCancelledAt, | ||
| int payPrice | ||
| int payPrice, | ||
| int refundableAmount | ||
| ) { | ||
| } |
12 changes: 12 additions & 0 deletions
12
...ain/java/com/threestar/trainus/domain/payment/dto/cancel/PaymentCancelHistoryPageDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.threestar.trainus.domain.payment.dto.cancel; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record PaymentCancelHistoryPageDto( | ||
| Integer count, | ||
| List<PaymentCancelHistoryResponseDto> failureHistory | ||
| ) { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용되는 부분을 추후에 공통 로직으로 빼야할지 고민해봐야겠군요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 추후에 리팩토링 진행해봐도 좋을 것 같습니다!