-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.tsx
41 lines (34 loc) · 1.15 KB
/
result.tsx
1
2
3
4
5
6
7
8
9
10
11
12
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
38
39
40
41
import { NextPage } from 'next'
import { useRouter } from 'next/router'
import Layout from '../components/Layout'
import PrintObject from '../components/PrintObject'
import Cart from '../components/Cart'
import ClearCart from '../components/ClearCart'
import { fetchGetJSON } from '../utils/api-helpers'
import useSWR from 'swr'
const ResultPage: NextPage = () => {
const router = useRouter()
// Fetch CheckoutSession from static page via
// https://nextjs.org/docs/basic-features/data-fetching#static-generation
const { data, error } = useSWR(
router.query.session_id
? `/api/checkout_sessions/${router.query.session_id}`
: null,
fetchGetJSON
)
if (error) return <div>failed to load</div>
return (
<Layout title="Checkout Payment Result | Next.js + TypeScript Example">
<div className="page-container">
<h1>Checkout Payment Result</h1>
<h2>Status: {data?.payment_intent?.status ?? 'loading...'}</h2>
<h3>CheckoutSession response:</h3>
<PrintObject content={data ?? 'loading...'} />
<Cart>
<ClearCart />
</Cart>
</div>
</Layout>
)
}
export default ResultPage