feat(#31): Add ability to record the stripe customer id in the customers table when a purchase is made

This commit is contained in:
Josh Creek
2024-10-20 18:37:40 +01:00
parent 03157a6d2f
commit 7d994d1c09
4 changed files with 80 additions and 8 deletions
+12 -3
View File
@@ -2,8 +2,8 @@ import type { PageLoad } from './$types';
import { redirect } from '@sveltejs/kit';
import Stripe from 'stripe';
export const load: PageLoad = async ({fetch}) => {
const response = await fetch('/api/checkout/status');
export const load: PageLoad = async ({ fetch }) => {
const response = await fetch('/api/checkout/status');
if (!response.ok) {
console.error('Failed to fetch checkout status');
return;
@@ -18,10 +18,19 @@ export const load: PageLoad = async ({fetch}) => {
throw redirect(303, '/checkout/cancelled');
}
// Save the stripe customer id in the customers table
const stripeCustomerId = checkoutSession.customer as string;
console.log('stripeCustomerId', stripeCustomerId);
const createCustomerResponse = await fetch(
'/api/checkout/create-customer?stripeCustomerId=' + stripeCustomerId
);
if (!createCustomerResponse.ok) {
console.error('Failed to create customer');
}
return {
checkoutSession,
lineItems,
paymentStatus
};
};