-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from lotteon2/fix/develop
fix: 배치 정기결제 로직 수정 및 정기결제 취소 API 추가
- Loading branch information
Showing
14 changed files
with
329 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/kr/bb/payment/dto/request/KakaopayCancelRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.bb.payment.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class KakaopayCancelRequestDto { | ||
private String orderId; | ||
private Long cancelAmount; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/kr/bb/payment/dto/response/ApprovedCancelAmount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kr.bb.payment.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ApprovedCancelAmount { // 이번 요청으로 취소된 금액 | ||
private Integer total; | ||
private Integer tax_free; | ||
private Integer vat; | ||
private Integer point; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/kr/bb/payment/dto/response/CancelAvailableAmount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package kr.bb.payment.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CancelAvailableAmount { // 남은 취소 가능 금액 | ||
private Integer total; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/kr/bb/payment/dto/response/CanceledAmount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package kr.bb.payment.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CanceledAmount { // 누계 취소된 금액 | ||
private Integer total; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/kr/bb/payment/dto/response/KakaopayCancelResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package kr.bb.payment.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class KakaopayCancelResponseDto { | ||
private String cid; | ||
private String status; | ||
private String partner_order_id; | ||
private String partner_user_id; | ||
private ApprovedCancelAmount approved_cancel_amount; // 금번 취소 금액 | ||
private CanceledAmount canceled_amount; // 누적 취소 금액 | ||
private CancelAvailableAmount cancel_available_amount; | ||
private LocalDateTime created_at; | ||
private LocalDateTime canceled_at; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/kr/bb/payment/dto/response/KakaopayCancelSubscriptionResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kr.bb.payment.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class KakaopayCancelSubscriptionResponseDto { | ||
private String status; | ||
private LocalDateTime created_at; | ||
private LocalDateTime inactivated_at; | ||
private LocalDateTime last_approved_at; | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/kr/bb/payment/repository/SubscriptionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package kr.bb.payment.repository; | ||
|
||
import java.util.Optional; | ||
import kr.bb.payment.entity.Subscription; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SubscriptionRepository extends JpaRepository<Subscription, Long> { | ||
Subscription findBySubscriptionSid(String subscriptionSid); | ||
Optional<Subscription> findByOrderSubscriptionId(String orderSubscriptionId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/test/java/kr/bb/payment/service/KakaopayCancelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package kr.bb.payment.service; | ||
|
||
import bloomingblooms.domain.notification.order.OrderType; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import java.time.LocalDateTime; | ||
import kr.bb.payment.dto.request.KakaopayCancelRequestDto; | ||
import kr.bb.payment.dto.response.ApprovedCancelAmount; | ||
import kr.bb.payment.dto.response.CancelAvailableAmount; | ||
import kr.bb.payment.dto.response.CanceledAmount; | ||
import kr.bb.payment.dto.response.KakaopayCancelResponseDto; | ||
import kr.bb.payment.entity.Payment; | ||
import kr.bb.payment.entity.PaymentStatus; | ||
import kr.bb.payment.repository.PaymentRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.client.MockRestServiceServer; | ||
import org.springframework.test.web.client.match.MockRestRequestMatchers; | ||
import org.springframework.test.web.client.response.MockRestResponseCreators; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
public class KakaopayCancelTest { | ||
@Autowired private RestTemplate restTemplate; | ||
@Autowired private KakaopayService kakaopayService; | ||
@Autowired private PaymentRepository paymentRepository; | ||
private MockRestServiceServer mockServer; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
mockServer = MockRestServiceServer.createServer(restTemplate); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new JavaTimeModule()); | ||
String responseJson = objectMapper.writeValueAsString(kakaopayCancelResponseDto()); | ||
|
||
mockServer | ||
.expect(MockRestRequestMatchers.requestTo("https://kapi.kakao.com/v1/payment/cancel")) | ||
.andExpect(MockRestRequestMatchers.method(HttpMethod.POST)) | ||
.andRespond(MockRestResponseCreators.withSuccess(responseJson, MediaType.APPLICATION_JSON)); | ||
} | ||
|
||
@Test | ||
@DisplayName("카카오 결제 취소 테스트") | ||
void cancelPay() { | ||
// given | ||
KakaopayCancelRequestDto cancelRequestDto = | ||
KakaopayCancelRequestDto.builder().cancelAmount(2000L).orderId("orderGroupId").build(); | ||
|
||
Payment payment = Payment.builder() | ||
.orderId("orderGroupId") | ||
.orderType(OrderType.DELIVERY) | ||
.paymentActualAmount(10000L) | ||
.paymentCid("TC0ONETIME") | ||
.paymentStatus(PaymentStatus.PENDING) | ||
.paymentTid("T59eb9072dff7a6a6515") | ||
.paymentType("MONEY") | ||
.userId(1L) | ||
.build(); | ||
paymentRepository.save(payment); | ||
|
||
// when | ||
kakaopayService.cancelPayment(cancelRequestDto); | ||
|
||
mockServer.verify(); | ||
} | ||
|
||
private KakaopayCancelResponseDto kakaopayCancelResponseDto() { | ||
ApprovedCancelAmount approvedCancelAmount = | ||
ApprovedCancelAmount.builder().total(10000).tax_free(0).vat(0).point(0).build(); | ||
CanceledAmount canceledAmount = CanceledAmount.builder().total(10000).build(); | ||
CancelAvailableAmount cancelAvailableAmount = | ||
CancelAvailableAmount.builder().total(40000).build(); | ||
|
||
return KakaopayCancelResponseDto.builder() | ||
.cid("cid 번호") | ||
.status("주문취소") | ||
.partner_order_id("orderGroupId") | ||
.partner_user_id("userId") | ||
.approved_cancel_amount(approvedCancelAmount) | ||
.canceled_amount(canceledAmount) | ||
.cancel_available_amount(cancelAvailableAmount) | ||
.created_at(LocalDateTime.now().minusDays(10)) | ||
.canceled_at(LocalDateTime.now()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.