-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 환불 멱등성 키 + 중복 환불 방지 #341
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
Changes from all commits
c7f824d
fd2ae35
bf55562
6f1d5b7
67e5efd
6964c9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| package com.samhap.kokomen.payment.domain; | ||
|
|
||
| public enum TosspaymentsStatus { | ||
| READY, | ||
| IN_PROGRESS, | ||
| WAITING_FOR_DEPOSIT, | ||
| DONE, | ||
| CANCELED, | ||
| PARTIAL_CANCELED, | ||
| ABORTED, | ||
| EXPIRED | ||
| READY, // 결제 준비 | ||
| IN_PROGRESS, // 결제 진행 중 | ||
| DONE, // 승인 성공 | ||
| CANCELED, // 결제 취소 | ||
| PARTIAL_CANCELED, // 결제 부분 취소 | ||
| ABORTED, // 승인 실패 | ||
| EXPIRED // 유효 시간 만료 | ||
|
Comment on lines
+4
to
+10
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. 🧩 Analysis chain🌐 Web query:
💡 Result: In the Toss Payments Core API Payment object, the
Sources
Citations: 🏁 Script executed: # 파일 위치 확인 및 TosspaymentsStatus enum 전체 내용 조회
find . -name "TosspaymentsStatus.java" -type fRepository: samhap-soft/kokomen-backend Length of output: 144 🏁 Script executed: # TosspaymentsStatus enum의 전체 코드와 enum 상수 확인
cat -n "src/main/java/com/samhap/kokomen/payment/domain/TosspaymentsStatus.java"Repository: samhap-soft/kokomen-backend Length of output: 396 🏁 Script executed: # TosspaymentsStatus enum이 사용되는 모든 위치 찾기 (역직렬화, 매핑 등)
rg "TosspaymentsStatus" --type java -B 2 -A 2Repository: samhap-soft/kokomen-backend Length of output: 24524 🏁 Script executed: # Toss Payments 관련 설정, API 모델, 응답 처리 확인
fd -t f -e java . -path "*toss*" -o -path "*payment*" | head -20Repository: samhap-soft/kokomen-backend Length of output: 239 가상계좌 결제 시 Toss Payments API는 공식 문서에 🔧 수정 방안 public enum TosspaymentsStatus {
READY, // 결제 준비
IN_PROGRESS, // 결제 진행 중
+ WAITING_FOR_DEPOSIT, // 입금 대기 (가상계좌 등)
DONE, // 승인 성공
CANCELED, // 결제 취소
PARTIAL_CANCELED, // 결제 부분 취소
ABORTED, // 승인 실패
EXPIRED // 유효 시간 만료
}🤖 Prompt for AI Agents
Contributor
Author
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. 저희 서비스는 가상계좌 결제 기능을 제공하지 않기로 결정했습니다. 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.
✏️ Learnings added
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.samhap.kokomen.payment.service; | ||
|
|
||
| import com.samhap.kokomen.global.annotation.DistributedLock; | ||
| import com.samhap.kokomen.global.exception.BadRequestException; | ||
| import com.samhap.kokomen.global.exception.InternalServerErrorException; | ||
| import com.samhap.kokomen.global.exception.KokomenException; | ||
|
|
@@ -15,8 +16,8 @@ | |
| import com.samhap.kokomen.payment.service.dto.CancelRequest; | ||
| import com.samhap.kokomen.payment.service.dto.ConfirmRequest; | ||
| import com.samhap.kokomen.payment.service.dto.PaymentResponse; | ||
| import com.samhap.kokomen.global.annotation.DistributedLock; | ||
| import java.net.SocketTimeoutException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
@@ -54,7 +55,8 @@ public PaymentResponse confirmPayment(ConfirmRequest request) { | |
|
|
||
| private TosspaymentsPaymentResponse confirmPayment(ConfirmRequest request, | ||
| TosspaymentsPayment tosspaymentsPayment) { | ||
| String idempotencyKey = UUID.randomUUID().toString(); | ||
| String idempotencyKey = UUID.nameUUIDFromBytes( | ||
| ("confirm:" + request.paymentKey()).getBytes(StandardCharsets.UTF_8)).toString(); | ||
| try { | ||
| TosspaymentsPaymentResponse tosspaymentsConfirmResponse = tosspaymentsConfirmRetryTemplate.execute( | ||
| context -> { | ||
|
|
@@ -139,12 +141,22 @@ private void handleConfirmNetworkError(ResourceAccessException e, TosspaymentsPa | |
| tosspaymentsPaymentService.updateState(tosspaymentsPayment.getId(), PaymentState.NEED_CANCEL); | ||
| } | ||
|
|
||
| @DistributedLock(prefix = "payment", key = "#request.paymentKey()") | ||
| public void cancelPayment(CancelRequest request) { | ||
| TosspaymentsPaymentCancelRequest tosspaymentsPaymentCancelRequest = new TosspaymentsPaymentCancelRequest( | ||
| request.cancelReason()); | ||
| String idempotencyKey = UUID.nameUUIDFromBytes( | ||
| ("cancel:" + request.paymentKey()).getBytes(StandardCharsets.UTF_8)).toString(); | ||
| try { | ||
| TosspaymentsPaymentResponse response = tosspaymentsClient.cancelPayment(request.paymentKey(), | ||
| tosspaymentsPaymentCancelRequest); | ||
| TosspaymentsPaymentResponse response = tosspaymentsConfirmRetryTemplate.execute( | ||
| context -> { | ||
| if (context.getRetryCount() > 0) { | ||
| log.warn("토스페이먼츠 환불 승인 재시도 {}회차, paymentKey = {}", | ||
| context.getRetryCount(), request.paymentKey()); | ||
| } | ||
| return tosspaymentsClient.cancelPayment(request.paymentKey(), | ||
| tosspaymentsPaymentCancelRequest, idempotencyKey); | ||
| }); | ||
|
Comment on lines
+151
to
+159
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. 🧹 Nitpick | 🔵 Trivial RetryTemplate 재사용은 적절하나, 네이밍 불일치에 주의하세요.
🤖 Prompt for AI Agents |
||
| tosspaymentsTransactionService.applyCancelResult(response); | ||
| } catch (HttpClientErrorException e) { | ||
| Failure failure = e.getResponseBodyAs(Failure.class); | ||
|
|
||
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.
WAITING_FOR_DEPOSIT 상태가 제거되었습니다. 이 상태가 더 이상 사용되지 않거나 다른 방식으로 처리되는지 확인이 필요합니다. 만약 이 상태를 사용하는 기존 로직이 있다면, 예기치 않은 동작이나 데이터 불일치가 발생할 수 있습니다. 제거된 이유와 시스템 전반에 미치는 영향에 대한 설명이 추가되면 좋을 것 같습니다.