Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
butter-studio
Commits
344fee7a
Commit
344fee7a
authored
Aug 09, 2021
by
Jiwon Yoon
Browse files
카카오페이api 승인완료
parent
73dd813f
Changes
5
Show whitespace changes
Inline
Side-by-side
client/src/pages/PaymentCompletePage.js
View file @
344fee7a
...
...
@@ -8,6 +8,7 @@ import catchErrors from '../utils/catchErrors'
const
PaymentCompletePage
=
()
=>
{
const
{
user
}
=
useAuth
()
const
[
error
,
setError
]
=
useState
()
useEffect
(()
=>
{
if
(
user
.
role
===
"
member
"
)
{
getUserInfo
()
...
...
@@ -16,6 +17,11 @@ const PaymentCompletePage = () => {
}
},
[
user
])
useEffect
(()
=>
{
const
tid
=
localStorage
.
getItem
(
'
tid
'
)
approveKakaopay
(
tid
)
},
[])
async
function
getGuestInfo
()
{
try
{
if
(
user
.
id
>
0
)
{
...
...
@@ -35,7 +41,7 @@ const PaymentCompletePage = () => {
cinema
:
"
Butter Studio 조치원
"
,
title
:
"
더 수어사이드 스쿼드
"
,
theater
:
"
1
"
,
time
:
"
2021/07/21 10:00
"
time
:
"
2021/07/21 10:00
"
})
console
.
log
(
responseEmail
.
data
)
}
...
...
@@ -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
(
<
div
className
=
"
text-center
"
>
<
h3
>
예매가
정상적으로
완료되었습니다
.
<
/h3
>
...
...
client/src/pages/PaymentPage/PaymentPage.js
View file @
344fee7a
...
...
@@ -77,8 +77,8 @@ const Payment = ({ location }) => {
})
const
responsekakao
=
await
axios
.
post
(
'
/api/kakaopay/test/single
'
,
{
cid
:
'
TC0ONETIME
'
,
partner_order_id
:
'
orderNum
'
,
partner_user_id
:
userInfo
.
id
||
guestInfo
.
id
,
partner_order_id
:
'
butter_studio
'
,
partner_user_id
:
'
000000
'
+
(
userInfo
.
id
||
guestInfo
.
id
)
,
item_name
:
ticketInfo
.
title
,
quantity
:
ticketInfo
.
adult
+
ticketInfo
.
youth
+
ticketInfo
.
senior
,
total_amount
:
ticketInfo
.
totalFee
,
...
...
@@ -102,8 +102,8 @@ const Payment = ({ location }) => {
})
const
responsekakao
=
await
axios
.
post
(
'
/api/kakaopay/test/single
'
,
{
cid
:
'
TC0ONETIME
'
,
partner_order_id
:
'
orderNum
'
,
partner_user_id
:
'
user
'
,
partner_order_id
:
'
butter_studio
'
,
partner_user_id
:
'
000000
'
+
guestID
,
item_name
:
ticketInfo
.
title
,
quantity
:
ticketInfo
.
adult
+
ticketInfo
.
youth
+
ticketInfo
.
senior
,
total_amount
:
ticketInfo
.
totalFee
,
...
...
@@ -114,6 +114,7 @@ const Payment = ({ location }) => {
cancel_url
:
'
http://localhost:3000/ticket
'
,
})
if
(
response
&&
responsekakao
)
{
localStorage
.
setItem
(
'
tid
'
,
responsekakao
.
data
.
tid
)
window
.
location
.
href
=
responsekakao
.
data
.
redirect_url
}
}
else
{
...
...
server/controllers/kakaopay.controller.js
View file @
344fee7a
import
axios
from
'
axios
'
import
config
from
"
../config/app.config.js
"
;
const
success
=
(
req
,
res
)
=>
{
return
res
.
json
({
message
:
'
Success
'
const
success
=
async
(
req
,
res
)
=>
{
try
{
// 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
)
=>
{
...
...
@@ -36,8 +57,8 @@ const singleTest = async (req, res) => {
},
})
const
resp
=
response
.
data
//
console.log('resp', resp)
res
.
json
({
redirect_url
:
resp
.
next_redirect_pc_url
})
console
.
log
(
'
resp
'
,
resp
)
res
.
json
({
tid
:
resp
.
tid
,
redirect_url
:
resp
.
next_redirect_pc_url
})
}
catch
(
error
)
{
console
.
log
(
error
)
}
...
...
server/routes/kakaopay.route.js
View file @
344fee7a
...
...
@@ -4,7 +4,7 @@ import kakaopayCtrl from '../controllers/kakaopay.controller.js'
const
router
=
express
.
Router
()
router
.
route
(
'
/success
'
)
.
ge
t
(
kakaopayCtrl
.
success
)
.
pos
t
(
kakaopayCtrl
.
success
)
router
.
route
(
'
/fail
'
)
.
get
(
kakaopayCtrl
.
fail
)
...
...
server/routes/user.route.js
View file @
344fee7a
...
...
@@ -57,6 +57,6 @@ router.route('/guestinfo/:guestId')
router
.
route
(
"
/:userId
"
)
.
get
(
userCtrl
.
compareId
)
//
.get(userCtrl.compareId)
export
default
router
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment