-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 결제 연동 기능 테스트 #29 * feat: 결제 연동 구현에 맞춘 dbml 수정 #29 * feat: 결제 연동 구현 thymeleaf 오류 수정 1트 #29 * feat: 결제 연동 구현 thymeleaf 오류 수정 완료 #29 * .keep 생성 * fix: console.log to alert * fix: dbml 수정 #29 * feat: 결제 API 기본 템플릿 작성#29 * feat: 결제 DBML 수정 #29 * edit: 결제 DBML 수정 + 결제 API 초안 갈아엎기 #29 * edit: 결제 DBML 수정 + 결제 API 초안 갈아엎기 #29
- Loading branch information
1 parent
3c71800
commit f4d230a
Showing
15 changed files
with
305 additions
and
10 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
38 changes: 38 additions & 0 deletions
38
Api/src/main/java/picasso/server/api/exchange/controller/ExchangeController.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,38 @@ | ||
package picasso.server.api.exchange.controller; | ||
|
||
import com.siot.IamportRestClient.IamportClient; | ||
import com.siot.IamportRestClient.exception.IamportResponseException; | ||
import com.siot.IamportRestClient.response.IamportResponse; | ||
import com.siot.IamportRestClient.response.Payment; | ||
import jakarta.servlet.http.HttpSession; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import picasso.server.api.exchange.model.request.PostCreateExchangeRequest; | ||
import picasso.server.api.exchange.service.ExchangeService; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
@RequestMapping("/exchange") | ||
@RequiredArgsConstructor | ||
@RestController | ||
public class ExchangeController { | ||
|
||
private final ExchangeService exchangeService; | ||
private IamportClient api = new IamportClient("REST API KEY", "REST SECRET KEY"); | ||
private String impKey = System.getProperty("IMP"); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
Api/src/main/java/picasso/server/api/exchange/model/dto/ExchangeDTO.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 picasso.server.api.exchange.model.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import picasso.server.domain.domains.items.PaymentHistory; | ||
import picasso.server.domain.domains.items.PGName; | ||
import picasso.server.domain.domains.items.PayMethod; | ||
|
||
@Getter | ||
@Builder | ||
public class ExchangeDTO { | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
Api/src/main/java/picasso/server/api/exchange/model/request/PostCreateExchangeRequest.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 picasso.server.api.exchange.model.request; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import picasso.server.api.exchange.model.dto.ExchangeDTO; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class PostCreateExchangeRequest { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
Api/src/main/java/picasso/server/api/exchange/service/ExchangeService.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 picasso.server.api.exchange.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import picasso.server.api.exchange.model.dto.ExchangeDTO; | ||
import picasso.server.api.exchange.model.request.PostCreateExchangeRequest; | ||
import picasso.server.api.exchange.validator.ExchangeValidator; | ||
import picasso.server.domain.domains.items.PaymentHistory; | ||
import picasso.server.domain.domains.repository.ExchangeRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ExchangeService { | ||
|
||
private final ExchangeRepository exchangeRepository; | ||
private final ExchangeValidator exchangeValidator; | ||
|
||
|
||
} |
19 changes: 19 additions & 0 deletions
19
Api/src/main/java/picasso/server/api/exchange/util/ExchangeUtils.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,19 @@ | ||
package picasso.server.api.exchange.util; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import picasso.server.domain.domains.items.PaymentHistory; | ||
import picasso.server.domain.domains.repository.ExchangeRepository; | ||
|
||
@RequiredArgsConstructor | ||
public class ExchangeUtils { | ||
|
||
private final ExchangeRepository exchangeRepository; | ||
|
||
@Transactional | ||
public void save(PaymentHistory paymentHistory) { | ||
exchangeRepository.save(paymentHistory); | ||
} | ||
|
||
|
||
} |
17 changes: 17 additions & 0 deletions
17
Api/src/main/java/picasso/server/api/exchange/validator/ExchangeValidator.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 picasso.server.api.exchange.validator; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import picasso.server.common.annotation.Validator; | ||
import picasso.server.domain.domains.items.PaymentHistory; | ||
import picasso.server.domain.domains.repository.ExchangeRepository; | ||
|
||
@Validator | ||
@RequiredArgsConstructor | ||
public class ExchangeValidator { | ||
|
||
private final ExchangeRepository exchangeRepository; | ||
|
||
public boolean isExchangeValid(PaymentHistory paymentHistory) { | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var IMP = window.IMP; | ||
IMP.init("imp16618334"); // 재발급 받은 뒤 숨겨버릴 예정 | ||
|
||
var requestPayment = pg_name => { | ||
return IMP.request_pay({ | ||
pg : pg_name, | ||
pay_method : 'card', | ||
merchant_uid: "picasso_" + new Date().getMilliseconds(), // 계속 바뀌게 설정해야함. 결제에서 가장 중요한 정보 -> 이걸로 결제 하나하나를 식별함 | ||
name : 'asdfasdf', | ||
amount : 1004, | ||
buyer_email : 'Iamport@chai.finance', | ||
buyer_name : '아임포트 기술지원팀' | ||
}); | ||
} | ||
|
||
var paymentResult = obj => { | ||
var pg_name = obj.value | ||
return (requestPayment(pg_name), function(response) { | ||
if (response.success) { | ||
var msg = "결제 완료"; | ||
msg += '고유ID : ' + response.imp_uid; | ||
msg += '// 상점 거래ID : ' + response.merchant_uid; | ||
msg += '// 결제 금액 : ' + response.paid_amount; | ||
msg += '// 카드 승인번호 : ' + response.apply_num; | ||
|
||
postPayInfo(true); | ||
alert("결제가 완료되었습니다."); | ||
} else { | ||
var msg = "결제 실패" | ||
msg += "에러 내용" + response.error_msg; | ||
postPayInfo(false); | ||
alert("결제 실패입니다."); | ||
} | ||
}); | ||
} | ||
|
||
function postPayInfo(tof, rsp) { | ||
$.ajax({ | ||
type : 'post', | ||
url : '/pay', | ||
data : { | ||
"pay_result" : tof, | ||
"buyer_name" : rsp.buyer_name, | ||
"buyer_email" : rsp.buyer_email, | ||
"merchant_uid" : rsp.merchant_uid, | ||
"product_name" : rsp.name, | ||
"pg_provider" : rsp.pg_provider, | ||
"amount" : rsp.paid_amount, | ||
"pay_method" : rsp.pay_method | ||
}, | ||
}) | ||
} |
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,27 @@ | ||
<!DOCTYPE html> | ||
<html | ||
lang="ko" | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:th="http://www.thymeleaf.org" | ||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" | ||
> | ||
<head th:replace="~{fragment/config :: configFragment}"></head> | ||
<body> | ||
<input class="inputPrice" type="hidden"> | ||
<input class="amountValue" type="text"> | ||
<div> | ||
<h1>결제하기</h1> | ||
</div> | ||
<button id="kakaopay" onclick="paymentResult(this)" th:value="${T(picasso.server.domain.domains.items.PGName).KAKAO.getValue()}" type="button">카카오페이 결제하기</button> | ||
<button id="tosspay" onclick="paymentResult(this)" th:value="${T(picasso.server.domain.domains.items.PGName).TOSS.getValue()}" type="button">토스페이 결제하기</button> | ||
<div> | ||
<h3 class="amount" id="price_amount">결제 금액</h3> | ||
<label> | ||
<input onchange="inputPrice(this)"/> | ||
</label> | ||
</div> | ||
<script src="/static/js/pay_modal.js"></script> | ||
<script src="/js/paymentHistory.js"></script> | ||
</body> | ||
</html> | ||
|
19 changes: 19 additions & 0 deletions
19
Common/src/main/java/picasso/server/common/annotation/Validator.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,19 @@ | ||
package picasso.server.common.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.core.annotation.AliasFor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Component | ||
public @interface Validator { | ||
@AliasFor(annotation = Component.class) | ||
String value() default ""; | ||
} | ||
|
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
14 changes: 14 additions & 0 deletions
14
Domain/src/main/java/picasso/server/domain/domains/items/PGName.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 picasso.server.domain.domains.items; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum PGName { | ||
KAKAO("kakaopay.TC0ONETIME"), | ||
TOSS("tosspay.tosstest"); | ||
|
||
private final String value; | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
Domain/src/main/java/picasso/server/domain/domains/items/PayMethod.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 picasso.server.domain.domains.items; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum PayMethod { | ||
|
||
CARD("카드결제"), | ||
; | ||
|
||
private final String method; | ||
} |
36 changes: 36 additions & 0 deletions
36
Domain/src/main/java/picasso/server/domain/domains/items/PaymentHistory.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 picasso.server.domain.domains.items; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
public class PaymentHistory { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private PGName pgName; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private PayMethod payMethod; | ||
|
||
@NotNull | ||
private String productName; | ||
|
||
@NotNull | ||
private int amount; | ||
|
||
@NotNull | ||
private Long userId; | ||
} |
8 changes: 8 additions & 0 deletions
8
Domain/src/main/java/picasso/server/domain/domains/repository/ExchangeRepository.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,8 @@ | ||
package picasso.server.domain.domains.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import picasso.server.domain.domains.items.PaymentHistory; | ||
|
||
public interface ExchangeRepository extends JpaRepository<PaymentHistory, Long> { | ||
|
||
} |