From 2396ead7e1a341d849ea11a335f440097b432473 Mon Sep 17 00:00:00 2001 From: yang Date: Sun, 10 Mar 2024 23:14:11 +0900 Subject: [PATCH] =?UTF-8?q?RAC-304=20fix=20:=20Payple=EA=B2=B0=EC=A0=9C=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=EC=8B=9C=20=EB=A6=AC=EB=8B=A4=EC=9D=B4?= =?UTF-8?q?=EB=A0=89=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/PaymentManageUseCase.java | 12 +++++++--- .../presentation/PaymentController.java | 22 +++++++++++++++---- .../usecase/SeniorInfoUseCase.java | 5 +++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java b/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java index ac742d45..91a5f8cc 100644 --- a/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java @@ -31,6 +31,8 @@ import java.util.Optional; import static com.postgraduate.domain.payment.application.usecase.PaymentParameter.*; +import static com.postgraduate.domain.payment.presentation.constant.PaymentResponseCode.PAYMENT_FAIL; +import static com.postgraduate.domain.payment.presentation.constant.PaymentResponseMessage.FAIL_PAYMENT; import static org.springframework.http.CacheControl.noCache; @Service @@ -61,9 +63,12 @@ public class PaymentManageUseCase { private final SalaryGetService salaryGetService; private final WebClient webClient; - public void savePay(PaymentResultRequest request) { - if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) - throw new PaymentFailException(); + public boolean savePay(PaymentResultRequest request) { + if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) { + log.error("PayPle 결제 진행 취소 및 오류"); + log.error("message : {} code : {}", FAIL_PAYMENT.getMessage(), request.PCD_PAY_CODE()); + return false; + } try { String seniorNickName = request.PCD_PAY_GOODS(); long userId = Long.parseLong(request.PCD_PAYER_NO()); @@ -78,6 +83,7 @@ public void savePay(PaymentResultRequest request) { paymentSaveService.save(payment); refundPay(payment); } + return true; } public void refundPayByUser(User user, String orderId) { diff --git a/src/main/java/com/postgraduate/domain/payment/presentation/PaymentController.java b/src/main/java/com/postgraduate/domain/payment/presentation/PaymentController.java index c6fa0bae..b60a6638 100644 --- a/src/main/java/com/postgraduate/domain/payment/presentation/PaymentController.java +++ b/src/main/java/com/postgraduate/domain/payment/presentation/PaymentController.java @@ -2,6 +2,7 @@ import com.postgraduate.domain.payment.application.dto.req.PaymentResultRequest; import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase; +import com.postgraduate.domain.senior.application.usecase.SeniorInfoUseCase; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; @@ -18,21 +19,34 @@ @Tag(name = "PAYMENT Controller", description = "") public class PaymentController { private final PaymentManageUseCase paymentManageUseCase; + private final SeniorInfoUseCase seniorInfoUseCase; @Value("${payple.redirect-uri}") private String redirectUri; @Value("${payple.redirect-uri-dev}") private String redirectUriDev; + @Value("${payple.cancel-redirect-uri}") + private String cancelRedirectUri; + @Value("${payple.cancel-redirect-uri-dev}") + private String cancelRedirectUriDev; @PostMapping("/payple/result") public void resultGet(HttpServletResponse response, @ModelAttribute PaymentResultRequest request) throws IOException { - paymentManageUseCase.savePay(request); - response.sendRedirect(redirectUri + request.PCD_PAY_OID()); + if (paymentManageUseCase.savePay(request)) { + response.sendRedirect(redirectUri + request.PCD_PAY_OID()); + return; + } + Long seniorId = seniorInfoUseCase.getSeniorId(request.PCD_PAY_GOODS()); + response.sendRedirect(cancelRedirectUri + seniorId); } @PostMapping("/payple/dev/result") public void resultGetWithDev(HttpServletResponse response, @ModelAttribute PaymentResultRequest request) throws IOException { - paymentManageUseCase.savePay(request); - response.sendRedirect(redirectUriDev + request.PCD_PAY_OID()); + if (paymentManageUseCase.savePay(request)) { + response.sendRedirect(redirectUriDev + request.PCD_PAY_OID()); + return; + } + Long seniorId = seniorInfoUseCase.getSeniorId(request.PCD_PAY_GOODS()); + response.sendRedirect(cancelRedirectUriDev + seniorId); } @PostMapping("/webhook") diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java index f4501c91..adfa9935 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java @@ -99,4 +99,9 @@ public AllSeniorIdResponse getAllSeniorId() { .toList(); return new AllSeniorIdResponse(seniorIds); } + + public Long getSeniorId(String nickName) { + Senior senior = seniorGetService.bySeniorNickName(nickName); + return senior.getSeniorId(); + } }