#binod-subscription webhooks

1 messages · Page 1 of 1 (latest)

umbral solar
#

👋 happy to help

obtuse sigil
#

hi

#

i have implemented webhook for subscription payment

#

webhook is being triggered but displaying internal server error

#

webhook ID we_1LKkk9HsW9ET26JguGyryPwz

umbral solar
#

let me take a look

#

could you please share your code?

obtuse sigil
#

which code?

umbral solar
#

the webhook endpoint code

#

this is an error generated from your code

obtuse sigil
#

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); }

umbral solar
#

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

obtuse sigil
#

const { payload, headers } = req; const sig = headers['stripe-signature']; let event; try { event = stripe.webhooks.constructEvent(payload, sig, WEBHOOK_SECRET);

#

Its working on local

umbral solar
#

Its working on local
using stripe cli?

obtuse sigil
#

yes

#

??

umbral solar
#

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

obtuse sigil
#

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

umbral solar
#

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

obtuse sigil
#

its working on local

umbral solar
#

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

obtuse sigil
#

okay