-
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.
- Loading branch information
1 parent
52c4924
commit 7a1797a
Showing
12 changed files
with
274 additions
and
18 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
13 changes: 13 additions & 0 deletions
13
src/main/java/kr/bb/payment/config/RestTemplateConfig.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,13 @@ | ||
package kr.bb.payment.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class RestTemplateConfig { | ||
@Bean | ||
public RestTemplate restTemplate(){ | ||
return new RestTemplate(); | ||
} | ||
} |
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
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,30 @@ | ||
package kr.bb.payment.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@NoArgsConstructor | ||
public class Amount { | ||
|
||
private Integer total; | ||
private Integer tax_free; | ||
private Integer vat; | ||
private Integer point; | ||
private Integer discount; | ||
|
||
public Amount(Integer total, Integer tax_free, Integer vat, Integer point, Integer discount) { | ||
this.total = total; | ||
this.tax_free = tax_free; | ||
this.vat = vat; | ||
this.point = point; | ||
this.discount = discount; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/kr/bb/payment/dto/response/KakaoPayApproveResponseDto.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,37 @@ | ||
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; | ||
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 String createdAt; | ||
@JsonProperty("approved_at") | ||
private String approvedAt; | ||
private Amount amount; | ||
} |
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
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
100 changes: 100 additions & 0 deletions
100
src/test/java/kr/bb/payment/service/KakaopayApproveTest.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,100 @@ | ||
package kr.bb.payment.service; | ||
|
||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import kr.bb.payment.dto.request.KakaopayApproveRequestDto; | ||
import kr.bb.payment.dto.response.Amount; | ||
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.repository.PaymentRepository; | ||
import org.junit.jupiter.api.AfterEach; | ||
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.annotation.DirtiesContext; | ||
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 KakaopayApproveTest { | ||
@Autowired | ||
private RestTemplate restTemplate; | ||
private MockRestServiceServer mockServer; | ||
@Autowired | ||
private KakaopayService kakaopayService; | ||
@Autowired | ||
private PaymentRepository paymentRepository; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception{ | ||
mockServer = MockRestServiceServer.createServer(restTemplate); | ||
|
||
// Payment Entity 저장 | ||
Payment payment = | ||
Payment.builder() | ||
.userId(1L) | ||
.orderId(1L) | ||
.orderType(OrderType.ORDER_DELIVERY) | ||
.paymentCid("TC0ONETIME") | ||
.paymentTid("FAKE_TID_FOR_TEST") | ||
.paymentActualAmount(52900L) | ||
.paymentStatus(PaymentStatus.PENDING) | ||
.build(); | ||
paymentRepository.save(payment); | ||
|
||
KakaoPayApproveResponseDto responseDto = | ||
KakaoPayApproveResponseDto.builder() | ||
.aid("A5678901234567890123") | ||
.tid("T1234567890123456789") | ||
.cid("TC0ONETIME") | ||
.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") | ||
.build(); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
String responseJson = objectMapper.writeValueAsString(responseDto); | ||
|
||
mockServer | ||
.expect(MockRestRequestMatchers.requestTo("https://kapi.kakao.com/v1/payment/approve")) | ||
.andExpect(MockRestRequestMatchers.method(HttpMethod.POST)) | ||
.andRespond(MockRestResponseCreators.withSuccess(responseJson, MediaType.APPLICATION_JSON)); | ||
} | ||
|
||
@AfterEach | ||
void shutDown() { | ||
mockServer.reset(); | ||
} | ||
|
||
@DisplayName("결제 승인 테스트") | ||
@DirtiesContext | ||
@Test | ||
void kakaoPayApproveTest() { | ||
KakaopayApproveRequestDto requestDto = | ||
KakaopayApproveRequestDto.builder() | ||
.userId(1L) | ||
.orderId(1L) | ||
.tid("T1234567890123456789") | ||
.pgToken("pg_token=xxxxxxxxxxxxxxxxxxxx") | ||
.build(); | ||
|
||
kakaopayService.kakaoPayApprove(requestDto); | ||
|
||
mockServer.verify(); | ||
} | ||
} |
Oops, something went wrong.