I need my game server to process some inventory request to remove or add inventory items to players. I also need to ensure no item can be lost or duplicated while doing so, as I'm implementing a trading system.
For removing items, there is no problem: I can call Server/RevokeInventoryItems, and since the items to revoke are identified by their ItemInstanceId, if for some weird reason I happen to call the playfab API twice (because my server failed to get the answer of the first call, or failed to persistent this result for instance), nothing wrong will happen. Previously revoked items will just stay revoked. I have no such luck with adding inventory items with Server/GrantItemsToUser though.
If a call to Server/GrantItemsToUser is made to Playfab's API twice by mistake, the item will be granted twice, effectively duplicating it. I don't have a way to specify a transaction id in the request that will ensure idempotency. My idea to ensure a transaction cannot be played twice by accident would be to input the transaction idin the only field from GrantItemsToUser that's custom, that is the Annotation field. Then I would need a CloudScript that reacts to the request and accept or reject it. Is that possible to do? Or is there a better (and possibly simpler) way to create add or remove item from inventory transactions?
,I need my game server to process some transactions and give or remove items from users accordingly. I need to ensure that a given transaction is not played twice accidentally, because something weird happened and my server could not get Playfab's response, or had a failure when persisting the result of the call to Playfab.
I have no issue with the removing an item part: I can just use Server/RevokeInventoryItems : if for any reason I send the request twice, it will only revoke the item once because it's uniquely identified by the item's ItemInstanceId. I have no such luck with Server/GrantItemsToUser.
Is there a way to ensure I cannot accidentally replay the same transaction? Maybe by filling the Annotation field of Server/GrantItemsToUser and using it to validate in a cloud script the transaction has not been performed already?