#meek-subscription-credit
1 messages · Page 1 of 1 (latest)
A couple of ways to do that
But I would listen to the customer.subscription.updated event: https://stripe.com/docs/billing/subscriptions/webhooks
Recommend reading that article too in case any other parts are of use. It does a solid job of outlining how to combine webhooks with subscriptions
Does this run only on successful payments?
It will help you identify when a subscription is upgraded or downgraded
So you can mark in your database that the sub was upgraded/downgraded at that moment
What's your end goal though? What are you trying to do?
I want to update users credits in the database.
EX. They have a plan that is $20 for 50 credits per month
So once they sign up for a paid plan, they get ex. 50 credits
Each month, they also get 50 credits
They can upgrade or downgrade plan to get more or less credits and they should only receive the new credits if its an upgrade
I am having a hard time understanding which webhooks to listen to for all these different stages
I am trying to impliment pricing similar to https://www.remove.bg/pricing
Ok that makes sense. One sec
Thanks!
There's several ways to do this. One way is to just listen to invoice.paid and inspect the price (price_123) used.
You'd also be keeping track of the customer's pricing tier in your database
So if you detect that the price they're paying now is different, update the pricing tier in your database
But also customer.subscription.updated works as you can inspect previous attributes on the subscription (in the event object: https://stripe.com/docs/api/events/object#event_object-data-previous_attributes) and see if the price changed
Hmm interesting, looking at the previous attributes now. Brb
So do you think this is a good way to go about this?
- Give 50 credits once they sign up for a 50 credits monthly paid plan -> add credits on customer.subscription.created webhook
- Each month, give 50 credits -> add credits on invoice.paid webhook
- Add credits on upgrade -> add credits on customer.subscription.updated webhook but only when the credits on previous_attributes is less
The issue i see with my solution is that invoice.paid on step 2 will get called for step 1 and 3
Ok that gives a bit more detail into how things work thanks
When you upgrade the subscriptions, how do you handle prorations?
(trying to get a little more info so I can provide the best rec)
So if the user upgrades, ex. if the new plan is $40 for 100 credits a month, then it will just add 100 to the current balance of credits and then continue charging them $40 a month
What do you pass for proration_behavior? https://stripe.com/docs/api/subscriptions/update#update_subscription-proration_behavior
meek-subscription-credit
Currently I have nothing so i guess it is using the default create_prorations not too sure if thats the best option but that's what currently there
that's the default yes.
I think what's important is to be explicit about what you want your customer to pay when.
I am using this repo which uses stripe checkout. https://github.com/vercel/nextjs-subscription-payments so everything I am doing is basically derived from here
When they upgrade, whether they pay the full price or the difference, it doesnt really matter to me at the moment
I just want to give them the appropriate credits
Sorry that's not really what I'm asking. I'm asking you to write down clearly when you expect the customer to pay what/how much
Like April 1st pays $10 for 50 credit, May 1st pays $10 for 50 credit, May 15 switches to $40 plan for 100 credits <insert what you expect>
Ahhh I see....
April 1st pays $10 for 50 credit, May 1st pays $10 for 50 credit, May 15 switches to $40 plan for 100 credits -> Client gets charged $40 and they get 100 credits added to their account. June 15 pays $40 for 100 credits...
ect...
ohhhh you change the billing cycle on May 15, that's important!!! What about the $10 they paid for a month but mid month you chnaged the rule? Is it fine because they got the credits anyways?
Yes exactly
okay so really what you need to do is update the Subscription to switch to the $40 price and pass billing_cycle_anchor: 'now' so that the new cycle is May 15 - June 15 and pass proration_behavior: 'none' because you don't want any credit for the previous $10
and then in the webhook you notice it's a new Invoice and you add 100 credit to your tracking
Hmmm, few questions, I am using stripe checkout so will this work with that?
And Also could you do something like i did here #1083862390019473531 message outlining the steps so I can better understand what you mentioned above? Thank you and sorry for taking up so much time
Checkout is not relevant, you're talking about updating an existing Subscription which Checkout can never do