#saarthi_90619
1 messages ยท Page 1 of 1 (latest)
Hi there!
I'm not sure I understand. You want to know when a Subscription changes from a free trial to an active subscription?
yes
In the webhook payload you should be able to view the previous_attributes. So check if the status changed from trialing to active.
when the subscription become active after the trial , stripe first send the webhook customer.subscription.updated in which it change the status to active after trialing , and then after 1 hour stripe charges the actual subscription fees , and then webhook invoice payment succeeded calls . when the subscription became active after trial , the billing reason comes is subs cycle , also when the recurring payment done
i have handle recurring conditions on my backend side through invoice payment succeeded , stripe throw this webhook in one hour only
my all conditions failing because of this
when the subscription become active after the trial , stripe first send the webhook customer.subscription.updated in which it change the status to active after trialing , and then after 1 hour stripe charges the actual subscription fees , and then webhook invoice payment succeeded calls .
Yes, all of this is correct
But I'm not sure to understand what is the issue?
i am handling the recurring condition through webhhok invoice.payment succeeded , i have created the condition when the billing reason is subscription cycle i am considering that this webhook stripe will through when the time of recurring period comes let suppose after 1 month ,, but the problem is this webhook is coming just after 1 hour when actual subscription payment has been taken
on trial i am giving 15 credits
on active i am deleting all the trial , and giving 50 credits
when trial ends , subscription changes - invoice payment webhook hits (billing reason = subsc cycle)
when recuring hit - i want to transfer 50 credits more
but the invoice payment succed webhook hits just after 1 hour points become 150 instead of 100
what should i do any answers
waiting 1 hour is normal documented behaviour for how subscriptions work in Stripe : https://stripe.com/docs/billing/invoices/subscription#subscription-renewal , so I'd design your system to work with that model
step 1 --> in trial - i am giving 15 credits to the user
step 2 ---> when trial ends - actual subscription start - i am transfering 50 credits - stripe changes the status to active
step 3 --> stripe charges the actual amount from customer , creating and succedding invoice after 1 hour
step 4 - subscription have a recur period of 1 day , after 1 day recur payment happens , stripe send invoice payment succeded webhook , through i which i am transferring 50 credit to the user again because his subscription get renew
problem happening is - when subscription became active after trial , stripe sending the webhhok invoice payment succeded , the code which supposed to be run after 1 day when recur happens , running in just 1 hour ... how can i get to know webhook is coming of trial to active or the recur webhhook
my credit become 150 because invoice webhook hit twice
@violet lantern u there
Can you share an example evt_xxx ID of an invoice.payment_succeeded event?
I would expect that the billing_reason will be different on the Invoice object: https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i.e. subscription_create for the trial invoice
You can probably use that field to perform conditional logic
when the subscription move from trail to active , billing reason is subscription cycle
Baically your question is how to identify that an Invoice is the Invoice that happeed at the end of a trial. A simple check might be that when you get the invoice.payment_succeded event, you can count how many Invoices that Subscription has had so far. (via https://stripe.com/docs/api/invoices/list#list_invoices-subscription )
if it's 2, then this is the second invoice, so it's the one at the end of the trial, and you can treat it differently.
from the customer.subsc.updated webhook i have saved the latest invoice id in my db , latest invoice id is the upcoming invoice id , so whever the invoice comes , i check whether this is the latest invoice or not , if not means this is the recurring one
is this approach is correct ?
technically that can work yes. When the trial ends there is a customer.subscription.updated event, and in that the latest_invoice is the new Invoice created and that will be charged in an hour
so saving that ID and looking for it later also works; I suggested my approach just because it wouldn't involve storing state/database records, but both work
but for every payment stripe sends invoice.payment_succeeded webhook , my logic will somewhere fail in the future
I'm not sure what I can say to that. But yes, we do send that event for each recurring payment on the subscription, that's the system your code has to work with
what is best approach and webhook to handle recurring payments ?
and when the subscription changes from trial to active , why the stripe changes the billing reason from subscription create to subcription cycle
what is best approach and webhook to handle recurring payments ?
https://stripe.com/docs/billing/subscriptions/webhooks covers this in detail
and when the subscription changes from trial to active , why the stripe changes the billing reason from subscription create to subcription cycle
because that's correct. At the start of the trial when the subscription is created, there is a $0 invoice, and that has billing_reason:subscription_create. At the end of the trial when the billing period cycles to the next one, there is a $x invoice for the next period, and that has billing_reason:subscription_cycle.
i am getting really confused what is the best approach to handle recurring payments conditions in the database
๐ taking over for my colleague. Let me catch up.
how to handle recurring payments through which webhook should i handle it
I think invoice.paid is the place to start
is this just for testing?
yes
you shouldn't be doing this to test your code
instead you should use test clocks
create a new subscription or the user ?