#gracine
1 messages · Page 1 of 1 (latest)
Can you say more about what is giving you trouble? WHat is not doing what you expect?
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
Do you need all of those events?
meaning I cannot go back from active to incomplete or incomplete_expired
If you only need certain events, you can turn others off for your endpoint
is need to know all the subscription statuses
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
ah ok
right so then for any subscription event, just retrieve the subscription and get the latest status
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
No, incomplete only happens to new subscriptions, that sounds like an out-of-order sequence indeed