Commit 344fee7a authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

카카오페이api 승인완료

parent 73dd813f
...@@ -8,6 +8,7 @@ import catchErrors from '../utils/catchErrors' ...@@ -8,6 +8,7 @@ import catchErrors from '../utils/catchErrors'
const PaymentCompletePage = () => { const PaymentCompletePage = () => {
const { user } = useAuth() const { user } = useAuth()
const [error, setError] = useState() const [error, setError] = useState()
useEffect(() => { useEffect(() => {
if (user.role === "member") { if (user.role === "member") {
getUserInfo() getUserInfo()
...@@ -16,6 +17,11 @@ const PaymentCompletePage = () => { ...@@ -16,6 +17,11 @@ const PaymentCompletePage = () => {
} }
}, [user]) }, [user])
useEffect(() => {
const tid = localStorage.getItem('tid')
approveKakaopay(tid)
}, [])
async function getGuestInfo() { async function getGuestInfo() {
try { try {
if (user.id > 0) { if (user.id > 0) {
...@@ -35,7 +41,7 @@ const PaymentCompletePage = () => { ...@@ -35,7 +41,7 @@ const PaymentCompletePage = () => {
cinema: "Butter Studio 조치원", cinema: "Butter Studio 조치원",
title: "더 수어사이드 스쿼드", title: "더 수어사이드 스쿼드",
theater: "1", theater: "1",
time:"2021/07/21 10:00" time: "2021/07/21 10:00"
}) })
console.log(responseEmail.data) console.log(responseEmail.data)
} }
...@@ -61,7 +67,7 @@ const PaymentCompletePage = () => { ...@@ -61,7 +67,7 @@ const PaymentCompletePage = () => {
const responseEmail = await axios.post('/api/email/send', { const responseEmail = await axios.post('/api/email/send', {
...response2.data, ...response2.data,
...response.data, ...response.data,
}) })
console.log(responseEmail.data) console.log(responseEmail.data)
} }
...@@ -70,6 +76,26 @@ const PaymentCompletePage = () => { ...@@ -70,6 +76,26 @@ const PaymentCompletePage = () => {
} }
} }
async function approveKakaopay(tid) {
const urlParams = new URLSearchParams(window.location.search);
const pg_token = urlParams.get('pg_token');
try {
if (user) {
console.log(user.id)
const response = await axios.post(`/api/kakaopay/success`, {
'tid': tid,
cid: 'TC0ONETIME',
partner_order_id: 'butter_studio',
partner_user_id: '000000' + '6',
pg_token: pg_token
})
console.log(response.data)
}
} catch (error) {
catchErrors(error, setError)
}
}
return ( return (
<div className="text-center"> <div className="text-center">
<h3>예매가 정상적으로 완료되었습니다.</h3> <h3>예매가 정상적으로 완료되었습니다.</h3>
......
...@@ -77,8 +77,8 @@ const Payment = ({ location }) => { ...@@ -77,8 +77,8 @@ const Payment = ({ location }) => {
}) })
const responsekakao = await axios.post('/api/kakaopay/test/single', { const responsekakao = await axios.post('/api/kakaopay/test/single', {
cid: 'TC0ONETIME', cid: 'TC0ONETIME',
partner_order_id: 'orderNum', partner_order_id: 'butter_studio',
partner_user_id: userInfo.id || guestInfo.id, partner_user_id: '000000'+ (userInfo.id || guestInfo.id),
item_name: ticketInfo.title, item_name: ticketInfo.title,
quantity: ticketInfo.adult + ticketInfo.youth + ticketInfo.senior, quantity: ticketInfo.adult + ticketInfo.youth + ticketInfo.senior,
total_amount: ticketInfo.totalFee, total_amount: ticketInfo.totalFee,
...@@ -102,8 +102,8 @@ const Payment = ({ location }) => { ...@@ -102,8 +102,8 @@ const Payment = ({ location }) => {
}) })
const responsekakao = await axios.post('/api/kakaopay/test/single', { const responsekakao = await axios.post('/api/kakaopay/test/single', {
cid: 'TC0ONETIME', cid: 'TC0ONETIME',
partner_order_id: 'orderNum', partner_order_id: 'butter_studio',
partner_user_id: 'user', partner_user_id: '000000'+ guestID,
item_name: ticketInfo.title, item_name: ticketInfo.title,
quantity: ticketInfo.adult + ticketInfo.youth + ticketInfo.senior, quantity: ticketInfo.adult + ticketInfo.youth + ticketInfo.senior,
total_amount: ticketInfo.totalFee, total_amount: ticketInfo.totalFee,
...@@ -114,6 +114,7 @@ const Payment = ({ location }) => { ...@@ -114,6 +114,7 @@ const Payment = ({ location }) => {
cancel_url: 'http://localhost:3000/ticket', cancel_url: 'http://localhost:3000/ticket',
}) })
if (response && responsekakao) { if (response && responsekakao) {
localStorage.setItem('tid',responsekakao.data.tid)
window.location.href = responsekakao.data.redirect_url window.location.href = responsekakao.data.redirect_url
} }
} else { } else {
......
import axios from 'axios' import axios from 'axios'
import config from "../config/app.config.js"; import config from "../config/app.config.js";
const success = (req, res) => { const success = async(req, res) => {
return res.json({ try {
message: 'Success' // const { cid, tid, partner_order_id, partner_user_id, pg_token } = req.body
}) const item = req.body
const data = []
for (let property in item) {
let encodedKey = encodeURIComponent(property);
let encodedValue = encodeURIComponent(item[property]);
data.push(encodedKey + "=" + encodedValue);
}
const bodyData = data.join('&')
const response = await axios.post('https://kapi.kakao.com/v1/payment/approve', bodyData, {
headers: {
'Authorization': `KakaoAK ${config.kakaoAdminKey}`,
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
})
const resp = response.data
console.log('resp', resp)
res.json({...resp})
} catch (error) {
console.log(error)
}
} }
const fail = (req, res) => { const fail = (req, res) => {
...@@ -36,8 +57,8 @@ const singleTest = async (req, res) => { ...@@ -36,8 +57,8 @@ const singleTest = async (req, res) => {
}, },
}) })
const resp = response.data const resp = response.data
// console.log('resp', resp) console.log('resp', resp)
res.json({ redirect_url: resp.next_redirect_pc_url }) res.json({ tid: resp.tid, redirect_url: resp.next_redirect_pc_url })
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
......
...@@ -4,7 +4,7 @@ import kakaopayCtrl from '../controllers/kakaopay.controller.js' ...@@ -4,7 +4,7 @@ import kakaopayCtrl from '../controllers/kakaopay.controller.js'
const router = express.Router() const router = express.Router()
router.route('/success') router.route('/success')
.get(kakaopayCtrl.success) .post(kakaopayCtrl.success)
router.route('/fail') router.route('/fail')
.get(kakaopayCtrl.fail) .get(kakaopayCtrl.fail)
......
...@@ -57,6 +57,6 @@ router.route('/guestinfo/:guestId') ...@@ -57,6 +57,6 @@ router.route('/guestinfo/:guestId')
router router
.route("/:userId") .route("/:userId")
.get(userCtrl.compareId) // .get(userCtrl.compareId)
export default router; export default router;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment