From 4f699e7d32cdcf45c3c73672de3c8e358acd9ef2 Mon Sep 17 00:00:00 2001 From: binarywoo27 Date: Fri, 5 Jan 2024 15:43:39 +0900 Subject: [PATCH] =?UTF-8?q?:bug:=20OrderType=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=B0=8F=20Feign=20client=20=EC=9A=94=EC=B2=AD=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderClientController.java | 16 ++++++++++ .../java/kr/bb/payment/entity/OrderType.java | 16 ---------- .../java/kr/bb/payment/entity/Payment.java | 3 +- .../kr/bb/payment/kafka/KafkaConsumer.java | 1 - .../payment/repository/PaymentRepository.java | 4 +++ .../bb/payment/service/KakaopayService.java | 3 -- .../kr/bb/payment/service/PaymentService.java | 30 +++++++++++++++++-- .../payment/service/KakaopayApproveTest.java | 6 ++-- .../bb/payment/service/KakaopayReadyTest.java | 4 +-- .../payment/service/PaymentServiceTest.java | 27 +++++++++++++++++ 10 files changed, 82 insertions(+), 28 deletions(-) delete mode 100644 src/main/java/kr/bb/payment/entity/OrderType.java create mode 100644 src/test/java/kr/bb/payment/service/PaymentServiceTest.java diff --git a/src/main/java/kr/bb/payment/controller/clientcontroller/OrderClientController.java b/src/main/java/kr/bb/payment/controller/clientcontroller/OrderClientController.java index 568cb6e..2bf0051 100644 --- a/src/main/java/kr/bb/payment/controller/clientcontroller/OrderClientController.java +++ b/src/main/java/kr/bb/payment/controller/clientcontroller/OrderClientController.java @@ -3,13 +3,18 @@ import bloomingblooms.domain.payment.KakaopayApproveRequestDto; import bloomingblooms.domain.payment.KakaopayReadyRequestDto; import bloomingblooms.domain.payment.KakaopayReadyResponseDto; +import bloomingblooms.domain.payment.PaymentInfoDto; import bloomingblooms.response.CommonResponse; import java.time.LocalDateTime; +import java.util.List; import kr.bb.payment.service.KakaopayService; +import kr.bb.payment.service.PaymentService; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -18,6 +23,7 @@ public class OrderClientController { private final KakaopayService kakaopayService; + private final PaymentService paymentService; @PostMapping("/ready") public CommonResponse payReady( @@ -31,4 +37,14 @@ public CommonResponse payApprove( @RequestBody KakaopayApproveRequestDto approveRequestDto) { return CommonResponse.success(kakaopayService.kakaoPayApprove(approveRequestDto)); } + + @GetMapping("/paymentInfo") + CommonResponse> getPaymentInfo(@RequestParam List orderGroupIds){ + return CommonResponse.success(paymentService.getPaymentInfo(orderGroupIds)); + } + + @GetMapping(value = "/client/paymentDate") + CommonResponse getPaymentDate(@RequestParam String orderGroupId){ + return CommonResponse.success(paymentService.getPaymentDate(orderGroupId)); + } } diff --git a/src/main/java/kr/bb/payment/entity/OrderType.java b/src/main/java/kr/bb/payment/entity/OrderType.java deleted file mode 100644 index 89db908..0000000 --- a/src/main/java/kr/bb/payment/entity/OrderType.java +++ /dev/null @@ -1,16 +0,0 @@ -package kr.bb.payment.entity; - -import lombok.Getter; - -@Getter -public enum OrderType { - ORDER_DELIVERY("주문 배송"), - ORDER_PICKUP("주문 픽업"), - ORDER_SUBSCRIPTION("주문 구독"); - - private final String message; - - OrderType(String message) { - this.message = message; - } -} diff --git a/src/main/java/kr/bb/payment/entity/Payment.java b/src/main/java/kr/bb/payment/entity/Payment.java index 70fc99d..3763823 100644 --- a/src/main/java/kr/bb/payment/entity/Payment.java +++ b/src/main/java/kr/bb/payment/entity/Payment.java @@ -1,5 +1,6 @@ package kr.bb.payment.entity; +import bloomingblooms.domain.notification.order.OrderType; import bloomingblooms.domain.payment.KakaopayApproveRequestDto; import javax.persistence.Column; import javax.persistence.Entity; @@ -61,7 +62,7 @@ public class Payment extends BaseEntity { public static Payment toEntity(KakaopayApproveRequestDto requestDto, OrderType type) { return Payment.builder() - .userId(Long.valueOf(requestDto.getUserId())) + .userId(requestDto.getUserId()) .orderId(requestDto.getOrderId()) .orderType(type) .paymentCid(requestDto.getCid()) diff --git a/src/main/java/kr/bb/payment/kafka/KafkaConsumer.java b/src/main/java/kr/bb/payment/kafka/KafkaConsumer.java index d532abf..7490b12 100644 --- a/src/main/java/kr/bb/payment/kafka/KafkaConsumer.java +++ b/src/main/java/kr/bb/payment/kafka/KafkaConsumer.java @@ -11,7 +11,6 @@ @RequiredArgsConstructor public class KafkaConsumer { private final KakaopayService kakaopayService; - private ObjectMapper objectMapper; @KafkaListener(topics = "subscription-batch", groupId = "payment-subscription") public void subscriptionBatch(SubscriptionBatchDtoList subscriptionBatchDtoList) { diff --git a/src/main/java/kr/bb/payment/repository/PaymentRepository.java b/src/main/java/kr/bb/payment/repository/PaymentRepository.java index 032fde1..3fb4722 100644 --- a/src/main/java/kr/bb/payment/repository/PaymentRepository.java +++ b/src/main/java/kr/bb/payment/repository/PaymentRepository.java @@ -1,8 +1,12 @@ package kr.bb.payment.repository; +import java.util.List; import kr.bb.payment.entity.Payment; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface PaymentRepository extends JpaRepository { Payment findByOrderId(String orderId); + @Query("select p from Payment p where p.orderId = :orderIds") + List findAllByOrderIds(List orderIds); } diff --git a/src/main/java/kr/bb/payment/service/KakaopayService.java b/src/main/java/kr/bb/payment/service/KakaopayService.java index 3ca67fb..d9b4e4f 100644 --- a/src/main/java/kr/bb/payment/service/KakaopayService.java +++ b/src/main/java/kr/bb/payment/service/KakaopayService.java @@ -117,9 +117,6 @@ public void renewSubscription(SubscriptionBatchDtoList subscriptionBatchDtoList) List newDeliveryIdsList = deliveryServiceClient.createDeliveryForSubscription(oldDeliveryIdsList).getData(); paymentService.saveDeliveryIds(oldDeliveryIdsMap, newDeliveryIdsList); - // SQS 로 구매자에게 주문 발생 알림 - - } @NotNull diff --git a/src/main/java/kr/bb/payment/service/PaymentService.java b/src/main/java/kr/bb/payment/service/PaymentService.java index 1f84102..4a4bf6c 100644 --- a/src/main/java/kr/bb/payment/service/PaymentService.java +++ b/src/main/java/kr/bb/payment/service/PaymentService.java @@ -1,12 +1,14 @@ package kr.bb.payment.service; +import bloomingblooms.domain.notification.order.OrderType; import bloomingblooms.domain.payment.KakaopayApproveRequestDto; +import bloomingblooms.domain.payment.PaymentInfoDto; import java.time.LocalDateTime; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.persistence.EntityNotFoundException; import kr.bb.payment.dto.response.KakaopayApproveResponseDto; -import kr.bb.payment.entity.OrderType; import kr.bb.payment.entity.Payment; import kr.bb.payment.entity.Subscription; import kr.bb.payment.entity.SubscriptionRecords; @@ -31,7 +33,7 @@ public LocalDateTime saveSinglePaymentInfo( KakaopayApproveRequestDto requestDto, KakaopayApproveResponseDto responseDto) { // 정기 결제 저장 - if (OrderType.ORDER_SUBSCRIPTION.toString().equals(requestDto.getOrderType())) { + if (OrderType.SUBSCRIBE.toString().equals(requestDto.getOrderType())) { String phoneNumber = requestDto.getPhoneNumber(); Subscription subscription = SubscriptionMapper.toSubscriptionEntity(phoneNumber, responseDto); // 배송id도 함께 저장 @@ -78,4 +80,28 @@ public void saveDeliveryIds(Map oldDeliveryIdsMap, List newDel subscriptionRecords.setDeliveryId(value); } } + + @Transactional + public List getPaymentInfo(List orderGroupIds) { + List allPaymentsByOrderIds = paymentRepository.findAllByOrderIds(orderGroupIds); + return allPaymentsByOrderIds.stream() + .map( + payment -> { + return PaymentInfoDto.builder() + .orderGroupId(payment.getOrderId()) + .paymentActualAmount(payment.getPaymentActualAmount()) + .createdAt(payment.getCreatedAt()) + .build(); + }) + .collect(Collectors.toList()); + } + + @Transactional + public String getPaymentDate(String orderGroupId){ + Payment payment = paymentRepository.findByOrderId(orderGroupId); + if(payment != null){ + return payment.getCreatedAt().toString(); + } + return ""; + } } diff --git a/src/test/java/kr/bb/payment/service/KakaopayApproveTest.java b/src/test/java/kr/bb/payment/service/KakaopayApproveTest.java index cb64db3..d7d38a8 100644 --- a/src/test/java/kr/bb/payment/service/KakaopayApproveTest.java +++ b/src/test/java/kr/bb/payment/service/KakaopayApproveTest.java @@ -67,7 +67,7 @@ void shutDown() { @DirtiesContext @Test void kakaoPayApproveForDeliveryTest() { - KakaopayApproveRequestDto requestDto = creatApproveRequestDto("임시orderId1", "ORDER_DELIVERY"); + KakaopayApproveRequestDto requestDto = creatApproveRequestDto("임시orderId1", "DELIVERY"); kakaopayService.kakaoPayApprove(requestDto); mockServer.verify(); @@ -77,7 +77,7 @@ void kakaoPayApproveForDeliveryTest() { @DirtiesContext @Test void kakaoPayApproveForPickupTest() { - KakaopayApproveRequestDto requestDto = creatApproveRequestDto("임시orderId2", "ORDER_PICKUP"); + KakaopayApproveRequestDto requestDto = creatApproveRequestDto("임시orderId2", "PICKUP"); kakaopayService.kakaoPayApprove(requestDto); mockServer.verify(); @@ -106,7 +106,7 @@ KakaopayApproveRequestDto creatApproveRequestDto(String orderId, String orderTyp @Test void kakaoPayApproveForSubscriptionTest() { KakaopayApproveRequestDto requestDto = - creatApproveRequestDto("임시orderId2", "ORDER_SUBSCRIPTION"); + creatApproveRequestDto("임시orderId2", "SUBSCRIBE"); kakaopayService.kakaoPayApprove(requestDto); mockServer.verify(); diff --git a/src/test/java/kr/bb/payment/service/KakaopayReadyTest.java b/src/test/java/kr/bb/payment/service/KakaopayReadyTest.java index 0b95a07..1f319d5 100644 --- a/src/test/java/kr/bb/payment/service/KakaopayReadyTest.java +++ b/src/test/java/kr/bb/payment/service/KakaopayReadyTest.java @@ -24,7 +24,7 @@ void kakaopayReadyForDeliveryAndPickupTest() { KakaopayReadyRequestDto.builder() .userId("1") .orderId("1") - .orderType("ORDER_PICKUP") + .orderType("PICKUP") .itemName("계절마음") .quantity(1) .totalAmount(52900) @@ -47,7 +47,7 @@ void kakaopayReadyForSubscriptionTest() { KakaopayReadyRequestDto.builder() .userId("1") .orderId("2") - .orderType("ORDER_DELIVERY") + .orderType("SUBSCRIBE") .itemName("계절마음") .quantity(1) .totalAmount(52900) diff --git a/src/test/java/kr/bb/payment/service/PaymentServiceTest.java b/src/test/java/kr/bb/payment/service/PaymentServiceTest.java new file mode 100644 index 0000000..2f0f558 --- /dev/null +++ b/src/test/java/kr/bb/payment/service/PaymentServiceTest.java @@ -0,0 +1,27 @@ +package kr.bb.payment.service; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import bloomingblooms.domain.payment.PaymentInfoDto; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +@SpringBootTest +@Transactional +public class PaymentServiceTest { + @Autowired private PaymentService paymentService; + @Test + void getPaymentInfoTest(){ + List paymentInfo = paymentService.getPaymentInfo(List.of("임시주문번호")); + assertThat(paymentInfo.size()).isEqualTo(0); + } + + @Test + void getPaymentDateTest(){ + String paymentDate = paymentService.getPaymentDate("임시주문번호"); + assertThat(paymentDate).isEmpty(); + } +}