Hey. I am trying to create a gift system. Player is supposed to pick a player and then do the purchase. This is no problem.
What I am thinking of is edge cases. If the player that is supposed to receive the gift leaves, it basically won’t be able to award that player. In that case I either need to save the purchase to handle it later or find a way to refund it. I want to refund but I know NotProcessedYet enum won’t do it. What is the best way to handle this problem?
As others have already mentioned, directly updating the target’s data store would be the best approach here. You can use functions like Players.GetUserIdFromNameAsync to retrieve the target’s UserId, which you should be using as, or as a part of, data store keys. Bare in mind functions like this one, and the data store operations, are asynchronous network requests and can fail. On the small, but still existent chance that they do, you could give the gifted item to the player who purchased it, but as a regiftable item which they can then manually gift to whoever they wanted to gift to in the first place. This would be better as a last resort than just exiting the ProcessReceipt function, which will still take the player’s robux but give them nothing.
Alright then, I’ll explore those options.
Though, another edge case would be with games that uses ProfileService, which is mine too. Player being too slow to do a purchase but the player getting the gift rejoining to another server before the purchase happens would cause player’s datastore to be locked as far as I know. Yet it being re-giftable would handle the problem, if everything else fails.