Skip to content

[Feat] Toss 취소 실패 시 DLQ 적재 및 스케줄링 기반 환불 재시도 구현#208

Merged
today-is-first merged 16 commits intomainfrom
feature/#203
May 23, 2025
Merged

[Feat] Toss 취소 실패 시 DLQ 적재 및 스케줄링 기반 환불 재시도 구현#208
today-is-first merged 16 commits intomainfrom
feature/#203

Conversation

@seolminkkang
Copy link
Collaborator

개요

Resolves: #203

PR 유형

어떤 변경 사항이 있나요?

  • 새로운 기능 추가
  • 버그 수정
  • CSS 등 사용자 UI 디자인 변경
  • 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
  • 코드 리팩토링
  • 주석 추가 및 수정
  • 문서 수정
  • 테스트 추가, 테스트 리팩토링
  • 빌드 부분 혹은 패키지 매니저 수정
  • 파일 혹은 폴더명 수정
  • 파일 혹은 폴더 삭제

작업 내용

🔁 DLQ 및 환불 재시도 흐름

  • CancelDLQServiceImpl
    • TossCancel 실패 시 DLQ(payment:cancel:queue)에 JSON 메시지 적재
  • CancelRetryServiceImpl
    • Redis로부터 실패 메시지 pop 후 TossCancel 재시도
    • 성공 시 → refund_receipt 저장
    • 실패 시 → retry 증가 후 재적재
    • 3회 실패 시 → cancel_fail_log 테이블 insert
  • ScheduledCancelRetryWorker
    • 5초마다 재시도 트리거 수행

✅ 응답 구조 변경

  • PaymentResultResponse
    • ROLLBACK_PENDING 응답 타입 추가
    • ROLLBACK_REFUNDED (자동 환불 완료), ROLLBACK_FAILED (3회 실패) 기존 유지
  • PaymentUsecase
    • TossCancel 실패 시 ROLLBACK_PENDING 반환

📦 관련 클래스 / 리팩토링

변경 사항 설명
CancelRetryPayload DLQ 메시지 구조 정의
RefundReason enum + DB 대응 메서드 (toDbValue, fromDbValue)
CancelFailLogDTO 3회 실패 시 DB insert용 DTO
PaymentDAO findIdByOrderId, insertCancelFailLog 메서드 추가
RefundReceiptServiceImpl 재시도 성공 시 환불 기록 저장

  • /api/payments/result/{orderId} GET API 구현 (DeferredResult 기반 롱폴링 응답)
  • 1초마다 결제 상태 확인 → 최대 3분 대기
  • PaymentResultResponse에 SYSTEM_ERROR 상태 추가
  • RefundReceiptDTO, CancelFailLogDTO → toTossConfirmResponse() 추가
  • PaymentStatusServiceImpl → 환불 성공/실패/미처리 분기 구현
  • PaymentDAO 및 Mapper 쿼리 구현 (payment 조인 포함)
  • 롱폴링 중 예외 및 타임아웃 발생 시 graceful fallback 처리

findRefundReceiptByOrderId(), findCancelFailLogByOrderId() 추가
@github-actions github-actions bot added this to the 챌린지 결제 기능 milestone May 23, 2025
@today-is-first today-is-first merged commit 414c662 into main May 23, 2025
1 check passed
@today-is-first today-is-first deleted the feature/#203 branch May 23, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

서버는 결제 취소가 실패한 건에 대한 정보를 처리 및 저장할 수 있다.

2 participants