From fdd9afda174871c71399c58e8c04abf02cdbd0d0 Mon Sep 17 00:00:00 2001 From: Muon05 Date: Tue, 3 Oct 2023 20:43:55 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=9C=20=EC=A4=80=EB=B9=84=20(tid=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 우선 고정된 값을 담아 kakao api 서버로 정보 보내기 - consol에 tid 생성 - 카카오 결제 이미지 업로드 ref: #90 --- .../KakaoPaymentButton/KakaoPaymentButton.js | 65 ++++++++++++++++++ .../KakaoPaymentButton/package.json | 4 ++ .../kakao_payment_icon_yellow_medium.png | Bin 0 -> 1833 bytes packages/server/controllers/authController.js | 6 +- 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js create mode 100644 packages/apps/user/src/components/KakaoPaymentButton/package.json create mode 100644 packages/apps/user/src/images/kakao_payment_icon_yellow_medium.png diff --git a/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js b/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js new file mode 100644 index 00000000..2c59ee9d --- /dev/null +++ b/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js @@ -0,0 +1,65 @@ +import { useCallback } from 'react'; +import { Image } from '@chakra-ui/react'; +import axios from 'axios'; +import logo from '../../images/kakao_payment_icon_yellow_medium.png'; + +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 ITEM_NAME = '진료비'; + const QUANTITY = 1; + const TOTAL_AMOUNT = 15000; + const TAX_FREE_AMOUNT = 0; + const APPROVAL_URL = 'http://localhost:8080'; // TODO : 성공 url 변경하기 + const CANCEL_URL = 'http://localhost:8080'; // TODO : 취소 url 변경하기 + const FAIL_URL = 'http://localhost:8080'; // TODO : 실패(시간 초과) url 변경하기 + + const KAKAO_PAYMENT_READY_URL = + `${BASE_URL}?cid=` + + process.env.REACT_APP_KAKAO_PAYMENT_CID + + '&partner_order_id=' + + PARTNER_ORDER_ID + + '&partner_user_id=' + + PARTNER_USER_ID + + '&item_name=' + + ITEM_NAME + + '&quantity=' + + QUANTITY + + '&total_amount=' + + TOTAL_AMOUNT + + '&tax_free_amount=' + + TAX_FREE_AMOUNT + + '&approval_url=' + + APPROVAL_URL + + '&cancel_url=' + + CANCEL_URL + + '&fail_url=' + + FAIL_URL; + + const onPaymentClick = useCallback(() => { + axios.post( + KAKAO_PAYMENT_READY_URL, + null, // You can pass request data here if needed + { + headers: { + Authorization: `KakaoAK ${process.env.REACT_APP_KAKAO_ADMIN_KEY}`, + 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8', + }, + } + ) + .then((response) => { + // Handle the response here + console.log(response.data); // Log the response or update the state, etc. + }) + .catch((error) => { + // Handle errors here + console.error(error); + }); + }, [KAKAO_PAYMENT_READY_URL]); + + return ; +}; + +export default KakaoPayment; diff --git a/packages/apps/user/src/components/KakaoPaymentButton/package.json b/packages/apps/user/src/components/KakaoPaymentButton/package.json new file mode 100644 index 00000000..d962fdf8 --- /dev/null +++ b/packages/apps/user/src/components/KakaoPaymentButton/package.json @@ -0,0 +1,4 @@ +{ + "main": "KakaoPaymentButton.js" + } + \ No newline at end of file diff --git a/packages/apps/user/src/images/kakao_payment_icon_yellow_medium.png b/packages/apps/user/src/images/kakao_payment_icon_yellow_medium.png new file mode 100644 index 0000000000000000000000000000000000000000..9ec2a4371c715e8f99dde134763173d1cad0b0c1 GIT binary patch literal 1833 zcmV+^2iEwBP)X<;E_I>Z^>MIO`1@{)FF z5oJiH0Cs?MX$L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h`vx?jh?lnho96eBnNAx*qDE*>P;JsDnwIOn)j zS2=+Gxsqy$b%q0Z{#q@DSf966kFm%EDk;I4C17v;U%@d4-M3Yt^zDy3`6IJel|l&s|uzj2B!LDZIwj{ zFKeT)zAcXL*7SXKfcHM3rr$O-Fx4+mtrRZl1*$sgS0R^;D|{6)hx(=FF5v#9=0x;A X$5I+KUT?b%00000NkvXXu0mjf&4XZZ literal 0 HcmV?d00001 diff --git a/packages/server/controllers/authController.js b/packages/server/controllers/authController.js index 938f736c..17bd0586 100644 --- a/packages/server/controllers/authController.js +++ b/packages/server/controllers/authController.js @@ -1,5 +1,9 @@ const fbAdmin = require('../config/fbAdmin'); +const getKakaoAuthapiuri = (code, state) => { + +}; + const getNaverAuthApiUri = (code, state) => { const REDIRECT_URI = 'http://localhost:3000/api/auth/naver-callback'; @@ -24,4 +28,4 @@ const fbCreateCustomToken = async uid => { module.exports = { getNaverAuthApiUri, fbCreateCustomToken, -}; +}; \ No newline at end of file From 2920f41fb246207a11479b1e0753757863f0796e Mon Sep 17 00:00:00 2001 From: Muon05 Date: Wed, 4 Oct 2023 20:26:23 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20pg=5Ftoken=20=EB=B0=9B=EC=95=84?= =?UTF-8?q?=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tid 받아와 인증 요청 보내 결제 페이지 띄우기 - 사용자가 결제 승인하면 pg_token 받아오기 ref: #90 --- .../components/KakaoPaymentButton/KakaoPaymentButton.js | 9 ++++----- packages/server/index.js | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js b/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js index 2c59ee9d..b93d36bd 100644 --- a/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js +++ b/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js @@ -12,7 +12,7 @@ const KakaoPayment = function () { const QUANTITY = 1; const TOTAL_AMOUNT = 15000; const TAX_FREE_AMOUNT = 0; - const APPROVAL_URL = 'http://localhost:8080'; // TODO : 성공 url 변경하기 + const APPROVAL_URL = 'http://localhost:3000/kakao-payment/callback'; // TODO : 성공 url 변경하기 const CANCEL_URL = 'http://localhost:8080'; // TODO : 취소 url 변경하기 const FAIL_URL = 'http://localhost:8080'; // TODO : 실패(시간 초과) url 변경하기 @@ -41,7 +41,7 @@ const KakaoPayment = function () { const onPaymentClick = useCallback(() => { axios.post( KAKAO_PAYMENT_READY_URL, - null, // You can pass request data here if needed + null, { headers: { Authorization: `KakaoAK ${process.env.REACT_APP_KAKAO_ADMIN_KEY}`, @@ -50,11 +50,10 @@ const KakaoPayment = function () { } ) .then((response) => { - // Handle the response here - console.log(response.data); // Log the response or update the state, etc. + const { next_redirect_pc_url } = response.data; + window.location.href = next_redirect_pc_url }) .catch((error) => { - // Handle errors here console.error(error); }); }, [KAKAO_PAYMENT_READY_URL]); diff --git a/packages/server/index.js b/packages/server/index.js index b46d4240..a7bcba5f 100644 --- a/packages/server/index.js +++ b/packages/server/index.js @@ -194,6 +194,11 @@ app.patch('/api/users/me', (req, res) => { console.log(req.body); }); +app.get('/kakao-payment/callback', async (req, res) =>{ + const { pg_token } = req.query + console.log(pg_token) +}); + app.get('/api/hospitals', (req, res) => { res.json([ { From a7c93fcda016023bd52c48744dc76726b4840460 Mon Sep 17 00:00:00 2001 From: Muon05 Date: Fri, 6 Oct 2023 15:48:53 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=8A=B9?= =?UTF-8?q?=EC=9D=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 정보 최종 수합해 server index에서 결제 승인 구현 ref: #90 --- .../KakaoPaymentButton/KakaoPaymentButton.js | 6 +++- packages/server/index.js | 35 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js b/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js index b93d36bd..10ccaeb4 100644 --- a/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js +++ b/packages/apps/user/src/components/KakaoPaymentButton/KakaoPaymentButton.js @@ -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; @@ -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 }) diff --git a/packages/server/index.js b/packages/server/index.js index a7bcba5f..fff74421 100644 --- a/packages/server/index.js +++ b/packages/server/index.js @@ -7,6 +7,7 @@ const { fbCreateCustomToken, getNaverAuthApiUri, } = require('./controllers/authController'); +const { color } = require('framer-motion'); require('dotenv').config(); @@ -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) => {