#gracine

1 messages · Page 1 of 1 (latest)

summer stumpBOT
stark bloom
#

Can you say more about what is giving you trouble? WHat is not doing what you expect?

buoyant escarp
#

ok

#

Yes for the first time this morning I had unordered events after completed a checkout

#

I always sync my subscription in my db based on webhook events

#

and I received subscription status 'active', and then subscription status 'incomplete'

#

so I end up as 'incomplete' in my db, where in stripe the status is active

#

I did not code anything to prevent unordered events

#

I though of status transition validation

#

I want to know what is the best pratice

#

This is what I have so far

#

def can_transition_to(new_status:)

case status
  when Status::ACTIVE
    return [Status::ACTIVE, Status::PAST_DUE, Status::CANCELED, Status::UNPAID].include?(new_status)
  else
    true
end

end

stark bloom
#

Do you need all of those events?

buoyant escarp
#

meaning I cannot go back from active to incomplete or incomplete_expired

stark bloom
#

If you only need certain events, you can turn others off for your endpoint

buoyant escarp
#

is need to know all the subscription statuses

stark bloom
#

If you need all events and they come in close succession, possibly out of order, then what we recommend is using them as a signal to retrieve the object (subscription, in this case) from the API to get the latest version of the object

buoyant escarp
#

ah ok

stark bloom
#

right so then for any subscription event, just retrieve the subscription and get the latest status

buoyant escarp
#

that would work indeed

#

I though it was a bad pratice for rate limiting

#

its easier though

#

I was wondering if there is a case where we can transition from an active status to incomplete

stark bloom
#

No, incomplete only happens to new subscriptions, that sounds like an out-of-order sequence indeed

buoyant escarp
#

so my logic would be valid

#

i was just wondering if it make sense or I am missing other transition cases

#

for sure your re-fetch sub object would work