Skip to content

Commit 16156ee

Browse files
authored
Merge pull request #108 from umc-commit/feat/107-payment-api
[FEAT] 결제 정보 저장 API JWT 인증 적용
2 parents 279dfc9 + 69a99d9 commit 16156ee

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

src/common/swagger/payment.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"post": {
55
"summary": "결제 완료 처리",
66
"description": "아임포트 imp_uid로 결제 검증 후 DB에 결제 내역, 포인트 거래 내역, 최종 포인트를 저장합니다.",
7+
"security": [
8+
{
9+
"bearerAuth": []
10+
}
11+
],
712
"tags": ["Payment"],
813
"requestBody": {
914
"required": true,
@@ -66,6 +71,25 @@
6671
}
6772
}
6873
},
74+
"401": {
75+
"description": "JWT 인증 실패 (Unauthorized)",
76+
"content": {
77+
"application/json": {
78+
"schema": {
79+
"$ref": "#/components/schemas/ErrorResponse"
80+
},
81+
"example": {
82+
"resultType": "FAIL",
83+
"error": {
84+
"errorCode": "AUTH001",
85+
"reason": "유효하지 않은 토큰입니다.",
86+
"data": null
87+
},
88+
"success": null
89+
}
90+
}
91+
}
92+
},
6993
"500": {
7094
"description": "서버 오류",
7195
"content": {

src/payment/controller/payment.controller.js

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

66
export const paymentConfirm = async (req, res, next) => {
77
try {
8-
const dto = new CreatePaymentDto({
9-
impUid: req.body.impUid,
10-
merchantUid: req.body.merchantUid,
11-
productId: req.body.productId,
12-
userId: req.body.userId,
13-
});
8+
const userId = req.user.id;
9+
10+
const dto = new CreatePaymentDto({
11+
impUid: req.body.impUid,
12+
merchantUid: req.body.merchantUid,
13+
productId: req.body.productId,
14+
userId: userId,
15+
});
1416

15-
const payment = await PaymentService.createPayment(dto);
16-
const responseData = parseWithBigInt(stringifyWithBigInt(payment));
17-
res.status(StatusCodes.CREATED).success(responseData);
18-
} catch (err) {
19-
next(err);
20-
}
17+
const payment = await PaymentService.createPayment(dto);
18+
const responseData = parseWithBigInt(stringifyWithBigInt(payment));
19+
res.status(StatusCodes.CREATED).success(responseData);
20+
} catch (err) {
21+
next(err);
22+
}
2123
}
2224

2325
export const getPayments = async (req, res, next) => {

src/payment/payment.routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { authenticate } from "../middlewares/auth.middleware.js";
66
const router = express.Router();
77

88
// 결제 정보 저장 API
9-
router.post("/complete", paymentConfirm);
9+
router.post("/complete", authenticate, paymentConfirm);
1010

1111
// 결제 정보 조회 API
1212
router.get("", authenticate, getPayments);

0 commit comments

Comments
 (0)