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
This commit is contained in:
2022-12-29 23:10:11 +01:00
parent e86f22fbe2
commit 9c549b72f0
7 changed files with 145 additions and 63 deletions

View File

@@ -1,10 +1,33 @@
import validOrderId from '$lib/utils/validOrderId';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = ({ params }) => {
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,
isValidReceipt: validOrderId(id)
email,
order
};
};