I am implementing in app purchases for a few consumables products called GEMS. My app has its own server which keeps tracks of user information, including the gem count.
I am concerned about the following situation:
User A logs in the app and purchases a few gems. The app sends a transaction to the App Store. App receives transaction state as 'Purchased'. The app sends a request to server to update the gem count in the DB. At this point the server call fails and the User A will not be awarded any gems and hence the transaction could not be set as 'completed'.
At this point User A logs out and User B logs in. Since the previous transaction was not completed, the app, when relaunched, will receive this transaction and will again try to send a request to the server to award the user the purchased gems. But now the gems will be incorrectly awarded to the user B instead of A via my server call.
Now, how can I differentiate the said transaction to be of user A instead of B?
Will I have to handle this locally on the app side; ie storing a unique transaction identifier against the user id? In that case how will I differentiate a previous pending transaction vs a new transaction.
Is server side receipt validation a solution? Even so, the receipt will not contain custom information regarding the actual user app account which made the request.