Kakaopay.js 1.25 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
2
import axios from 'axios'

Jiwon Yoon's avatar
Jiwon Yoon committed
3
const Kakaopay = ({ticketInfo}) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
4
5
6
7
8
9
    async function handleClick() {
        try {
            const response = await axios.post('/api/kakaopay/test/single', {
                cid: 'TC0ONETIME',
                partner_order_id: 'orderNum',
                partner_user_id: 'userName',
Jiwon Yoon's avatar
Jiwon Yoon committed
10
11
12
                item_name: ticketInfo.title,
                quantity: ticketInfo.teenager+ticketInfo.adult+ticketInfo.elderly,
                total_amount: ticketInfo.teenager * 7000 + ticketInfo.adult * 8000 + ticketInfo.elderly * 6000,
Jiwon Yoon's avatar
Jiwon Yoon committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
                vat_amount: 0,
                tax_free_amount: 0,
                approval_url: 'http://localhost:3000/',
                fail_url: 'http://localhost:3000/',
                cancel_url: 'http://localhost:3000/',
            })
            console.log(response.data)
            if (response.data) {
                window.location.href = response.data.redirect_url
            }
        } catch (error) {
            console.log(error)
        }
    }

    return (
        <>
            <button onClick={handleClick} style={{ backgroundColor: "black", border: '0' }}>
                <img src="/images/payment_icon_yellow_medium.png" />
            </button>
        </>
    )
}

export default Kakaopay