mirror of
https://github.com/KevinMidboe/planetposen-frontend.git
synced 2025-10-29 13:10:12 +00:00
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:
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user