#eleanor

1 messages · Page 1 of 1 (latest)

slow hingeBOT
tired dust
#

Hey there

#

Hmm let's back up a second

#

So your actual question here is: "how do I distinguish what plan a customer changed to on an upgrade/downgrade"?

brazen sparrow
#

I guess it's two questions — the first is making sure I understand when we'll receive the type invoiceitem (which I think is just when proration happens?)

tired dust
#

Yes that's correct

brazen sparrow
#

And then if I am right in my understanding of that, the follow-up question is distinguishing plans; I'm a little worried to do it based on the description since it's described as an "arbitrary string" in the docs so wanted to confirm

#

ok awesome!! that's great

tired dust
#

Or if you add your own invoice item

#

That wasn't generated by the Subscription's regular renewal

#

Yes definitely would not use the description to determine plans

#

You want to use the customer.subscription.updated webhook in this case.

#

Which will contain previous_attributes

#

And you can easily compare the plan that is now on the Sub versus what it was before

brazen sparrow
#

Ah, nice — yes, that's a much better way of doing things!! Woo!! 🥳

#

Thanks so much, this is super useful (scrambling to release new billing haha so I really appreciate the fast response)

tired dust
#

Happy to help!

brazen sparrow
#

One more question here, sorry — will the customer.subscription.updated hook be fired only if billing actually succeeds? We don't want to give people access to features on plan B unless their payment works

tired dust
#

Nope

#

It fires every time anything on the Subscription object changes

#

So every time a new billing period is reached it will fire

#

Regardless of whether their payment is successful or not

#

Then you can check the status of the Subscription to determine whether payment was successful

#

Or you can listen for the invoice.payment* event

brazen sparrow
#

and yeah, we want the niceness of checking for previous plan vs current plan that the customer.subscription.updated hook would give us (I think, based on your earlier message), thus the preference to handle fulfillment for prorations there

tired dust
#

Yep

#

If status is active then you know the payment succeeded

#

If past_due then it would have failed