Merge branch 'master' into 11-add-the-description-and-fetching-the-images-from-stripe-on-checkout-success-page

This commit is contained in:
Josh Creek
2024-10-22 19:38:46 +01:00
6 changed files with 117 additions and 31 deletions
+10 -1
View File
@@ -2,7 +2,7 @@ import { redirect } from '@sveltejs/kit';
import Stripe from 'stripe';
import { getProductById } from '$lib/utils/supabase/admin';
export const load = async ({ fetch }) => {
export const load: PageLoad = async ({ fetch }) => {
const response = await fetch('/api/checkout/status');
if (!response.ok) {
console.error('Failed to fetch checkout status');
@@ -24,6 +24,15 @@ export const load = async ({ fetch }) => {
lineItem.productDescription = product.description ?? '';
}
// Save the stripe customer id in the customers table
const stripeCustomerId = checkoutSession.customer as string;
const createCustomerResponse = await fetch(
'/api/checkout/create-customer?stripeCustomerId=' + stripeCustomerId
);
if (!createCustomerResponse.ok) {
console.error('Failed to create customer');
}
return {
checkoutSession,
lineItems