#idhruv-webhook
1 messages · Page 1 of 1 (latest)
definitely
This is the request Id when webhook is created for the first time after subscription schedule is set:
req_SUrrEybwCjbv1D
and this is the eventId of successful webhook response
evt_1LLCEvGdNldKu1zmgCblLqGe
both calls were returned with 200 (success)
and yet metadata is empty when this response is fetched at endpoint end
you shouldn't add the metadata to the webhook endpoint
not adding it at endpoint but during creation of webhook
const webhookEndpoint = await stripe.webhookEndpoints.create({ url: ${BASE.URL}/api/payment/subscription-paid, enabled_events: [ 'invoice.payment_succeeded', ], metadata: {'bookingId': String(bookingArr[i]?._id)} });
like this
this works totally fine with testing and simulation via stripe cli
the way to go about this is to add the metadata to the subscription object during creation - https://stripe.com/docs/api/subscriptions/create#create_subscription-metadata.
you would also save the subcription id and metadata to your own DB at this point in time
stripe trigger invoice.payment_succeeded --add invoice:metadata.bookingId='1234' okay, then how is running this command via strip CLI is working out? i want to achieve same thing via code
subsequently, for each invoice that is generated in relation to a subscription, it would contain a subscription id [0]. You can then retrieve the metadata for that invoice from your own DB based on the subscription id
[0] https://stripe.com/docs/api/invoices/object#invoice_object-subscription
okay, is there no way i can get metadata directly after setting it up somewhere like subscription?
that CLI command works because it's just generating a one-off invoice
not an invoice related to a subscription
ohh ok
I have a question, if we are anyway using our own DB to retrieve metadata then what is benefit of adding it to subscription object?
EDIT: I am not using simple subscriptions, but subscription-schedule
you would receive it back in every subscription event e.g. customer.subscription.created, customer.subscription.updated, etc
But as a general rule, metadata that is set on an object will not be silently copied over to any associated objects that are created at the same time.
ohh..k
that's why you won't automatically see the metadata on a subscription on it's corresponding invoice
so how about this, I create a metadata on subscription schedule and when webhook calls my endpoint, can i retrieve this data using subscription.updated or similar event
if you're using subscription schedules, then you can probably add it here : https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-phases-metadata
this way i dont have to save it in my db
so how about this, I create a metadata on subscription schedule and when webhook calls my endpoint, can i retrieve this data using subscription.updated or similar event
yes, you can retrieve the subscription : https://stripe.com/docs/api/subscriptions/retrieve
okaay! let me try n see what works n what doesnt. thanks
you would want to test subscriptions using test clocks : https://stripe.com/docs/billing/testing/test-clocks
also, what is difference between metadata inside phases and metadata inside subscription object? i mean how it differs from implementation perspective.
i'm a bit confused and don't quite understand the question. Could you try rephrasing perhaps?
yes
what is the difference between putting metadata inside subscription object vs putting it inside phases, which ultimately is an object inside subscription?
if you use that parameter to set the metadata, as the description in the doc mentions :
Metadata on a schedule’s phase will update the underlying subscription’s metadata when the phase is entered, adding new keys and replacing existing keys in the subscription’s metadata
ok
I think i will stick to subscription's metadata coz i dont want to replace anything here
i personally think you should set the metadata on https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-phases-metadata, since that'll mean that Stripe will automatically create the subscriptions for each phase with that metadata
but if you want to implement the logic to do it on each subscription that's fine as well
hello, how to add metadata to testing clock's customer subscription?
Can you share the request id where you've created the customer subscription with a test clock?