-
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 #3 from lotteon2/LF1-302-single-payment
Jacoco 설정 및 카카오페이 결제준비 Service, Repository Test 생성
- Loading branch information
Showing
17 changed files
with
416 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lombok.addLombokGeneratedAnnotation = true |
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
36 changes: 36 additions & 0 deletions
36
src/main/java/kr/bb/payment/controller/clientcontroller/OrderClientController.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,36 @@ | ||
package kr.bb.payment.controller.clientcontroller; | ||
|
||
import bloomingblooms.response.SuccessResponse; | ||
import kr.bb.payment.dto.request.KakaopayReadyRequestDto; | ||
import kr.bb.payment.dto.response.KakaopayReadyResponseDto; | ||
import kr.bb.payment.service.KakaopayReadyService; | ||
import kr.bb.payment.service.PaymentService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class OrderClientController { | ||
|
||
private final PaymentService paymentService; | ||
private final KakaopayReadyService kakaopayReadyService; | ||
|
||
@PostMapping("/ready") | ||
public ResponseEntity<SuccessResponse<KakaopayReadyResponseDto>> payReady( | ||
@RequestBody KakaopayReadyRequestDto readyRequestDto) { | ||
|
||
KakaopayReadyResponseDto responseDto = kakaopayReadyService.kakaoPayReady(readyRequestDto); | ||
|
||
return ResponseEntity.ok() | ||
.body( | ||
SuccessResponse.<KakaopayReadyResponseDto>builder() | ||
.code(String.valueOf(HttpStatus.OK.value())) | ||
.message(HttpStatus.OK.name()) | ||
.data(responseDto) | ||
.build()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/kr/bb/payment/controller/restcontroller/PaymentRestController.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,12 @@ | ||
package kr.bb.payment.controller.restcontroller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@RequiredArgsConstructor | ||
public class PaymentRestController { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/kr/bb/payment/dto/request/KakaopayReadyRequestDto.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,22 @@ | ||
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; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/kr/bb/payment/dto/response/KakaopayReadyResponseDto.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,18 @@ | ||
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; | ||
} |
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,13 @@ | ||
package kr.bb.payment.entity; | ||
|
||
public enum PaymentStatus { | ||
PENDING("주문 중"), | ||
COMPLETED("주문 완료"), | ||
CANCELED("주문 취소"); | ||
|
||
private final String message; | ||
|
||
PaymentStatus(String message) { | ||
this.message = message; | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
src/main/java/kr/bb/payment/service/KakaopayReadyService.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,67 @@ | ||
package kr.bb.payment.service; | ||
|
||
import kr.bb.payment.dto.request.KakaopayReadyRequestDto; | ||
import kr.bb.payment.dto.response.KakaopayReadyResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class KakaopayReadyService { | ||
private final PaymentService paymentService; | ||
|
||
@Value("${kakao.admin}") | ||
private String ADMIN_KEY; | ||
|
||
@Value("${host.fronturl}") | ||
private String FRONT_URL; | ||
|
||
public KakaopayReadyResponseDto kakaoPayReady(KakaopayReadyRequestDto requestDto) { | ||
String cid = requestDto.isSubscriptionPay() ? "TC0ONETIME" : "TCSUBSCRIP"; | ||
|
||
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(); | ||
|
||
parameters.add("cid", cid); | ||
parameters.add("partner_order_id", requestDto.getOrderId()); | ||
parameters.add("partner_user_id", requestDto.getUserId()); | ||
parameters.add("item_name", requestDto.getItemName()); | ||
parameters.add("quantity", String.valueOf(requestDto.getQuantity())); | ||
parameters.add("total_amount", String.valueOf(requestDto.getTotalAmount())); | ||
parameters.add("tax_free_amount", String.valueOf(requestDto.getTaxFreeAMount())); | ||
|
||
parameters.add( | ||
"approval_url", | ||
FRONT_URL + "/payments/approve/" + requestDto.getOrderId() + "/" + requestDto.getUserId()); | ||
parameters.add("cancel_url", FRONT_URL + "/payments/cancel"); | ||
parameters.add("fail_url", FRONT_URL + "/payments/fail"); | ||
|
||
HttpEntity<MultiValueMap<String, String>> requestEntity = | ||
new HttpEntity<>(parameters, this.getHeaders()); | ||
|
||
RestTemplate template = new RestTemplate(); | ||
String url = "https://kapi.kakao.com/v1/payment/ready"; | ||
KakaopayReadyResponseDto responseDto = | ||
template.postForObject(url, requestEntity, KakaopayReadyResponseDto.class); | ||
|
||
paymentService.savePayReadyInfo(requestDto, responseDto, cid); | ||
|
||
return responseDto; | ||
} | ||
|
||
@NotNull | ||
private HttpHeaders getHeaders() { | ||
HttpHeaders headers = new HttpHeaders(); | ||
|
||
String auth = "KakaoAK " + ADMIN_KEY; | ||
headers.set("Authorization", auth); | ||
headers.set("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); | ||
return headers; | ||
} | ||
} |
Oops, something went wrong.