#saarthi_90619

1 messages ยท Page 1 of 1 (latest)

vast summitBOT
delicate pike
#

Hi there!

#

I'm not sure I understand. You want to know when a Subscription changes from a free trial to an active subscription?

uncut wren
#

yes

delicate pike
#

In the webhook payload you should be able to view the previous_attributes. So check if the status changed from trialing to active.

uncut wren
#

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

delicate pike
#

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?

uncut wren
#

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

vast summitBOT
violet lantern
uncut wren
#

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

sullen sorrel
#

Can you share an example evt_xxx ID of an invoice.payment_succeeded event?

#

i.e. subscription_create for the trial invoice

#

You can probably use that field to perform conditional logic

uncut wren
#

when the subscription move from trail to active , billing reason is subscription cycle

violet lantern
#

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.

uncut wren
#

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 ?

violet lantern
#

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

uncut wren
#

but for every payment stripe sends invoice.payment_succeeded webhook , my logic will somewhere fail in the future

violet lantern
#

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

uncut wren
#

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

violet lantern
#

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.

uncut wren
#

i am getting really confused what is the best approach to handle recurring payments conditions in the database

hushed warren
#

๐Ÿ‘‹ taking over for my colleague. Let me catch up.

uncut wren
#

how to handle recurring payments through which webhook should i handle it

hushed warren
#

I think invoice.paid is the place to start

uncut wren
#

if the recurring period is 1 day then how should i handle this

#

at daily basis

hushed warren
#

is this just for testing?

uncut wren
#

yes

hushed warren
#

you shouldn't be doing this to test your code

#

instead you should use test clocks

uncut wren
#

ok

#

where should i pass the test clock parameter

hushed warren
#

on the customer object

#

but you need to create a new one

uncut wren
#

create a new subscription or the user ?

hushed warren
#

you should start with creating a new customer

#

and then create a new subscription for that customer