question

Anh Le avatar image
Anh Le asked

Questions about transaction API call

I'd like to ask about the technique to optimize the update for multiple VirtualCurrency, Inventory at the same time; and handle the rollback in case there is any issues happening.

The case is: An user opens a loot box with 10 gem (virtual currency). He gets 100 gold (another virtual currency) and 1 item in the inventory.

The custom server checks the logic and verify the transaction then call 3 API to update:

  • AddUserVirtualCurrency (Add gold)
  • SubtractUserVirtualCurrency (Decrease gem)
  • GrantItemsToUser (Add item)

My questions are:

  • Is there any way to use 1 API to handle all these requests?
  • If there is any issue when calling these API, is there any way to rollback the process (ex: revoke the item, add back gem and reduce gold)?
apisCustom Game ServersPlayer Inventory
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
pfnathan avatar image
pfnathan answered

1). Only way you could do is using a cloud script. Cloud script can make multiple calls and then return all of the results together.

2). If the issue is in user state like; they have 50 gold in their inventory then they are granted with 100gold and GetVC call indicates they have 151 gold now then what you can do is manually call subtract on 100 gold they were granted and that would "roll back"

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

@Le Giang Anh Why not just have all the items in the Container? Then, you only have to make one call to UnlockContainer, and all VCs and items will be added to the player account.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.