Skip to content

Fix: 결제 처리 에러 수정 - #119

Merged
jaebeom79 merged 1 commit into
mainfrom
develop
Jun 1, 2026
Merged

Fix: 결제 처리 에러 수정#119
jaebeom79 merged 1 commit into
mainfrom
develop

Conversation

@jaebeom79

Copy link
Copy Markdown
Contributor

📢 기능 설명

필요시 실행결과 스크린샷 첨부

연결된 issue

연결된 issue를 자동을 닫기 위해 아래 {이슈넘버}를 입력해주세요.

close #{이슈넘버}

✅ 체크리스트

  • PR 제목 규칙 잘 지켰는가?
  • 추가/수정사항을 설명하였는가?
  • 이슈넘버를 적었는가?

@jaebeom79
jaebeom79 merged commit 60f2d48 into main Jun 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new PAYMENT_ALREADY_PAID error code and adds logic to clean up existing payment records before creating a new payment in ReservationService. However, the review comments correctly identify a critical logic error: because createReservationCore always creates a new Reservation with a fresh ID, searching for an existing payment by saved.getId() will always return empty, making the new idempotency logic dead code. The reviewer recommends validating existing pending reservations for the user and time slot before creating a new reservation.

Comment on lines +130 to +136
paymentRepository.findByReservation_Id(saved.getId()).ifPresent(existing -> {
if (existing.getStatus() == PaymentStatus.PAID) {
throw new CustomException(ErrorCode.PAYMENT_ALREADY_PAID);
}
paymentRepository.delete(existing);
paymentRepository.flush();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

⚠️ 데드 코드(Dead Code) 및 로직 오류 안내\n\ncreateReservationCore 메서드는 항상 새로운 Reservation 엔티티를 생성하고 저장하므로, saved.getId()는 매번 새롭게 발급되는 고유한 ID입니다.\n\n따라서 새로 생성된 saved.getId()를 조건으로 paymentRepository.findByReservation_Id(saved.getId())를 조회하면 항상 결과가 비어있게 되므로(Optional.empty()), ifPresent 내부의 로직은 결코 실행되지 않습니다.\n\n#### 💡 권장 해결 방안\n결제 재시도 시나리오나 중복 예약을 방지하고자 한다면, 새로운 예약을 생성하기 전에 기존에 동일한 사용자(userId)와 예약 시간대(remainId)로 생성된 PENDING 상태의 예약이 존재하는지 먼저 조회해야 합니다.\n\n만약 존재한다면 해당 예약의 결제 정보를 재사용하거나 예외를 던지도록 수정하는 것이 올바른 멱등성(Idempotency) 보장 방식입니다.

Comment on lines +237 to +243
paymentRepository.findByReservation_Id(saved.getId()).ifPresent(existing -> {
if (existing.getStatus() == PaymentStatus.PAID) {
throw new CustomException(ErrorCode.PAYMENT_ALREADY_PAID);
}
paymentRepository.delete(existing);
paymentRepository.flush();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

⚠️ 데드 코드(Dead Code) 및 로직 오류 안내\n\n위의 createReservationFromAi 메서드와 마찬가지로, createReservationCore를 통해 매번 새로운 예약이 생성되므로 saved.getId()에 대응하는 기존 Payment 레코드는 존재할 수 없습니다. 따라서 이 블록은 항상 실행되지 않는 데드 코드가 됩니다.\n\n#### 💡 권장 해결 방안\n새로운 예약을 생성하기 전에 기존에 동일한 조건의 PENDING 예약이 있는지 검증하는 로직을 추가하거나, 결제 재시도 시에는 예약 생성 API(POST /api/v1/reservations)가 아닌 기존 예약 ID를 기반으로 결제창을 다시 호출하는 방식을 사용하도록 클라이언트와 API 설계를 조율해야 합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant