Created
January 16, 2023 03:24
-
-
Save dipeshhkc/c3ee8e6054a357bc67e682a1ba1f3f4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handleInvoicePaid = async (data: Stripe.Event.Data.Object) => { | |
const invoice = data as Stripe.Invoice; | |
const stripeSubId = invoice.subscription?.toString(); | |
if ( | |
invoice.billing_reason === 'subscription_create' || | |
invoice.billing_reason === 'subscription_update' | |
) { | |
// this should already be handled with 'checkout.session.completed' or with 'customer.subscription.updated' | |
return; | |
} | |
const subscription = await db.subscription.findFirst({ | |
where: { | |
stripe_subscription_id: stripeSubId, | |
}, | |
}); | |
await db.subscription.update({ | |
where: { id: subscription!.id }, | |
data: { ends_at: null, stripe_status: 'active' }, | |
}); | |
console.log({ message: 'Invoice paid' }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment