mirror of
https://github.com/KevinMidboe/planetposen-frontend.git
synced 2025-10-29 13:10:12 +00:00
This is the page sent to after the payment is verified clientside at /checkout. While status is only initiated and not updated from stripe webhook we display spinner. TODO should still timeout to content message
34 lines
692 B
TypeScript
34 lines
692 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
|
|
export const load: PageServerLoad = async ({ fetch, params, url }) => {
|
|
const { id } = params;
|
|
const email = url.searchParams.get('email');
|
|
|
|
let order = null;
|
|
|
|
try {
|
|
const res = await fetch(`/api/v1/order/${id}`);
|
|
if (res?.status === 404) {
|
|
return {
|
|
id,
|
|
email,
|
|
order: null
|
|
};
|
|
}
|
|
const orderResponse = await res.json();
|
|
|
|
if (orderResponse?.order && orderResponse?.order?.lineItems?.length > 0) {
|
|
order = orderResponse?.order;
|
|
}
|
|
} catch (error) {
|
|
console.error('unable to parse order response');
|
|
throw error;
|
|
}
|
|
|
|
return {
|
|
id,
|
|
email,
|
|
order
|
|
};
|
|
};
|