#ahjaydog-subsription

1 messages · Page 1 of 1 (latest)

left ether
#

hi

gleaming musk
#

hi

left ether
#

We have an event 3 days prior to trial end, but you want one exactly at the timimg?

gleaming musk
#

yes

left ether
#

then customer.subscription.updated

gleaming musk
#

i did that

left ether
#

Occurs whenever a subscription changes (e.g., switching from one plan to another, or changing the status from trial to active).

gleaming musk
#

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

left ether
#

When pausing do you rely on the same event?

gleaming musk
#

yes

#

i want to separate pause from trial in the same event

left ether
#

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

gleaming musk
#

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

left ether
#

fmfm

gleaming musk
#

what does that mean?

left ether
#

sorry, meant I am thinking of a solution

gleaming musk
#

ok no problem

left ether
#

how about current_period_start and current_period_end? Are they having same value?

gleaming musk
#

under previous attributes? Do you want me to look when a trial starts or ends?

left ether
#

Under the main Subscription object when you received customer.subscription.updated on a trial end

gleaming musk
#

"previous_attributes": {
"current_period_end": 1655949078,
"current_period_start": 1655862678,
"latest_invoice": "in_1LDImWIeTJrsS1re1g0PtdpA"

left ether
#

Let me take a look

gleaming musk
#

ok

#

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

left ether
#

exact time it should end

#

Do you have the event id of the customer.subscription.updated on trial ending timing?

#

like evt_xxx

gleaming musk
#

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

left ether
#

sub_1LDXIQIeTJrsS1rewnqKWRzp correct?

gleaming musk
#

yup

#

I am guessing not the previous attribute one?

#

Use the one under object?

#

brb

left ether
#

yes not the previous one

#

brb

gleaming musk
#

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

left ether
#

I think the trial_end matching or current should work. Can I see the event id for trial_end again? Is it evt_1LDfaZIeTJrsS1reXNZWKrdr?

gleaming musk
#

evt_1LDflxIeTJrsS1reOhvCskYI - trial ended

left ether
#

maybe checking if trial_end equal to current_period_start?

gleaming musk
#

evt_1LDfaZIeTJrsS1reXNZWKrdr is when i created the trial

left ether
#

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

gleaming musk
#

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??

left ether
#

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

gleaming musk
#

ok good

#

thank you. I am wondering how to prevent elif event.data.object.pause_collection == None from running all the time?

left ether
#

I don't follow that pause_collection part. What is the issue exactly?

gleaming musk
#

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

left ether
#

I doubt the part trials have null all the time. Can you give an example of event id, when you change pause_collection?

gleaming musk
#

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

left ether
#

If you compare status and previos_attributes's status

#

one is trialing -> active, one is active -> trialing

gleaming musk
#

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

left ether
#

but your current status would be trialing, right

gleaming musk
#

right

left ether
#

For the case trail->active, your current status should always be active

gleaming musk
#

#start trial (active -> trial): current trialing, previous active
#end trial (trial -> active): current active, previous trialing

left ether
#

yep

gleaming musk
#

ok i am trying a few things

#

I feel like if i pause then trial during the pause it will break things

gleaming musk
#

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

left ether
#

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

gleaming musk
#

ok thanks for the help today i'll come back tomorrow

left ether
#

Sure

gleaming musk
#

it worked if i put in try blocks

#

damn that was hard

#

thank you again