-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use Stripe embedded checkout form
- Loading branch information
1 parent
bef71f8
commit 738833a
Showing
13 changed files
with
572 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import './src/envVars.js'; | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
swcMinify: true, | ||
output: 'standalone', // for Docker | ||
trailingSlash: false, | ||
}; | ||
|
||
export default nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
import { memo } from 'react'; | ||
import OrderConfirmation from '@/components/OrderConfirmation'; | ||
import { validateStripeSession } from '@/lib/stripe'; | ||
import { stripe } from '@/lib/stripe'; | ||
import { notFound } from 'next/navigation'; | ||
|
||
async function getSession(sessionId: string) { | ||
try { | ||
const session = await stripe.checkout.sessions.retrieve(sessionId!); | ||
return session; | ||
} catch (error) { | ||
return null; | ||
} | ||
} | ||
|
||
// Redirect page after successful checkout | ||
// <baseUrl>/order-confirmation?session_id=cs_test_b1FKoQomBOaQFgMqW1lU6oYXRwIruD6AbGV804gMZRrptJr1bF91sDmK5T | ||
const OrderConfirmationPage: React.FC<{ searchParams: { [key: string]: string | undefined } }> = async ({ searchParams }) => { | ||
const sessionId = searchParams['session_id']; | ||
const { validSession } = await validateStripeSession(sessionId); | ||
if (!validSession) return notFound(); | ||
if (!sessionId) return notFound(); | ||
|
||
const session = await getSession(sessionId); | ||
if (!session) return notFound(); | ||
|
||
if (session?.status === 'open') { | ||
return <p>Payment did not work.</p>; | ||
} | ||
|
||
if (session?.status === 'complete') { | ||
return ( | ||
<div className="my-8 mx-20"> | ||
<OrderConfirmation /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="my-8 mx-20"> | ||
<OrderConfirmation /> | ||
</div> | ||
); | ||
return notFound(); | ||
}; | ||
|
||
export default memo(OrderConfirmationPage); | ||
export default OrderConfirmationPage; |
Oops, something went wrong.