File tree Expand file tree Collapse file tree 2 files changed +6
-21
lines changed
src/routes/examples/embedded-checkout Expand file tree Collapse file tree 2 files changed +6
-21
lines changed Original file line number Diff line number Diff line change 1- import { json } from '@sveltejs/kit'
21import Stripe from 'stripe'
32import { SECRET_STRIPE_KEY , DOMAIN } from '$env/static/private'
43
54const stripe = new Stripe ( SECRET_STRIPE_KEY )
65const return_url = new URL ( '/examples/embedded-checkout/thanks?session_id={CHECKOUT_SESSION_ID}' , DOMAIN ) . toString ( )
76
8- export async function POST ( ) {
7+ export async function load ( ) {
98 const session = await stripe . checkout . sessions . create ( {
109 ui_mode : 'embedded' ,
1110 line_items : [
@@ -18,7 +17,7 @@ export async function POST() {
1817 return_url
1918 } )
2019
21- return json ( {
20+ return {
2221 clientSecret : session . client_secret
23- } )
22+ }
2423}
Original file line number Diff line number Diff line change 11<script >
2- import { goto } from ' $app/navigation'
32 import { onMount } from ' svelte'
43 import { loadStripe } from ' @stripe/stripe-js'
54 import { PUBLIC_STRIPE_KEY } from ' $env/static/public'
65 import { EmbeddedCheckout } from ' $lib'
76
7+ export let data
8+
89 let stripe = null
9- let clientSecret = null
1010
1111 onMount (async () => {
1212 stripe = await loadStripe (PUBLIC_STRIPE_KEY )
13- clientSecret = await createCheckoutSession ()
1413 })
15-
16- async function createCheckoutSession () {
17- const response = await fetch (' /examples/embedded-checkout/checkout-session' , {
18- method: ' POST' ,
19- headers: {
20- ' content-type' : ' application/json'
21- },
22- body: JSON .stringify ({})
23- })
24- const { clientSecret } = await response .json ()
25-
26- return clientSecret
27- }
2814 </script >
2915
3016<h1 >Embedded Checkout Example</h1 >
3319 <a href =" https://github.com/joshnuss/svelte-stripe/tree/main/src/routes/examples/embedded-checkout" >View code</a >
3420</nav >
3521
36- <EmbeddedCheckout {stripe } { clientSecret }/>
22+ <EmbeddedCheckout {stripe } clientSecret ={ data . clientSecret }/>
You can’t perform that action at this time.
0 commit comments