try {
const checkout = await paykit.checkouts.create({
customer: 'cus_123',
item_id: 'price_123',
session_type: 'one_time',
quantity: 1,
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
});
redirect(checkout.payment_url);
} catch (error) {
if (error instanceof ValidationError) {
return res.status(400).json({ error: error.message });
}
if (error instanceof ProviderNotSupportedError) {
return res.status(501).json({ error: 'Not supported by this provider' });
}
return res.status(500).json({ error: 'Unexpected error' });
}