Custom shop checkout flow

Hi,

As I need some algorithm to speficy the shipping, as well as other rules during the checkout. I am making my own cart-checkout flow within the wix-stores-app.

I’ve read posts that some people have done it. The user clicks some products and they are added in my custom checkout cart, then I make the pay-order in the backend. Once the order has been processed I call the createorder()* api and marked it as paid. When the order is marked as paid the inventory is decreased.

Therefore as WiX dosent have locking write-collection mechanisms. How can I avoid a collision of two orders making an out-of-stock in one product when doing my custom cart flow?

[*] https://www.wix.com/corvid/reference/wix-stores-backend/createorder

Thank you.