Skip to content

Commit

Permalink
feat: 결제 승인 구현
Browse files Browse the repository at this point in the history
- 정보 최종 수합해 server index에서 결제 승인 구현

ref: #90
  • Loading branch information
Muon05 committed Oct 6, 2023
1 parent 2920f41 commit a7c93fc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const KakaoPayment = function () {
const BASE_URL = 'https://kapi.kakao.com/v1/payment/ready';
// TODO : 아래 있는 값 실시간으로 받아오게 만들기
const PARTNER_ORDER_ID = '12345678'; // TODO : unique한 값 생성하도록 변경하기
const PARTNER_USER_ID = 'slfjsdf';
const PARTNER_USER_ID = 'slfjfsdfff';
const ITEM_NAME = '진료비';
const QUANTITY = 1;
const TOTAL_AMOUNT = 15000;
Expand Down Expand Up @@ -50,6 +50,10 @@ const KakaoPayment = function () {
}
)
.then((response) => {
axios.post("http://localhost:3000/api/payment/kakao-tid", {PARTNER_ORDER_ID, PARTNER_USER_ID, ...response.data})
.then((listen) => console.log(listen.data))
.catch(e => console.error(e));

const { next_redirect_pc_url } = response.data;
window.location.href = next_redirect_pc_url
})
Expand Down
35 changes: 33 additions & 2 deletions packages/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
fbCreateCustomToken,
getNaverAuthApiUri,
} = require('./controllers/authController');
const { color } = require('framer-motion');

require('dotenv').config();

Expand Down Expand Up @@ -194,9 +195,39 @@ app.patch('/api/users/me', (req, res) => {
console.log(req.body);
});

let kakaoTid; // TODO : 깔끔하게 고치기
let partner_order_id;
let partner_user_id;

app.post('/api/payment/kakao-tid', (req, res) =>{
const { tid, PARTNER_ORDER_ID, PARTNER_USER_ID } = req.body;
kakaoTid = tid;
partner_order_id = PARTNER_ORDER_ID;
partner_user_id = PARTNER_USER_ID;
});

app.get('/kakao-payment/callback', async (req, res) =>{
const { pg_token } = req.query
console.log(pg_token)
const { pg_token } = req.query;

const API_URI = 'https://kapi.kakao.com/v1/payment/approve?cid=' +
process.env.KAKAO_PAYMENT_CID +
'&tid=' +
kakaoTid +
'&partner_order_id=' +
partner_order_id +
'&partner_user_id=' +
partner_user_id +
'&pg_token=' +
pg_token;

const payment_agree = await axios.post(API_URI, null,{
headers: {
"Authorization": `KakaoAK ${process.env.KAKAO_ADMIN_KEY}`,
"Content-type": "application/x-www-form-urlencoded;charset=utf-8"
},
});

console.log(payment_agree)
});

app.get('/api/hospitals', (req, res) => {
Expand Down

0 comments on commit a7c93fc

Please sign in to comment.