Files
planetposen-frontend/src/routes/receipt/[[id]]/+layout.server.ts
Kevin Midboe 9c549b72f0 Polls for order status & displays loading while status=initiated
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
2022-12-29 23:11:56 +01:00

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
};
};