From 77e6f861c4523a8b43deb2be328c98725a7daf40 Mon Sep 17 00:00:00 2001 From: binarywoo27 Date: Fri, 29 Dec 2023 20:34:57 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:memo:=20Url=20=EB=B3=80=EC=88=98=EB=AA=85?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../java/kr/bb/payment/service/KakaopayService.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 8dedede..9c83f81 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' implementation "org.springframework.cloud:spring-cloud-starter-bus-kafka" implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'io.github.lotteon-maven:blooming-blooms-utils:202312260649' + implementation 'io.github.lotteon-maven:blooming-blooms-utils:202312290714' runtimeOnly 'com.h2database:h2' implementation 'mysql:mysql-connector-java:8.0.33' testImplementation 'org.mock-server:mockserver-netty:5.11.2' // 사용 중인 MockServer 버전 diff --git a/src/main/java/kr/bb/payment/service/KakaopayService.java b/src/main/java/kr/bb/payment/service/KakaopayService.java index 4f478da..859a79b 100644 --- a/src/main/java/kr/bb/payment/service/KakaopayService.java +++ b/src/main/java/kr/bb/payment/service/KakaopayService.java @@ -24,8 +24,8 @@ public class KakaopayService { @Value("${kakao.admin}") private String ADMIN_KEY; - @Value("${endpoint.apigateway-service}") - private String APIGATEWAY_SERVICE_URL; + @Value("${endpoint.front-url}") + private String FRONT_URL; public KakaopayReadyResponseDto kakaoPayReady(KakaopayReadyRequestDto requestDto) { String cid = requestDto.isSubscriptionPay() ? "TCSUBSCRIP" : "TC0ONETIME"; @@ -42,13 +42,13 @@ public KakaopayReadyResponseDto kakaoPayReady(KakaopayReadyRequestDto requestDto parameters.add( "approval_url", - APIGATEWAY_SERVICE_URL + FRONT_URL + "/api/orders/approve/" + requestDto.getOrderId() + "/" + requestDto.getOrderType()); - parameters.add("cancel_url", APIGATEWAY_SERVICE_URL + "/api/orders/cancel"); - parameters.add("fail_url", APIGATEWAY_SERVICE_URL + "/api/orders/fail"); + parameters.add("cancel_url", FRONT_URL + "/api/orders/cancel"); + parameters.add("fail_url", FRONT_URL + "/api/orders/fail"); HttpEntity> requestEntity = new HttpEntity<>(parameters, this.getHeaders()); From 4b9db930f0a53d23b11fc070bab9d70924e7c471 Mon Sep 17 00:00:00 2001 From: binarywoo27 Date: Fri, 29 Dec 2023 22:59:30 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:sparkles:=20=EC=A0=95=EA=B8=B0=EA=B2=B0?= =?UTF-8?q?=EC=A0=9C=20API=20=EB=B0=8F=20Test=20Code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../OrderClientController.java | 7 ++-- .../request/KakaopayApproveRequestDto.java | 2 + .../dto/request/KakaopayReadyRequestDto.java | 22 ---------- .../response/KakaoPayApproveResponseDto.java | 7 ++-- .../response/KakaopayApproveResponseDto.java | 38 +++++++++++++++++ .../response/KakaopayReadyResponseDto.java | 18 -------- .../java/kr/bb/payment/entity/OrderType.java | 3 +- .../java/kr/bb/payment/entity/Payment.java | 2 +- .../kr/bb/payment/entity/Subscription.java | 21 +++++++--- .../payment/entity/SubscriptionRecords.java | 12 ++++-- .../bb/payment/mapper/SubscriptionMapper.java | 29 +++++++++++++ .../SubscriptionRecordsRepository.java | 6 +++ .../repository/SubscriptionRepository.java | 6 +++ .../bb/payment/service/KakaopayService.java | 12 +++--- .../kr/bb/payment/service/PaymentService.java | 42 +++++++++++-------- .../payment/service/KakaopayApproveTest.java | 29 ++++++++++--- .../bb/payment/service/KakaopayReadyTest.java | 4 +- 18 files changed, 173 insertions(+), 88 deletions(-) delete mode 100644 src/main/java/kr/bb/payment/dto/request/KakaopayReadyRequestDto.java create mode 100644 src/main/java/kr/bb/payment/dto/response/KakaopayApproveResponseDto.java delete mode 100644 src/main/java/kr/bb/payment/dto/response/KakaopayReadyResponseDto.java create mode 100644 src/main/java/kr/bb/payment/mapper/SubscriptionMapper.java create mode 100644 src/main/java/kr/bb/payment/repository/SubscriptionRecordsRepository.java create mode 100644 src/main/java/kr/bb/payment/repository/SubscriptionRepository.java diff --git a/build.gradle b/build.gradle index 9c83f81..73f3662 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,7 @@ dependencies { implementation 'mysql:mysql-connector-java:8.0.33' testImplementation 'org.mock-server:mockserver-netty:5.11.2' // 사용 중인 MockServer 버전 implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.1' } dependencyManagement { 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 c0104f7..568cb6e 100644 --- a/src/main/java/kr/bb/payment/controller/clientcontroller/OrderClientController.java +++ b/src/main/java/kr/bb/payment/controller/clientcontroller/OrderClientController.java @@ -1,10 +1,10 @@ package kr.bb.payment.controller.clientcontroller; +import bloomingblooms.domain.payment.KakaopayApproveRequestDto; +import bloomingblooms.domain.payment.KakaopayReadyRequestDto; +import bloomingblooms.domain.payment.KakaopayReadyResponseDto; import bloomingblooms.response.CommonResponse; import java.time.LocalDateTime; -import kr.bb.payment.dto.request.KakaopayApproveRequestDto; -import kr.bb.payment.dto.request.KakaopayReadyRequestDto; -import kr.bb.payment.dto.response.KakaopayReadyResponseDto; import kr.bb.payment.service.KakaopayService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; @@ -29,7 +29,6 @@ public CommonResponse payReady( @PostMapping("/approve") public CommonResponse payApprove( @RequestBody KakaopayApproveRequestDto approveRequestDto) { - return CommonResponse.success(kakaopayService.kakaoPayApprove(approveRequestDto)); } } diff --git a/src/main/java/kr/bb/payment/dto/request/KakaopayApproveRequestDto.java b/src/main/java/kr/bb/payment/dto/request/KakaopayApproveRequestDto.java index e42ed1b..ed26890 100644 --- a/src/main/java/kr/bb/payment/dto/request/KakaopayApproveRequestDto.java +++ b/src/main/java/kr/bb/payment/dto/request/KakaopayApproveRequestDto.java @@ -1,5 +1,6 @@ package kr.bb.payment.dto.request; +import javax.annotation.Nullable; import javax.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -23,4 +24,5 @@ public class KakaopayApproveRequestDto { @NotNull private String cid; @NotNull private String tid; @NotNull private String pgToken; + @Nullable private Long deliveryId; } diff --git a/src/main/java/kr/bb/payment/dto/request/KakaopayReadyRequestDto.java b/src/main/java/kr/bb/payment/dto/request/KakaopayReadyRequestDto.java deleted file mode 100644 index 719c9a3..0000000 --- a/src/main/java/kr/bb/payment/dto/request/KakaopayReadyRequestDto.java +++ /dev/null @@ -1,22 +0,0 @@ -package kr.bb.payment.dto.request; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Builder -@AllArgsConstructor(access = AccessLevel.PROTECTED) -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class KakaopayReadyRequestDto { - private String userId; - private String orderId; - private String orderType; - private String itemName; - private int quantity; - private int totalAmount; - private int taxFreeAMount; - private boolean isSubscriptionPay; -} diff --git a/src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.java b/src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.java index 12ef7cb..e9feb64 100644 --- a/src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.java +++ b/src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.java @@ -1,6 +1,7 @@ package kr.bb.payment.dto.response; import com.fasterxml.jackson.annotation.JsonProperty; +import java.time.LocalDateTime; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -15,7 +16,7 @@ @Builder @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class KakaoPayApproveResponseDto { +public class KakaopayApproveResponseDto { private String aid; // 요청 고유번호 private String tid; // 결제 고유번호 private String cid; // 가맹점 코드 @@ -30,8 +31,8 @@ public class KakaoPayApproveResponseDto { private String itemName; private Integer quantity; @JsonProperty("created_at") - private String createdAt; + private LocalDateTime createdAt; @JsonProperty("approved_at") - private String approvedAt; + private LocalDateTime approvedAt; private Amount amount; } diff --git a/src/main/java/kr/bb/payment/dto/response/KakaopayApproveResponseDto.java b/src/main/java/kr/bb/payment/dto/response/KakaopayApproveResponseDto.java new file mode 100644 index 0000000..e9feb64 --- /dev/null +++ b/src/main/java/kr/bb/payment/dto/response/KakaopayApproveResponseDto.java @@ -0,0 +1,38 @@ +package kr.bb.payment.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.time.LocalDateTime; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class KakaopayApproveResponseDto { + private String aid; // 요청 고유번호 + private String tid; // 결제 고유번호 + private String cid; // 가맹점 코드 + private String sid; // 정기 결제용 id + @JsonProperty("partner_order_id") + private String partnerOrderId; // 가맹점 주문번호 + @JsonProperty("partner_user_id") + private String partnerUserId; // 가맹점 회원 + @JsonProperty("payment_method_type") + private String paymentMethodType; // 결제수단 + @JsonProperty("item_name") + private String itemName; + private Integer quantity; + @JsonProperty("created_at") + private LocalDateTime createdAt; + @JsonProperty("approved_at") + private LocalDateTime approvedAt; + private Amount amount; +} diff --git a/src/main/java/kr/bb/payment/dto/response/KakaopayReadyResponseDto.java b/src/main/java/kr/bb/payment/dto/response/KakaopayReadyResponseDto.java deleted file mode 100644 index cce7f3d..0000000 --- a/src/main/java/kr/bb/payment/dto/response/KakaopayReadyResponseDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package kr.bb.payment.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Builder -@Getter -@AllArgsConstructor(access = AccessLevel.PROTECTED) -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class KakaopayReadyResponseDto { - private String tid; - @JsonProperty("next_redirect_pc_url") - private String nextRedirectPcUrl; -} diff --git a/src/main/java/kr/bb/payment/entity/OrderType.java b/src/main/java/kr/bb/payment/entity/OrderType.java index ecd2ee7..89db908 100644 --- a/src/main/java/kr/bb/payment/entity/OrderType.java +++ b/src/main/java/kr/bb/payment/entity/OrderType.java @@ -5,7 +5,8 @@ @Getter public enum OrderType { ORDER_DELIVERY("주문 배송"), - ORDER_PICKUP("주문 픽업"); + ORDER_PICKUP("주문 픽업"), + ORDER_SUBSCRIPTION("주문 구독"); private final String message; diff --git a/src/main/java/kr/bb/payment/entity/Payment.java b/src/main/java/kr/bb/payment/entity/Payment.java index 0f856ed..70fc99d 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.payment.KakaopayApproveRequestDto; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -8,7 +9,6 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; -import kr.bb.payment.dto.request.KakaopayApproveRequestDto; import kr.bb.payment.entity.common.BaseEntity; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/kr/bb/payment/entity/Subscription.java b/src/main/java/kr/bb/payment/entity/Subscription.java index 727fe55..29f1b76 100644 --- a/src/main/java/kr/bb/payment/entity/Subscription.java +++ b/src/main/java/kr/bb/payment/entity/Subscription.java @@ -1,18 +1,25 @@ package kr.bb.payment.entity; import java.time.LocalDate; -import java.util.Date; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.OneToMany; import javax.persistence.Table; import kr.bb.payment.entity.common.BaseEntity; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; - +@Getter +@Builder @Entity @Table(name = "subscription") @AllArgsConstructor(access = AccessLevel.PROTECTED) @@ -24,6 +31,10 @@ public class Subscription extends BaseEntity { @Column(name = "subscription_id") private Long subscriptionId; + @Builder.Default + @OneToMany(mappedBy = "subscription", cascade = CascadeType.PERSIST, orphanRemoval = true) + private List subscriptionRecordsList = new ArrayList<>(); + @Column(name = "order_subscription_id", unique = true, nullable = false) private String orderSubscriptionId; @@ -43,11 +54,11 @@ public class Subscription extends BaseEntity { private Long subscriptionTotalAmount; @Column(name = "payment_date", nullable = false) - private LocalDate paymentDate; + private LocalDateTime paymentDate; @Column(name = "start_date", nullable = false) - private LocalDate startDate; + private LocalDateTime startDate; @Column(name = "end_date") - private LocalDate endDate; + private LocalDateTime endDate; } diff --git a/src/main/java/kr/bb/payment/entity/SubscriptionRecords.java b/src/main/java/kr/bb/payment/entity/SubscriptionRecords.java index 5950b2d..b2e0c2f 100644 --- a/src/main/java/kr/bb/payment/entity/SubscriptionRecords.java +++ b/src/main/java/kr/bb/payment/entity/SubscriptionRecords.java @@ -12,8 +12,12 @@ import kr.bb.payment.entity.common.BaseEntity; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; +@Getter +@Builder @Entity @Table(name = "subscription_records") @AllArgsConstructor(access = AccessLevel.PROTECTED) @@ -26,7 +30,7 @@ public class SubscriptionRecords extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "subcription_id") - private Subscription subscriptionId; + private Subscription subscription; @Column(name = "delivery_id", unique = true, nullable = false) private Long deliveryId; @@ -34,6 +38,8 @@ public class SubscriptionRecords extends BaseEntity { @Column(name = "subscription_total_amount", unique = true, nullable = false) private Long subscriptionTotalAmount; - @Column(name = "subscription_status", unique = true, nullable = false) - private String subscriptionStatus; + public void setSubscription(Subscription subscription){ + this.subscription = subscription; + subscription.getSubscriptionRecordsList().add(this); + } } diff --git a/src/main/java/kr/bb/payment/mapper/SubscriptionMapper.java b/src/main/java/kr/bb/payment/mapper/SubscriptionMapper.java new file mode 100644 index 0000000..824d2d1 --- /dev/null +++ b/src/main/java/kr/bb/payment/mapper/SubscriptionMapper.java @@ -0,0 +1,29 @@ +package kr.bb.payment.mapper; + +import kr.bb.payment.dto.response.KakaopayApproveResponseDto; +import kr.bb.payment.entity.Subscription; +import kr.bb.payment.entity.SubscriptionRecords; + +public class SubscriptionMapper { + public static Subscription toSubscriptionEntity(KakaopayApproveResponseDto responseDto) { + return Subscription.builder() + .orderSubscriptionId(responseDto.getPartnerOrderId()) + .subscriptionCid(responseDto.getCid()) + .subscriptionTid(responseDto.getTid()) + .subscriptionSid(responseDto.getSid()) + .subscriptionQuantity(Long.valueOf(responseDto.getQuantity())) + .subscriptionTotalAmount(Long.valueOf(responseDto.getAmount().getTotal())) + .startDate(responseDto.getCreatedAt()) // 시작일 + .paymentDate(responseDto.getCreatedAt().plusDays(30)) // 다음 결제일을 저장 + .build(); + } + + public static SubscriptionRecords toSubscriptionRecordsEntity( + KakaopayApproveResponseDto responseDto, Subscription subscription, Long deliveryId) { + return SubscriptionRecords.builder() + .subscription(subscription) + .deliveryId(deliveryId) + .subscriptionTotalAmount(Long.valueOf(responseDto.getAmount().getTotal())) + .build(); + } +} diff --git a/src/main/java/kr/bb/payment/repository/SubscriptionRecordsRepository.java b/src/main/java/kr/bb/payment/repository/SubscriptionRecordsRepository.java new file mode 100644 index 0000000..f76a31c --- /dev/null +++ b/src/main/java/kr/bb/payment/repository/SubscriptionRecordsRepository.java @@ -0,0 +1,6 @@ +package kr.bb.payment.repository; + +import kr.bb.payment.entity.SubscriptionRecords; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface SubscriptionRecordsRepository extends JpaRepository {} diff --git a/src/main/java/kr/bb/payment/repository/SubscriptionRepository.java b/src/main/java/kr/bb/payment/repository/SubscriptionRepository.java new file mode 100644 index 0000000..793a07b --- /dev/null +++ b/src/main/java/kr/bb/payment/repository/SubscriptionRepository.java @@ -0,0 +1,6 @@ +package kr.bb.payment.repository; + +import kr.bb.payment.entity.Subscription; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface SubscriptionRepository extends JpaRepository {} diff --git a/src/main/java/kr/bb/payment/service/KakaopayService.java b/src/main/java/kr/bb/payment/service/KakaopayService.java index 859a79b..4523065 100644 --- a/src/main/java/kr/bb/payment/service/KakaopayService.java +++ b/src/main/java/kr/bb/payment/service/KakaopayService.java @@ -1,10 +1,10 @@ package kr.bb.payment.service; +import bloomingblooms.domain.payment.KakaopayApproveRequestDto; +import bloomingblooms.domain.payment.KakaopayReadyRequestDto; +import bloomingblooms.domain.payment.KakaopayReadyResponseDto; import java.time.LocalDateTime; -import kr.bb.payment.dto.request.KakaopayApproveRequestDto; -import kr.bb.payment.dto.request.KakaopayReadyRequestDto; -import kr.bb.payment.dto.response.KakaoPayApproveResponseDto; -import kr.bb.payment.dto.response.KakaopayReadyResponseDto; +import kr.bb.payment.dto.response.KakaopayApproveResponseDto; import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Value; @@ -74,9 +74,9 @@ public LocalDateTime kakaoPayApprove(KakaopayApproveRequestDto requestDto) { String url = "https://kapi.kakao.com/v1/payment/approve"; - restTemplate.postForObject(url, requestEntity, KakaoPayApproveResponseDto.class); + KakaopayApproveResponseDto responseDto = restTemplate.postForObject(url, requestEntity, KakaopayApproveResponseDto.class); - return paymentService.savePaymentInfo(requestDto); + return paymentService.savePaymentInfo(requestDto, responseDto); } @NotNull diff --git a/src/main/java/kr/bb/payment/service/PaymentService.java b/src/main/java/kr/bb/payment/service/PaymentService.java index 9c022fc..13463f4 100644 --- a/src/main/java/kr/bb/payment/service/PaymentService.java +++ b/src/main/java/kr/bb/payment/service/PaymentService.java @@ -1,14 +1,16 @@ package kr.bb.payment.service; +import bloomingblooms.domain.payment.KakaopayApproveRequestDto; import java.time.LocalDateTime; -import kr.bb.payment.dto.request.KakaopayApproveRequestDto; -import kr.bb.payment.dto.request.KakaopayReadyRequestDto; -import kr.bb.payment.dto.response.KakaoPayApproveResponseDto; -import kr.bb.payment.dto.response.KakaopayReadyResponseDto; +import kr.bb.payment.dto.response.KakaopayApproveResponseDto; import kr.bb.payment.entity.OrderType; import kr.bb.payment.entity.Payment; -import kr.bb.payment.entity.PaymentStatus; +import kr.bb.payment.entity.Subscription; +import kr.bb.payment.entity.SubscriptionRecords; +import kr.bb.payment.mapper.SubscriptionMapper; import kr.bb.payment.repository.PaymentRepository; +import kr.bb.payment.repository.SubscriptionRecordsRepository; +import kr.bb.payment.repository.SubscriptionRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,25 +19,31 @@ @RequiredArgsConstructor public class PaymentService { private final PaymentRepository paymentRepository; + private final SubscriptionRepository subscriptionRepository; + private final SubscriptionRecordsRepository subscriptionRecordsRepository; /** * 카카오페이 결제 준비 (단건, 정기) - * - * @param requestDto - * @return void */ @Transactional public LocalDateTime savePaymentInfo( - KakaopayApproveRequestDto requestDto) { + KakaopayApproveRequestDto requestDto, KakaopayApproveResponseDto responseDto) { - OrderType type = - (requestDto.getOrderType().equals("ORDER_DELIVERY") - ? OrderType.ORDER_DELIVERY - : OrderType.ORDER_PICKUP); + // 정기 결제 저장 + if(OrderType.ORDER_SUBSCRIPTION.toString().equals(requestDto.getOrderType())){ + Subscription subscription = SubscriptionMapper.toSubscriptionEntity(responseDto); + // 배송id도 함께 저장 + SubscriptionRecords subscriptionRecords = SubscriptionMapper.toSubscriptionRecordsEntity(responseDto, subscription, requestDto.getDeliveryId()); - // Payment 객체를 DB에 저장 - Payment payment = Payment.toEntity(requestDto, type); - paymentRepository.save(payment); - return payment.getCreatedAt(); + // 연관관계 매핑 : 편의 메서드 적용 + subscriptionRecords.setSubscription(subscription); + subscriptionRepository.save(subscription); + return subscription.getCreatedAt(); + } else{ + // 단건 결제 저장 + Payment payment = Payment.toEntity(requestDto, OrderType.valueOf(requestDto.getOrderType())); + paymentRepository.save(payment); + return payment.getCreatedAt(); + } } } diff --git a/src/test/java/kr/bb/payment/service/KakaopayApproveTest.java b/src/test/java/kr/bb/payment/service/KakaopayApproveTest.java index b751400..ad063bf 100644 --- a/src/test/java/kr/bb/payment/service/KakaopayApproveTest.java +++ b/src/test/java/kr/bb/payment/service/KakaopayApproveTest.java @@ -1,9 +1,12 @@ package kr.bb.payment.service; +import bloomingblooms.domain.payment.KakaopayApproveRequestDto; import com.fasterxml.jackson.databind.ObjectMapper; -import kr.bb.payment.dto.request.KakaopayApproveRequestDto; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.time.LocalDateTime; + import kr.bb.payment.dto.response.Amount; -import kr.bb.payment.dto.response.KakaoPayApproveResponseDto; +import kr.bb.payment.dto.response.KakaopayApproveResponseDto; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -30,22 +33,24 @@ public class KakaopayApproveTest { void setUp() throws Exception { mockServer = MockRestServiceServer.createServer(restTemplate); - KakaoPayApproveResponseDto responseDto = - KakaoPayApproveResponseDto.builder() + KakaopayApproveResponseDto responseDto = + KakaopayApproveResponseDto.builder() .aid("A5678901234567890123") .tid("T1234567890123456789") .cid("TC0ONETIME") + .sid("sid가상번호") .partnerOrderId("partner_order_id") .partnerUserId("partner_user_id") .paymentMethodType("MONEY") .itemName("초코파이") .quantity(1) .amount(new Amount(2200, 0, 200, 0, 0)) - .createdAt("2016-11-15T21:18:22") - .approvedAt("2016-11-15T21:20:47") + .createdAt(LocalDateTime.now()) + .approvedAt(LocalDateTime.now()) .build(); ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); String responseJson = objectMapper.writeValueAsString(responseDto); mockServer @@ -92,6 +97,18 @@ KakaopayApproveRequestDto creatApproveRequestDto(String orderId, String orderTyp .cid("가게가맹점코드") .tid("T1234567890123456789") .pgToken("pg_token=xxxxxxxxxxxxxxxxxxxx") + .deliveryId(1L) .build(); } + + @DisplayName("결제 승인 테스트 - 구독") + @DirtiesContext + @Test + void kakaoPayApproveForSubscriptionTest() { + KakaopayApproveRequestDto requestDto = + creatApproveRequestDto("임시orderId2", "ORDER_SUBSCRIPTION"); + + 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 df226ca..0b95a07 100644 --- a/src/test/java/kr/bb/payment/service/KakaopayReadyTest.java +++ b/src/test/java/kr/bb/payment/service/KakaopayReadyTest.java @@ -1,7 +1,7 @@ package kr.bb.payment.service; -import kr.bb.payment.dto.request.KakaopayReadyRequestDto; -import kr.bb.payment.dto.response.KakaopayReadyResponseDto; +import bloomingblooms.domain.payment.KakaopayReadyRequestDto; +import bloomingblooms.domain.payment.KakaopayReadyResponseDto; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From e913e1ac2e43dfbad77f463a9c93b46368c338fa Mon Sep 17 00:00:00 2001 From: binarywoo27 Date: Sat, 30 Dec 2023 03:02:00 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:bug:=20=EA=B2=B0=EC=A0=9C=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/kr/bb/payment/entity/SubscriptionRecords.java | 2 +- .../java/kr/bb/payment/service/KakaopayService.java | 10 +++++----- src/test/resources/application.yml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/kr/bb/payment/entity/SubscriptionRecords.java b/src/main/java/kr/bb/payment/entity/SubscriptionRecords.java index b2e0c2f..8fafd15 100644 --- a/src/main/java/kr/bb/payment/entity/SubscriptionRecords.java +++ b/src/main/java/kr/bb/payment/entity/SubscriptionRecords.java @@ -35,7 +35,7 @@ public class SubscriptionRecords extends BaseEntity { @Column(name = "delivery_id", unique = true, nullable = false) private Long deliveryId; - @Column(name = "subscription_total_amount", unique = true, nullable = false) + @Column(name = "subscription_total_amount", nullable = false) private Long subscriptionTotalAmount; public void setSubscription(Subscription subscription){ diff --git a/src/main/java/kr/bb/payment/service/KakaopayService.java b/src/main/java/kr/bb/payment/service/KakaopayService.java index 4523065..08c559d 100644 --- a/src/main/java/kr/bb/payment/service/KakaopayService.java +++ b/src/main/java/kr/bb/payment/service/KakaopayService.java @@ -24,8 +24,8 @@ public class KakaopayService { @Value("${kakao.admin}") private String ADMIN_KEY; - @Value("${endpoint.front-url}") - private String FRONT_URL; + @Value("${endpoint.order-service}") + private String ORDER_SERVICE_URL; public KakaopayReadyResponseDto kakaoPayReady(KakaopayReadyRequestDto requestDto) { String cid = requestDto.isSubscriptionPay() ? "TCSUBSCRIP" : "TC0ONETIME"; @@ -42,13 +42,13 @@ public KakaopayReadyResponseDto kakaoPayReady(KakaopayReadyRequestDto requestDto parameters.add( "approval_url", - FRONT_URL + ORDER_SERVICE_URL + "/api/orders/approve/" + requestDto.getOrderId() + "/" + requestDto.getOrderType()); - parameters.add("cancel_url", FRONT_URL + "/api/orders/cancel"); - parameters.add("fail_url", FRONT_URL + "/api/orders/fail"); + parameters.add("cancel_url", ORDER_SERVICE_URL + "/api/orders/cancel"); + parameters.add("fail_url", ORDER_SERVICE_URL + "/api/orders/fail"); HttpEntity> requestEntity = new HttpEntity<>(parameters, this.getHeaders()); diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index ef4dcd5..89ca891 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -21,4 +21,4 @@ spring: kakao: admin: e217481aeaeb6c14f8f10912b441f961 endpoint: - front-url: http://localhost:3000 \ No newline at end of file + order-service: http://localhost:8900 \ No newline at end of file From 6f5c9328bff31a6908580cdbb5cab406942f6f27 Mon Sep 17 00:00:00 2001 From: binarywoo27 Date: Sat, 30 Dec 2023 13:59:11 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:bug:=20Git=EC=9D=98=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EB=8C=80=EC=86=8C=EB=AC=B8=EC=9E=90=20=EC=9D=B8=EC=8B=9D=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0=20=EC=8B=9C=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/KakaoPayApproveResponseDto.java | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.java diff --git a/src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.java b/src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.java deleted file mode 100644 index e9feb64..0000000 --- a/src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.java +++ /dev/null @@ -1,38 +0,0 @@ -package kr.bb.payment.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.time.LocalDateTime; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@Builder -@AllArgsConstructor -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class KakaopayApproveResponseDto { - private String aid; // 요청 고유번호 - private String tid; // 결제 고유번호 - private String cid; // 가맹점 코드 - private String sid; // 정기 결제용 id - @JsonProperty("partner_order_id") - private String partnerOrderId; // 가맹점 주문번호 - @JsonProperty("partner_user_id") - private String partnerUserId; // 가맹점 회원 - @JsonProperty("payment_method_type") - private String paymentMethodType; // 결제수단 - @JsonProperty("item_name") - private String itemName; - private Integer quantity; - @JsonProperty("created_at") - private LocalDateTime createdAt; - @JsonProperty("approved_at") - private LocalDateTime approvedAt; - private Amount amount; -} From 6cd8710c9dbe6eab165df9e67d24383a79f68a82 Mon Sep 17 00:00:00 2001 From: binarywoo27 Date: Sat, 30 Dec 2023 14:01:37 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:bug:=20Git=EC=9D=98=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EB=8C=80=EC=86=8C=EB=AC=B8=EC=9E=90=20=EC=9D=B8=EC=8B=9D=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0=20=EC=8B=9C=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradlew | 0 gradlew.bat | 184 ++++++++++++++++++++++++++-------------------------- 2 files changed, 92 insertions(+), 92 deletions(-) mode change 100755 => 100644 gradlew diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/gradlew.bat b/gradlew.bat index 6689b85..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,92 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega