feat(#29): Add ability to record that a user has purchased a product - part 1

This commit is contained in:
Josh Creek
2024-09-21 19:55:10 +01:00
parent b159c33487
commit d4f7f5041d
3 changed files with 26 additions and 9 deletions
+7 -4
View File
@@ -1,4 +1,4 @@
import type { RequestHandler } from '@sveltejs/kit';
import { json, type RequestHandler } from '@sveltejs/kit';
import stripe from 'stripe';
import { STRIPE_ENDPOINT_SECRET } from '$env/static/private';
import {
@@ -71,16 +71,19 @@ export const POST: RequestHandler = async ({ request }) => {
checkoutSession.customer as string,
true
);
} else if (checkoutSession.mode === 'payment') {
// TODO Record that they purchased the product
console.log(checkoutSession);
}
break;
}
default:
console.log(`Unhandled event type ${event.type}`)
console.log(`Unhandled event type ${event.type}`);
}
} catch (err) {
const message = err instanceof Error ? err.message : 'An unknown error has occurred';
return new Response(`Webhook Error: ${message}`, { status: 500 });
}
return json({received: true})
}
return json({ received: true });
};