Skip to content

Commit b59a017

Browse files
authored
Merge pull request #167 from umc-commit/refactor/166-payment
2 parents cdde193 + 73aa031 commit b59a017

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

src/common/swagger/payment.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
"example": {
2121
"userId": 1,
2222
"productId": 1,
23-
"impUid": "imp_1234567890"
23+
"impUid": "imp_1234567890",
24+
"merchantUid": "order_no_1753062110278"
2425
}
2526
}
2627
}
2728
},
2829
"responses": {
29-
"200": {
30+
"201": {
3031
"description": "결제 완료 성공",
3132
"content": {
3233
"application/json": {

src/payment/controller/payment.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PaymentService } from "../service/payment.service.js";
55

66
export const paymentConfirm = async (req, res, next) => {
77
try {
8-
const userId = req.user.id;
8+
const userId = req.user.userId;
99

1010
const dto = new CreatePaymentDto({
1111
impUid: req.body.impUid,
@@ -24,7 +24,7 @@ export const paymentConfirm = async (req, res, next) => {
2424

2525
export const getPayments = async (req, res, next) => {
2626
try {
27-
const userId = req.user.id;
27+
const userId = req.user.userId;
2828

2929
const payments = await PaymentService.getPayments(userId);
3030
const responseData = parseWithBigInt(stringifyWithBigInt(payments));

views/client-paytest.ejs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@
77
</head>
88
<body>
99
<h1>아임포트 결제 테스트 페이지</h1>
10-
<button id="payment-button">결제하기</button>
10+
<button id="kakao-button">카카오페이 결제</button>
11+
<button id="tosspay-button">네이버페이 결제</button>
1112

1213
<script>
1314
const IMP = window.IMP;
14-
IMP.init("<%= impKey %>");
15+
IMP.init("<%= impKey %>"); // 서버에서 impKey 주입
1516
16-
document.getElementById("payment-button").addEventListener("click", () => {
17+
// 공통 결제 요청 함수
18+
function requestPayment(pgName) {
1719
IMP.request_pay(
1820
{
19-
pg: "kakaopay", // 테스트용 PG사 선택
21+
pg: pgName, // kakaopay 또는 naverpay
2022
pay_method: "card",
2123
merchant_uid: "order_no_" + new Date().getTime(), // 주문번호
2224
name: "테스트 상품",
23-
amount: 1200, // 테스트 결제 금액
25+
amount: 1200, // 금액
2426
buyer_email: "[email protected]",
2527
buyer_name: "테스트 사용자",
2628
buyer_tel: "010-1234-5678",
2729
},
2830
function (rsp) {
2931
if (rsp.success) {
30-
// 결제 성공 시 백엔드 검증 요청
3132
console.log("결제 성공", rsp);
3233
3334
fetch("http://localhost:3000/api/payments/complete", {
@@ -38,16 +39,15 @@
3839
body: JSON.stringify({
3940
impUid: rsp.imp_uid,
4041
merchantUid: rsp.merchant_uid,
41-
productId: 1, // productId
42-
userId: 3, // userId
43-
requestId: 1, // requestId
42+
productId: 1,
43+
userId: 3,
44+
requestId: 1,
4445
}),
4546
})
4647
.then((res) => res.json())
4748
.then((data) => {
4849
console.log("백엔드 검증 결과:", data);
49-
console.log(rsp.merchant_uid);
50-
alert("결제 및 검증 성공", rsp.merchant_uid);
50+
alert("결제 및 검증 성공: " + rsp.merchant_uid);
5151
})
5252
.catch((err) => {
5353
console.error(err);
@@ -59,6 +59,15 @@
5959
}
6060
}
6161
);
62+
}
63+
64+
// 버튼 이벤트 등록
65+
document.getElementById("kakao-button").addEventListener("click", () => {
66+
requestPayment("kakaopay");
67+
});
68+
69+
document.getElementById("tosspay-button").addEventListener("click", () => {
70+
requestPayment("tosspay");
6271
});
6372
</script>
6473
</body>

0 commit comments

Comments
 (0)