From bd3c656e700bb49fb50698aceb704cc7c4fcff6b Mon Sep 17 00:00:00 2001 From: CHAN <150508884+zerochani@users.noreply.github.com> Date: Sat, 31 Jan 2026 16:00:45 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[REFACTOR]:=20PaymentService=20=EC=99=B8?= =?UTF-8?q?=EB=B6=80=20API=20=ED=98=B8=EC=B6=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/service/PaymentService.java | 40 ++++------------- .../payment/service/TossPaymentService.java | 45 +++++++++++++++++++ 2 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java diff --git a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/PaymentService.java b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/PaymentService.java index 44d38aa..b16192a 100644 --- a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/PaymentService.java +++ b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/PaymentService.java @@ -22,7 +22,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.RestClient; import java.math.BigDecimal; import org.springframework.data.domain.PageRequest; @@ -38,7 +37,7 @@ public class PaymentService { private final PaymentRepository paymentRepository; private final BookingRepository bookingRepository; - private final RestClient tossPaymentClient; + private final TossPaymentService tossPaymentService; @Transactional public PaymentResponseDTO.PaymentRequestResultDTO requestPayment(PaymentRequestDTO.RequestPaymentDTO dto) { @@ -82,21 +81,10 @@ public PaymentResponseDTO.PaymentSuccessResultDTO confirmPayment(PaymentConfirmD throw new PaymentException(PaymentErrorStatus._PAYMENT_INVALID_AMOUNT); } // 토스 API 호출 - TossPaymentResponse response; - try { - response = tossPaymentClient.post() - .uri("/v1/payments/confirm") - .body(dto) - .retrieve() - .body(TossPaymentResponse.class); - - if (response == null || !"DONE".equals(response.status())) { - log.error("Toss Payment Confirmation Failed: Status is not DONE"); - payment.failPayment(); - throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR); - } - } catch (Exception e) { - log.error("Toss Payment API Error", e); + TossPaymentResponse response = tossPaymentService.confirm(dto); + + if (response == null || !"DONE".equals(response.status())) { + log.error("Toss Payment Confirmation Failed: Status is not DONE"); payment.failPayment(); throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR); } @@ -140,20 +128,10 @@ public PaymentResponseDTO.CancelPaymentResultDTO cancelPayment(String paymentKey .orElseThrow(() -> new PaymentException(PaymentErrorStatus._PAYMENT_NOT_FOUND)); // 토스 결제 취소 API 호출 - TossPaymentResponse response; - try { - response = tossPaymentClient.post() - .uri("/v1/payments/" + paymentKey + "/cancel") - .body(dto) - .retrieve() - .body(TossPaymentResponse.class); - - if (response == null || !"CANCELED".equals(response.status())) { - log.error("Toss Payment Cancel Failed: {}", response); - throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR); - } - } catch (Exception e) { - log.error("Toss Payment Cancel API Error", e); + TossPaymentResponse response = tossPaymentService.cancel(paymentKey, dto); + + if (response == null || !"CANCELED".equals(response.status())) { + log.error("Toss Payment Cancel Failed: {}", response); throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR); } diff --git a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java new file mode 100644 index 0000000..333a284 --- /dev/null +++ b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java @@ -0,0 +1,45 @@ +package com.eatsfine.eatsfine.domain.payment.service; + +import com.eatsfine.eatsfine.domain.payment.dto.request.PaymentConfirmDTO; +import com.eatsfine.eatsfine.domain.payment.dto.request.PaymentRequestDTO; +import com.eatsfine.eatsfine.domain.payment.dto.response.TossPaymentResponse; +import com.eatsfine.eatsfine.global.apiPayload.code.status.ErrorStatus; +import com.eatsfine.eatsfine.global.apiPayload.exception.GeneralException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; + +@Slf4j +@Service +@RequiredArgsConstructor +public class TossPaymentService { + + private final RestClient tossPaymentClient; + + public TossPaymentResponse confirm(PaymentConfirmDTO dto) { + try { + return tossPaymentClient.post() + .uri("/v1/payments/confirm") + .body(dto) + .retrieve() + .body(TossPaymentResponse.class); + } catch (Exception e) { + log.error("Toss Payment API Error", e); + throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR); + } + } + + public TossPaymentResponse cancel(String paymentKey, PaymentRequestDTO.CancelPaymentDTO dto) { + try { + return tossPaymentClient.post() + .uri("/v1/payments/" + paymentKey + "/cancel") + .body(dto) + .retrieve() + .body(TossPaymentResponse.class); + } catch (Exception e) { + log.error("Toss Payment Cancel API Error", e); + throw new GeneralException(ErrorStatus._INTERNAL_SERVER_ERROR); + } + } +} From 5945b0d894644bfb7f524452728844057bb1a53b Mon Sep 17 00:00:00 2001 From: CHAN <150508884+zerochani@users.noreply.github.com> Date: Sat, 31 Jan 2026 16:50:13 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[FIX]:=20=EA=B2=B0=EC=A0=9C=20=EC=8A=B9?= =?UTF-8?q?=EC=9D=B8=20API=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D=20?= =?UTF-8?q?=EC=8B=9C=20=EA=B2=B0=EC=A0=9C=20=EC=8B=A4=ED=8C=A8=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=AF=B8=EB=B0=98=EC=98=81=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatsfine/domain/payment/service/PaymentService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/PaymentService.java b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/PaymentService.java index b16192a..6cec011 100644 --- a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/PaymentService.java +++ b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/PaymentService.java @@ -81,7 +81,13 @@ public PaymentResponseDTO.PaymentSuccessResultDTO confirmPayment(PaymentConfirmD throw new PaymentException(PaymentErrorStatus._PAYMENT_INVALID_AMOUNT); } // 토스 API 호출 - TossPaymentResponse response = tossPaymentService.confirm(dto); + TossPaymentResponse response; + try { + response = tossPaymentService.confirm(dto); + } catch (Exception e) { + payment.failPayment(); + throw e; + } if (response == null || !"DONE".equals(response.status())) { log.error("Toss Payment Confirmation Failed: Status is not DONE"); From 278f5e712861499747924461ea5c56d9e04d6ec5 Mon Sep 17 00:00:00 2001 From: CHAN <150508884+zerochani@users.noreply.github.com> Date: Sat, 31 Jan 2026 16:57:38 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[FIX]:=20TossPaymentService=20=EA=B2=B0?= =?UTF-8?q?=EC=A0=9C=20=EC=B7=A8=EC=86=8C=20=EC=9A=94=EC=B2=AD=20URI=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=A9=EC=8B=9D=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eatsfine/domain/payment/service/TossPaymentService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java index 333a284..e10a516 100644 --- a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java +++ b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java @@ -33,7 +33,7 @@ public TossPaymentResponse confirm(PaymentConfirmDTO dto) { public TossPaymentResponse cancel(String paymentKey, PaymentRequestDTO.CancelPaymentDTO dto) { try { return tossPaymentClient.post() - .uri("/v1/payments/" + paymentKey + "/cancel") + .uri("/v1/payments/{paymentKey}/cancel", paymentKey) .body(dto) .retrieve() .body(TossPaymentResponse.class); From fd48817e1e659e3880ae72d7d8b1b9ecc9381b55 Mon Sep 17 00:00:00 2001 From: CHAN <150508884+zerochani@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:05:53 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[FIX]:=20TossPaymentService=20RestClient=20?= =?UTF-8?q?=EC=A3=BC=EC=9E=85=20=EB=AA=A8=ED=98=B8=EC=84=B1=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/payment/service/TossPaymentService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java index e10a516..4a434f8 100644 --- a/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java +++ b/src/main/java/com/eatsfine/eatsfine/domain/payment/service/TossPaymentService.java @@ -5,18 +5,21 @@ import com.eatsfine.eatsfine.domain.payment.dto.response.TossPaymentResponse; import com.eatsfine.eatsfine.global.apiPayload.code.status.ErrorStatus; import com.eatsfine.eatsfine.global.apiPayload.exception.GeneralException; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; @Slf4j @Service -@RequiredArgsConstructor public class TossPaymentService { private final RestClient tossPaymentClient; + public TossPaymentService(@Qualifier("tossPaymentClient") RestClient tossPaymentClient) { + this.tossPaymentClient = tossPaymentClient; + } + public TossPaymentResponse confirm(PaymentConfirmDTO dto) { try { return tossPaymentClient.post()