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.

Revisions

  1. dipeshhkc created this gist Jan 15, 2023.
    39 changes: 39 additions & 0 deletions webhook.server.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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 });
    }
    };