#m4rt1ns_1993

1 messages · Page 1 of 1 (latest)

quasi terraceBOT
livid vessel
#

hi! sure, you can call the API or do any action you choose when handling the webhook.

strong glacier
#

Then why the metadata is not being cleared?

#

I have this code.

case 'customer.subscription.updated': { const { cancellation_details, cancel_at, id } = data || {} const { reason } = cancellation_details try { if (['cancellation_requested'].includes(reason)) { // Admin requested subscription to be cancelled in future date await updateOrganisationValue(orgId, { subscriptionEndDate: format(fromUnixTime(cancel_at), 'yyyy-MM-dd') }) } } catch (error) { console.log('Webhook failed: ', error.message) } finally { // Remove metadata from subscription await stripe.subscriptions.update(id, { metadata: '' }, stripeAccId) } break }

#

Where I try to remove the metadata from the subscription object after doing the code inside the try statement...

#

But the metadata is not being deleted

#

However for the invoice.payment_failed, it works just fine:

case 'invoice.payment_failed': { //Payment failed, show payment modal const { extraAnnualReport } = data?.['subscription_details']?.['metadata'] try { // If the payment fails, we need to check if the payment is for extra annual report by checking subscription metadata // If it is, it means the users was trying to generate a new report, but the payment failed -> Don't block the access // If it fails for other reasons, block the access if (!extraAnnualReport) { await updateOrganisationValue(orgId, { subscriptionEndDate: '', paymentMethod: 'Stripe', hasSubscription: false, }) } } catch (error) { console.log('Error Handling Event: ', error.message) } finally { // Remove metadata from subscription if (extraAnnualReport) { await stripe.subscriptions.update(data.subscription, { metadata: '' }, stripeAccId) } } break }

livid vessel
#

what's the ID of a subscription where that happened? did you confirm the code entered the finally block and the API call was made?

strong glacier
#

Yeah because when I run it locally it works

livid vessel
#

did you log the value of id also and make sure it's sensible(you didn't share what data is so I can't tell)

strong glacier
#

This is the id: sub_1NnHQoFaDXm8uB7eDpE3rSBc

livid vessel
#

thanks, will have a look in a bit!

strong glacier
#

data is what it comes from event.data.object

livid vessel
#

unfortunately that Subscription has dozens of updates(https://dashboard.stripe.com/test/logs?object=sub_1NnHQoFaDXm8uB7eDpE3rSBc). So can you help me out and share the request ID of the exact request that unset the metadata https://support.stripe.com/questions/finding-the-id-for-an-api-request ? or the event ID or timestamp of when it would have been?

strong glacier
#

Sure!

livid vessel
#

also

strong glacier
#

this is the event id: evt_1NppxKFaDXm8uB7eZeYPSDmN

livid vessel
#

so seems quite possible the deletion worked fine, and then later you update the subscription again and set the metadada back on.

strong glacier
#

Strange

#

I'll try to remove that on another event

livid vessel
#

doens't seem strange, and yes I confirmed that is what happened

#

req_aZ5ltSSdHPiD4c deletes the metadata and req_aZ5ltSSdHPiD4ca adds it back

strong glacier
#

Whats this event? req_aZ5ltSSdHPiD4c

#

whats the event it triggers?

#

So when I call this api await stripe.subscriptions.update(data.subscription, { metadata: '' }, stripeAccId) ths triggers the customer.subscription.update?

livid vessel
#

req_xx is a request ID

#

when you call the API like with stripe.subscriptions.update, that generates a log, with a request ID req_xxx. I'm sharing them as you can look them up in the dashboard to see what API calls you're making.

livid vessel
#

you changed the subscription, so that will also generate a customer.subscription.updated event.

strong glacier
#

what is this request? req_aZ5ltSSdHPiD4ca

#

How can I search by request on stripe dev console?

livid vessel
strong glacier
#

Cool! Thanks