-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: Add Stripe embedded Checkout example (#60378)
- Loading branch information
1 parent
a7a403f
commit f82445b
Showing
12 changed files
with
159 additions
and
40 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
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
2 changes: 0 additions & 2 deletions
2
examples/with-stripe-typescript/app/donate-with-checkout/result/error.tsx
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,5 +1,3 @@ | ||
"use client"; | ||
|
||
export default function Error({ error }: { error: Error }) { | ||
return <h2>{error.message}</h2>; | ||
} |
2 changes: 0 additions & 2 deletions
2
examples/with-stripe-typescript/app/donate-with-elements/result/error.tsx
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,5 +1,3 @@ | ||
"use client"; | ||
|
||
export default function Error({ error }: { error: Error }) { | ||
return <h2>{error.message}</h2>; | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/with-stripe-typescript/app/donate-with-embedded-checkout/page.tsx
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Metadata } from "next"; | ||
|
||
import CheckoutForm from "@/components/CheckoutForm"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Donate with embedded Checkout | Next.js + TypeScript Example", | ||
}; | ||
|
||
export default function DonatePage(): JSX.Element { | ||
return ( | ||
<div className="page-container"> | ||
<h1>Donate with embedded Checkout</h1> | ||
<p>Donate to our project 💖</p> | ||
<CheckoutForm uiMode="embedded" /> | ||
</div> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/with-stripe-typescript/app/donate-with-embedded-checkout/result/error.tsx
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Error({ error }: { error: Error }) { | ||
return <h2>{error.message}</h2>; | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/with-stripe-typescript/app/donate-with-embedded-checkout/result/layout.tsx
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Metadata } from "next"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Checkout Session Result", | ||
}; | ||
|
||
export default function ResultLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}): JSX.Element { | ||
return ( | ||
<div className="page-container"> | ||
<h1>Checkout Session Result</h1> | ||
{children} | ||
</div> | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/with-stripe-typescript/app/donate-with-embedded-checkout/result/page.tsx
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Stripe } from "stripe"; | ||
|
||
import PrintObject from "@/components/PrintObject"; | ||
import { stripe } from "@/lib/stripe"; | ||
|
||
export default async function ResultPage({ | ||
searchParams, | ||
}: { | ||
searchParams: { session_id: string }; | ||
}): Promise<JSX.Element> { | ||
if (!searchParams.session_id) | ||
throw new Error("Please provide a valid session_id (`cs_test_...`)"); | ||
|
||
const checkoutSession: Stripe.Checkout.Session = | ||
await stripe.checkout.sessions.retrieve(searchParams.session_id, { | ||
expand: ["line_items", "payment_intent"], | ||
}); | ||
|
||
const paymentIntent = checkoutSession.payment_intent as Stripe.PaymentIntent; | ||
|
||
return ( | ||
<> | ||
<h2>Status: {paymentIntent.status}</h2> | ||
<h3>Checkout Session response:</h3> | ||
<PrintObject content={checkoutSession} /> | ||
</> | ||
); | ||
} |
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