PaymentPage.js 3.46 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import axios from 'axios'
2
import { useEffect, useState } from 'react'
Jiwon Yoon's avatar
Jiwon Yoon committed
3
import Kakaopay from '../components/Kakaopay'
4
5
import { useAuth } from '../context/auth_context'
import catchErrors from '../utils/catchErrors'
Jiwon Yoon's avatar
Jiwon Yoon committed
6
7
8

const Payment = ({ location }) => {
    const [ticketInfo, setTicketInfo] = useState({ ...location.state })
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    const [error, setError] = useState("")
    const [userInfo, setUserInfo] = useState()
    const { user } = useAuth()

    useEffect(() => {
        getUserInfo()
    }, [])

    async function getUserInfo() {
        try {
            const response = await axios.post(`/api/auth/getuserinfo`, {
                id: user.id
            })
            setUserInfo(response.data)
        } catch (error) {
            catchErrors(error, setError)
        }
    }


Jiwon Yoon's avatar
Jiwon Yoon committed
29
30
31

    async function SendMail(e) {
        try {
32
33
34
            const response = await axios.post('/api/email/send', {
                ...ticketInfo,
                ...userInfo
Jiwon Yoon's avatar
Jiwon Yoon committed
35
36
37
38
39
40
41
42
43
44
            })
            console.log(response.data)
        } catch (error) {
            console.log(error)
        }
    }

    return (
        <div className="container" style={{ color: "white" }}>
            {console.log(ticketInfo)}
45
            {console.log(userInfo)}
Jiwon Yoon's avatar
Jiwon Yoon committed
46
47
48
49
50
51
52
            <div className="row justify-content-center my-5">
                <div className="col-sm-4 mb-3 ">
                    <h3 className="py-2 text-white text-center" style={{ border: "3px solid #000000", borderBottom: "3px solid #FEDC00" }}>결제하기</h3>
                </div>
            </div>
            <div className="row justify-content-center">
                <div className="col-sm-8 text-center">
53
54
55
56
57
58
59
60
61
62
63
64
                    {user?.id > 0
                        ?
                        <div>
                            <h5 className="mb-3">회원정보</h5>

                        </div>
                        :
                        <div>
                            <h5 className="mb-3">비회원예매 정보입력</h5>

                        </div>
                    }
Jiwon Yoon's avatar
Jiwon Yoon committed
65
                    <h5 className="mb-3">결제방법</h5>
66
                    <img src="/images/naverpay_button.png" />
Jiwon Yoon's avatar
Jiwon Yoon committed
67
                    <Kakaopay ticketInfo={ticketInfo} setTicketInfo={setTicketInfo} />
68
69
70
                    <div className="my-5">
                        <button className="btn btn-warning" type="button" onClick={SendMail}>결제완료</button>
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
71
72
73
74
                </div>
                <div className="col-sm-4 p-3 text-center rounded-3" style={{ backgroundColor: "#252525" }}>
                    <img style={{ maxHeight: "10rem" }} src={`https://image.tmdb.org/t/p/original${ticketInfo.poster_path}`} alt="영화포스터" />
                    <h5 className="my-3">{ticketInfo.title}</h5>
75
                    <div>{ticketInfo.cinema}</div>
Jiwon Yoon's avatar
Jiwon Yoon committed
76
                    <div>{ticketInfo.time}</div>
77
78
                    <div className="mb-3">{ticketInfo.selectedTheater} {ticketInfo.selectedSeats}</div>
                    <div className="rounded-3 p-3" style={{ backgroundColor: '#404040' }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
79
80
81
                        <div>청소년: {ticketInfo.teenager}</div>
                        <div>성인: {ticketInfo.adult}</div>
                        <div>경로우대: {ticketInfo.elderly}</div>
82
                        <div> 결제금액: {ticketInfo.teenager * 7000 + ticketInfo.adult * 8000 + ticketInfo.elderly * 6000}</div>
Jiwon Yoon's avatar
Jiwon Yoon committed
83
84
85
                    </div>
                </div>
            </div>
86

Jiwon Yoon's avatar
Jiwon Yoon committed
87
88
89
90
91
        </div>
    )
}

export default Payment