Suppose I want to implement a policy where I do not allow the customer to alter their subscription if they are past due on an invoice. To implement this I can try the following:
1. Pull the data from Chargebee.
2. If the subscription is not past due allow the change, if not, return an error message to the user.
But this has a problem.
There is a window between when we get the data from Chargebee and post the update that the subscription may have changed state to past due. If this happens then it will allow a change on a past due subscription.
This is just one example. Generally speaking, any policy that depends on state on Chargebee side is impossible to implement correctly.
A simple and reasonably effective solution to this problem is to allow passing in a resource_version attribute in an update call. On Chargebee's side you can check the resource_version against what you have stored and apply the change only if they match (This would have to happen inside of a database transaction to ensure full correctness. Incidentally, are changes to the data on Chargebee done in a transnational setting?).
Thoughts from the Chargebee API team?
Thanks for writing to us on this.
We have converted this topic as a ticket. ID: 79777
We will get back to you after discussing with our engineers.