diff --git a/src/lib/components/products/ProductsListItem.svelte b/src/lib/components/products/ProductsListItem.svelte new file mode 100644 index 0000000..40574a5 --- /dev/null +++ b/src/lib/components/products/ProductsListItem.svelte @@ -0,0 +1,38 @@ + + + + + + + + + + {product.name} + £{product.actualPrice} + + + + + + + + diff --git a/src/routes/products/+page.svelte b/src/routes/products/+page.svelte new file mode 100644 index 0000000..ad1edd7 --- /dev/null +++ b/src/routes/products/+page.svelte @@ -0,0 +1,41 @@ + + + + + + Available Products + + + {#each products as product (product.id)} + + {/each} + + {#if enablePagination} + + + 1 + 2 + 3 + 4 + + + {/if} + + diff --git a/src/routes/products/+server.ts b/src/routes/products/+server.ts new file mode 100644 index 0000000..70e129d --- /dev/null +++ b/src/routes/products/+server.ts @@ -0,0 +1,23 @@ +import { json } from '@sveltejs/kit'; +import { PUBLIC_STRIPE_SECRET_KEY } from '$env/static/public'; +import stripe from 'stripe'; +const stripeClient = new stripe(PUBLIC_STRIPE_SECRET_KEY); + +export const GET = async () => { + const products = await stripeClient.products.list({ + limit: 100 + }); + + try { + // Get the price for each product + for (const product of products.data) { + const price = await stripeClient.prices.retrieve(product.default_price as string); + if (price) { + product.actualPrice = price.unit_amount / 100; + } + } + } catch (error) { + console.error(error); + } + return json(products); +}; diff --git a/src/routes/products/prices/[priceId]/+server.ts b/src/routes/products/prices/[priceId]/+server.ts new file mode 100644 index 0000000..b1fca62 --- /dev/null +++ b/src/routes/products/prices/[priceId]/+server.ts @@ -0,0 +1,10 @@ +import { json } from '@sveltejs/kit'; +import { PUBLIC_STRIPE_SECRET_KEY } from '$env/static/public'; +import stripe from 'stripe'; +const stripeClient = new stripe(PUBLIC_STRIPE_SECRET_KEY); + +export const GET = async ({ params }) => { + const { priceId } = params; + const price = await stripeClient.prices.retrieve(priceId); + return json(price); +};