Skip to content

Instantly share code, notes, and snippets.

@dipeshhkc
Created January 15, 2023 23:45
Show Gist options
  • Save dipeshhkc/e0789d24c68c07dee0d090060c73fcf4 to your computer and use it in GitHub Desktop.
Save dipeshhkc/e0789d24c68c07dee0d090060c73fcf4 to your computer and use it in GitHub Desktop.
export const handleStripeEvent = async (
type: string,
data: Stripe.Event.Data,
id: string
) => {
try {
const isTestEvent = id === 'evt_00000000000000';
if (isTestEvent) {
return;
}
switch (type) {
case 'checkout.session.completed':
await handleCheckoutSessionCompleted(data.object);
break;
case 'customer.subscription.updated':
await handleCustomerSubscriptionUpdated(data.object);
break;
case 'invoice.paid':
await handleInvoicePaid(data.object);
break;
case 'invoice.payment_failed':
await handleInvoicePaymentFailed(data.object);
break;
case 'customer.subscription.deleted':
await handleCustomerSubscriptionDeleted(data.object);
break;
}
return true;
} catch (e) {
console.log({ message: e });
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment