#m4rt1ns_1993
1 messages · Page 1 of 1 (latest)
hi! sure, you can call the API or do any action you choose when handling the webhook.
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 }
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?
Yeah because when I run it locally it works
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)
This is the id: sub_1NnHQoFaDXm8uB7eDpE3rSBc
thanks, will have a look in a bit!
data is what it comes from event.data.object
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?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
Sure!
also
if you look at https://dashboard.stripe.com/test/logs?object=sub_1NnHQoFaDXm8uB7eDpE3rSBc you'll see most requests are setting metadata
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
this is the event id: evt_1NppxKFaDXm8uB7eZeYPSDmN
so seems quite possible the deletion worked fine, and then later you update the subscription again and set the metadada back on.
doens't seem strange, and yes I confirmed that is what happened
req_aZ5ltSSdHPiD4c deletes the metadata and req_aZ5ltSSdHPiD4ca adds it back
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?
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.
yes, ,also
you changed the subscription, so that will also generate a customer.subscription.updated event.
what is this request? req_aZ5ltSSdHPiD4ca
How can I search by request on stripe dev console?
it's a typo, I meant req_aZ5ltSSdHPiD4c .
Cool! Thanks