Monetization
Billing & License Fulfillment
Polar.sh Merchant of Record integration, checkout sessions, and webhook automation.
Checkouts are handled by Polar.sh, acting as the Merchant of Record for EU VAT calculation, invoicing, and global compliance.
src/routes/api/checkout/+server.ts
const checkout = await polar.checkouts.create({
products: [productId],
successUrl: `${origin}/welcome?checkout_id={CHECKOUT_ID}`,
customerEmail: locals.user?.email,
metadata: { userId: locals.user?.id }
});The webhook handler verifies incoming Polar signatures via HMAC, upserts the customer and purchase records, generates a unique license key, and triggers transactional fulfillment emails.