#lkjhgfdsa-subscription

1 messages · Page 1 of 1 (latest)

knotty hare
#

Hi! The invoice.payment_succeeded event will be for the invoice before the changes. So you could compare the values of the invoice lines.data[].quantity and lines.data[].price to the values on the subscription to know what changed.

upbeat elm
#

Heyy. Thanks for the response. Follow up question, how do I find the previous invoice for the subscription?

knotty hare
#

Just to clarify, you don't need the previous invoice. You check the new invoice that you get in the invoice.payment_succeeded, and compare it to the items in the current subscription. And the invoice object should have a subscription property with the subscription ID.
Otherwise you can list all invoices for a subscription using this: https://stripe.com/docs/api/invoices/list

upbeat elm
#

But the invoice was generated by calling stripe.subscriptions.update(id, {...})?

knotty hare
#

Yes, so what's the issue?

upbeat elm
#

When the user upgrade from basic to pro, I need to re-set their credits to the pro level. When the user adds another collaborator, I only update the quantity of the subscription, and I also update our internal credits. How we do the credit update differs if it's a straight upgrade (reset credits) or if it's adding a user (current credits +newuser)?

#

What about this: we set a metadata property "newCreditAllowance" on the subscription update call, which we can calculate internally before hand... instead of us trying to determine after the fact via the event how/what happened to the subscription? That way, when I receive the event of invoice paid, I can then lookup the subscription and do the necessary update to our internal credits

slim beacon
#

that would yes