You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB
JavaScript

import {useState, useEffect} from 'react'
import Head from 'next/head'
import axios from 'axios'
import Router from 'next/router'
import {useSetCart} from '~/hooks/useCart'
CheckoutComplete.getInitialProps = async function({ctx: {query: {session_id}}}){
return {session_id}
}
export default function CheckoutComplete({session_id}){
const [loading, setLoading] = useState(true)
const setCart = useSetCart()
useEffect(()=>{
(async ()=>{
const {data: {status}} = await axios.post('/api/orders/current/checkout/verify', {session_id})
if(status === "succeeded") {
setCart(null)
Router.push('/store/checkout/complete')
} else {
setLoading(false)
}
})()
}, [])
if(loading)
return (
<>
<Head>
<title>Verifying Payment | Society of Socks</title>
</Head>
<h2>Checkout</h2>
<p style={{textAlign: 'center'}}>Verifying your payment . . .</p>
</>
)
return (
<>
<Head>
<title>Checkout Error | Society of Socks</title>
</Head>
<h2>Checkout</h2>
<p style={{textAlign: 'center'}}>There was a problem with your payment.</p>
</>
)
}