#binod-subscription webhooks
1 messages · Page 1 of 1 (latest)
hi
i have implemented webhook for subscription payment
webhook is being triggered but displaying internal server error
webhook ID we_1LKkk9HsW9ET26JguGyryPwz
which code?
if (event.type === STRIPE_EVENTS.INVOICE_PAID) { const { object } = event.data; const { customer_email } = object; const subscription = await stripe.subscriptions.retrieve(object.subscription); if (!subscription) throw Error('Subscription not found!'); const { plan } = subscription; const product = await stripe.products.retrieve(plan.product); const tenant = await getByEmail(customer_email); const membership_payload = { name: product.name, tenant: tenant._id, email: customer_email, stripe_cus_id: object.customer, plan_id: plan.id, subscription_id: object.subscription, expiry_date: createISODateString(subscription.current_period_end), }; return createOrUpdateMembership(membership_payload); }
I would need to take a look at your code to help you debug where the problem might be occurring
I think the problem is before the "switch" on event types
const { payload, headers } = req; const sig = headers['stripe-signature']; let event; try { event = stripe.webhooks.constructEvent(payload, sig, WEBHOOK_SECRET);
Its working on local
Its working on local
using stripe cli?
oh sorry, that fell under my radar
I think there's an issue with the code regardless of the event
I can't see a direct link to any particular event handling
if (event.type === STRIPE_EVENTS.INVOICE_PAID) { const { object } = event.data; const { customer_email } = object; const subscription = await stripe.subscriptions.retrieve(object.subscription); if (!subscription) throw Error('Subscription not found!'); const { plan } = subscription; const product = await stripe.products.retrieve(plan.product); const tenant = await getByEmail(customer_email); const membership_payload = { name: product.name, tenant: tenant._id, email: customer_email, stripe_cus_id: object.customer, plan_id: plan.id, subscription_id: object.subscription, expiry_date: createISODateString(subscription.current_period_end), };
im using paid event
I would strongly recommend you putting a lot of logs and trying to debug this
I don't think it's related to that part of the code
its working on local
yes it might be infrastructural it might a lot of things
there's something wrong and without proper logging I wouldn't be able to help you find the issue
okay