From 861d04cb4089a6083dab2a09b6998c75da094b98 Mon Sep 17 00:00:00 2001 From: yang Date: Sat, 2 Mar 2024 16:33:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?RAC-304=20fix=20:=20=EA=B2=B0=EC=A0=9C=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=EC=8B=9C=20=ED=99=98=EB=B6=88=20=EC=A7=84?= =?UTF-8?q?=ED=96=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/mapper/PaymentMapper.java | 13 +++++++++ .../usecase/PaymentManageUseCase.java | 29 ++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/payment/application/mapper/PaymentMapper.java b/src/main/java/com/postgraduate/domain/payment/application/mapper/PaymentMapper.java index f7c5773a..0596edf2 100644 --- a/src/main/java/com/postgraduate/domain/payment/application/mapper/PaymentMapper.java +++ b/src/main/java/com/postgraduate/domain/payment/application/mapper/PaymentMapper.java @@ -25,4 +25,17 @@ public static Payment resultToPayment(Salary salary, User user, PaymentResultReq .paidAt(LocalDateTime.parse(request.PCD_PAY_TIME(), formatter)) .build(); } + + public static Payment resultToPayment(PaymentResultRequest request) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + return Payment.builder() + .salary(null) + .user(null) + .pay(Integer.parseInt(request.PCD_PAY_TOTAL())) + .orderId(request.PCD_PAY_OID()) + .cardAuthNumber(request.PCD_PAY_CARDAUTHNO()) + .cardReceipt(request.PCD_PAY_CARDRECEIPT()) + .paidAt(LocalDateTime.parse(request.PCD_PAY_TIME(), formatter)) + .build(); + } } 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 d0b6e804..3605294a 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 @@ -62,9 +62,9 @@ public class PaymentManageUseCase { private final WebClient webClient; public void savePay(PaymentResultRequest request) { + if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) + throw new PaymentFailException(); try { - if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) - throw new PaymentFailException(); String seniorNickName = request.PCD_PAY_GOODS(); long userId = Long.parseLong(request.PCD_PAYER_NO()); User user = userGetService.byUserId(userId); @@ -73,7 +73,10 @@ public void savePay(PaymentResultRequest request) { Payment payment = PaymentMapper.resultToPayment(salary, user, request); paymentSaveService.save(payment); } catch (Exception ex) { - log.error("paymentError 발생 {}", ex.getMessage()); + log.error("paymentError 발생 환불 진행 | errorMessage : {}", ex.getMessage()); + Payment payment = PaymentMapper.resultToPayment(request); + paymentSaveService.save(payment); + refundPay(payment); } } @@ -124,16 +127,16 @@ private void refundProcess(CertificationResponse response, Payment payment) { } Map requestBody = getRefundRequestBody(response, payment); RefundResponse refundResponse = Optional.ofNullable(webClient.post() - .uri(refundUri + response.PCD_PAY_URL()) - .headers(h -> { - h.setContentType(MediaType.APPLICATION_JSON); - h.setCacheControl(noCache()); - h.set(REFERER.getName(), refererUri); - }) - .bodyValue(requestBody) - .retrieve() - .bodyToMono(RefundResponse.class) - .block()) + .uri(refundUri + response.PCD_PAY_URL()) + .headers(h -> { + h.setContentType(MediaType.APPLICATION_JSON); + h.setCacheControl(noCache()); + h.set(REFERER.getName(), refererUri); + }) + .bodyValue(requestBody) + .retrieve() + .bodyToMono(RefundResponse.class) + .block()) .orElseThrow(() -> new RefundFailException("NPE")); if (!refundResponse.PCD_PAY_RST().equals(SUCCESS.getName())) throw new RefundFailException(refundResponse.PCD_PAY_CODE()); From 7e544c3d615cee71a29e33558b469242869d9687 Mon Sep 17 00:00:00 2001 From: yang Date: Sat, 2 Mar 2024 16:36:26 +0900 Subject: [PATCH 2/2] =?UTF-8?q?RAC-304=20fix=20:=20=EA=B2=B0=EC=A0=9C=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=EC=8B=9C=20=ED=99=98=EB=B6=88=20=EC=A7=84?= =?UTF-8?q?=ED=96=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/application/usecase/PaymentManageUseCase.java | 2 +- .../domain/salary/domain/service/SalaryGetService.java | 5 ----- 2 files changed, 1 insertion(+), 6 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 3605294a..ac742d45 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 @@ -69,7 +69,7 @@ public void savePay(PaymentResultRequest request) { long userId = Long.parseLong(request.PCD_PAYER_NO()); User user = userGetService.byUserId(userId); Senior senior = seniorGetService.bySeniorNickName(seniorNickName); - Salary salary = salaryGetService.bySeniorWithNull(senior); + Salary salary = salaryGetService.bySenior(senior); Payment payment = PaymentMapper.resultToPayment(salary, user, request); paymentSaveService.save(payment); } catch (Exception ex) { diff --git a/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java b/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java index 90a0f509..9eea5e32 100644 --- a/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java +++ b/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java @@ -27,11 +27,6 @@ public Salary bySenior(Senior senior) { return salaryRepository.findBySeniorAndSalaryDate(senior, salaryDate).orElseThrow(SalaryNotFoundException::new); } - public Salary bySeniorWithNull(Senior senior) { - LocalDate salaryDate = SalaryUtil.getSalaryDate(); - return salaryRepository.findBySeniorAndSalaryDate(senior, salaryDate).orElse(null); - } - public Page findDistinctSeniors(String search, Integer page) { page = page == null ? 1 : page; Pageable pageable = PageRequest.of(page - 1, ADMIN_PAGE_SIZE);