#ahjaydog-subsription
1 messages · Page 1 of 1 (latest)
hi
We have an event 3 days prior to trial end, but you want one exactly at the timimg?
yes
then customer.subscription.updated
Occurs whenever a subscription changes (e.g., switching from one plan to another, or changing the status from trial to active).
i am trying to combine this with pauses to do something
i noticed that when i end a trial #subscription unpaused code runs too
so i need to be careful
When pausing do you rely on the same event?
The event content would be different
like, checking trial_end and check if it is the same with timestamp of the event, meaning it's an update from trial -> active
ah that is a good idea
hmm well trial_end becomes null though when it ends
idk if that would work if there are webhook event run time delays though
fmfm
what does that mean?
sorry, meant I am thinking of a solution
ok no problem
how about current_period_start and current_period_end? Are they having same value?
under previous attributes? Do you want me to look when a trial starts or ends?
Under the main Subscription object when you received customer.subscription.updated on a trial end
"previous_attributes": {
"current_period_end": 1655949078,
"current_period_start": 1655862678,
"latest_invoice": "in_1LDImWIeTJrsS1re1g0PtdpA"
Let me take a look
ok
I like this site for the dates btw https://www.epochconverter.com/
I'll put it in trial and send you the previous attributes then end the trial and send you the previous attributes
Trial start:
"previous_attributes": {
"billing_cycle_anchor": 1684088100,
"current_period_end": 1686766500,
"current_period_start": 1684088100,
"latest_invoice": "in_1LDf0OIeTJrsS1re35ZUwwCt",
"status": "active",
"trial_end": 1684088100
}
"created": 1655950570,
With test clocks should i advance by a couple days or the exact time it should end?
I did trial of 1 day
exact time it should end
Do you have the event id of the customer.subscription.updated on trial ending timing?
like evt_xxx
Ok i'll get to that
"id": "evt_1LDfaZIeTJrsS1reXNZWKrdr",
That is the trial start one
Wait a sec
Which trial_end do I use? I see 2
"trial_end": 1684260900,
"trial_end": 1684088100
sub_1LDXIQIeTJrsS1rewnqKWRzp correct?
yup
I am guessing not the previous attribute one?
Use the one under object?
brb
back
ok i advanced it
"status": "active",
"test_clock": "clock_1LDBVDIeTJrsS1reb6rGUnvS",
"transfer_data": null,
"trial_end": 1684260900,
"trial_start": 1683828900
},
"previous_attributes": {
"current_period_end": 1684260900,
"current_period_start": 1684174500,
"latest_invoice": "in_1LDfaYIeTJrsS1rebo1nFhMc",
"status": "trialing"
}
hmm maybe i was wrong about it being null
unless it is because before i advanced way too far
the problem is webhook delays
if it does not execute at the exact same time it could be a problem
"created": 1655951277,
Even the event created is different even when i advanced the time to the exact same time as trial end
oh but wait there are 2 createds
"created": 1683828900,
The matching created is inside the event.data.object
The non matching created is in event
What do you think I should do? Your logic may work but only if there aren't webhook delays
I think the trial_end matching or current should work. Can I see the event id for trial_end again? Is it evt_1LDfaZIeTJrsS1reXNZWKrdr?
evt_1LDflxIeTJrsS1reOhvCskYI - trial ended
maybe checking if trial_end equal to current_period_start?
evt_1LDfaZIeTJrsS1reXNZWKrdr is when i created the trial
ok looking at evt_1LDflxIeTJrsS1reOhvCskYI
trial_end = current_period_start
that means the trial just ended before this period = the Sub just changed from trial to active
event.data.object.current_period_start = event.data.object.trial_end ?
It makes sense I just want to be sure I got the right ones since there are multiple
There is not typically a problem with webhook delays generally?
You are certain webhooks always executes at the exact same time the event occurs??
event.data.object.current_period_start = event.data.object.trial_end yes
and this will be true even if the event is delayed
like, the event itself could be late by few mins, but its recorded current_period_start and trial_end should be the exact timing for the Subscription
ok good
thank you. I am wondering how to prevent elif event.data.object.pause_collection == None from running all the time?
I don't follow that pause_collection part. What is the issue exactly?
when i 'pause payment collection' for a subscription i want to separate that from trials
So i determined if a pause has anything inside event.data.object.pause_collection either null/not null
but the problem is trials have null all the time
for pause_collection
unless i structure the if statements differently and use ifs and elifs in their appropriate places
Or come up with another AND condition in the if statements
I would like some advice/guidance on that because I am not sure
unless i use the active status for pauses?
elif event.data.object.pause_collection == None and event.data.object.status == 'active' ?
ah but that runs when the trial ends
it works for trial start though
I doubt the part trials have null all the time. Can you give an example of event id, when you change pause_collection?
evt_1LDgRFIeTJrsS1re230S8ysp - trial end
evt_1LDgQeIeTJrsS1refmagrSFm - trial start
I need like 1 other AND condition for elif event.data.object.pause_collection == None and subscription_status == 'active': to separate it from trial ends
and have it be a true pause payment collection
If you compare status and previos_attributes's status
one is trialing -> active, one is active -> trialing
ahh yes that is it
i will try
if event.data.object.status == event.data.previous_attributes.status ?
hmm so previous_attributes might not have the same things in them all the time
so if i do a few pause collections in a row i don't see status in there
but your current status would be trialing, right
right
For the case trail->active, your current status should always be active
#start trial (active -> trial): current trialing, previous active
#end trial (trial -> active): current active, previous trialing
yep
ok i am trying a few things
I feel like if i pause then trial during the pause it will break things
When i pause only this still runs event.data.object.current_period_start == event.data.object.trial_end
we used that for trials too
status does not exist in previous attributes all the time
When i pause only this still runs event.data.object.current_period_start == event.data.object.trial_end
Because this condition is still true inside the period from when your Sub changed from trial -> active, until the next billing cycle
ok thanks for the help today i'll come back tomorrow
Sure