#glenb.
1 messages · Page 1 of 1 (latest)
Hello! Basically you can't, the metadata on the Invoice isn't editable prior to that Event being created in the scenario you describe. What you can do is set metadata on the Subscription, then retrieve the Subscription when you receive that Event. The Invoice will have the Subscription's ID in the subscription property.
Thanks, but that won't be reliable if I have more than 1 client causing an update on the subscription in a close timeframe as the metadata on the subscription will only show the latest change?
You could add unique keys for each change.
And clean them up/move them to the Invoice after you receive each Event.
Ok, I'm trying to get my head around this. So, I could add a metadata key to the subscription as I do the update, identifying the product being added with a value of 'Add'. Then when I handle the Event, I would remove the metadata key from the Subscription (or mark it as 'Added') once it has been handled on my end?
Yep.
If you wanted to avoid any potential conflicts you could make the metadata key a GUID and put all the details in the value.
Or make the key unique such that it couldn't overlap with another similar operation.
If the product being added is sufficient to avoid such conflicts that could work.
Ok, thanks. Is there a limit on the amount of metadata entries? I think I recall reading 50?
Yeah, it's 50: https://stripe.com/docs/api/metadata
No worries, will try it out - thanks mate.
I also want to mention that customer.subscription.updated Events contain a previous_attributes property that will tell you what changed: https://stripe.com/docs/api/events/object#event_object-data-previous_attributes