Stripe: `onSubscriptionUpdate` passes old subscription data
When the
onSubscriptionUpdate
callback is fired, it passes the subscription
data grabbed from the DB. However, this is the data before the updated properties are applied.
For example, if a user switches from one plan to another, the passed subscription
object contains the old plan, not the new one.
Relevant code:
1. Subscription is fetched from DB: https://github.com/better-auth/better-auth/blob/main/packages/stripe/src/hooks.ts#L100-L125
2. Subscription is updated in DB: https://github.com/better-auth/better-auth/blob/main/packages/stripe/src/hooks.ts#L128-L151
3. Old subscription (from step 1) is passed to callback: https://github.com/better-auth/better-auth/blob/main/packages/stripe/src/hooks.ts#L165-L168
This behavior can be seen by simply logging the subscription object from the callback:
My opinion is that it would be helpful if the callback included both the old subscription and the newly updated one, but I believe it should at last pass the new one.1 Reply
I would open a GH issue for this, but I wanted to first check to ensure this is actually a bug and not expected behavior
Well, the code annotates it as
A callback to run after a user is about to cancel their subscription
https://github.com/better-auth/better-auth/blob/main/packages/stripe/src/types.ts#L239
That makes me think this is expected behavior, but it doesn't seem clear to me in the docs