StansAssets/com.stansassets.android-native

Clarification About Ultimate Mobile Pro Unity

Ardito opened this issue · 2 comments

Premise: In my game you can buy gems with which you can buy other items in the game.

  1. Gems are a consumer product, right?

  2. In your guide: https://unionassets.com/android-native-pro/purchase-flow-675
    You say "After use has successfully purchased the product, it will stay inside the user inventory, until you consume it. Also if the user will not able to purchase the same product before you consume it from the inventory", but I bought more times the same product. Why? https://drive.google.com/file/d/1IforDeQjmEgGXPqKaWCpaYmWeXr3MY3H/view?usp=sharing

  3. It is possible that the client is not able to correctly send the purchase token to my server, to solve this problem what should I do? If I use PlayerPrefs and all PlayerPrefs are deleted in the meantime, how can I recover the user's purchase?

  4. I found this thread on the web: https://stackoverflow.com/questions/56289258/how-does-acknowledgepurchase-really-work-on-android

  • Do I have to confirm user purchases?
  • How can I validate purchases?
  • How can I use the items in the inventory?

Hey, @Ardito sorry for the slow replay on this one.

Gems are a consumer product, right?

Yes, gems should be consumable products.

In your guide: https://unionassets.com/android-native-pro/purchase-flow-675
You say "After use has successfully purchased the product, it will stay inside the user inventory, until you consume it. Also if the user will not able to purchase the same product before you consume it from the inventory", but I bought more times the same product. Why? https://drive.google.com/file/d/1IforDeQjmEgGXPqKaWCpaYmWeXr3MY3H/view?usp=sharing

Let's go to the Ultimate Mobile plugin documentation.
Here is a typical flow for consumable products.

  • Start transaction using UM_InAppService.Client.AddPayment("gems");
  • Use pays for the product
  • Your app getting notification via Transaction observer, so you add gems to the user.
  • User has gems on the balance and you sure that transaction is login
  • You finish the transaction with UM_InAppService.Client.FinishTransaction(transaction);
    After that transaction is finished and users can purchase gems again.

but I bought more times the same product. Why?
Consumable products can be bought as many times as your user wants. The only limitation you can not buy the same consumable product if you haven't finished an active transaction for it.

It is possible that the client is not able to correctly send the purchase token to my server, to solve this problem what should I do? If I use PlayerPrefs and all PlayerPrefs are deleted in the meantime, how can I recover the user's purchase?

On iOS, you can Restore purchases. but that will only restore non-consumable products.
There is a very simple rule. Do not call FinishTransaction until you made all the verification and provided user with items he paid for.
FinishTransaction - tells that you completed the transaction and all is good.
Until you do this, the transaction will "hang". So you can explain user that your server is down or his internet is bad, or any other reason why you can not finish the transaction.

Or you can just give users and items and validate the transaction later without finishing it.

Do I have to confirm user purchases?

That's up to you. There is local receipt validation built-in into the plugin. But only server validation would give you 100% protection from fraud transactions.

How can I validate purchases?

The flow is like this:

  • Plugins tells you that purchases is completed and provides transaction info
  • You send this info to your server
  • Your server uses a server to server request to validate with Google / Apple if that's a legit transaction.
  • Yout server send the callback to your app

How can I use the items in the inventory?
I think this was outdated documentation. There is no inventory anymore. Now plugin API matches and API provided by Apple / Google. And it basically translates to:

  • You start a transaction
  • You monitor transaction update
  • When a purchase is completed, you can add items to the user
  • If that's a permanent item, it is on you to make sure the user will have it on other devices and during app reinstall. But if you fail to do that, and the user will try to buy a non-consumable item he already owns, then you will get an error from Apple / Google that the user already owns that item, so the user won't be charged twice for the same item, and you can restore item for the user.

There are also some features provided by Native API.
On iOS
You have the dedicated Restore Transaction call. It will restore all the transactions made by the user. So you should always have a "Restore purchases" button in your game if you have non-consumable items.

On Android
When you connect to the billing server google provides all the user-owned non-consumable items.
The Ultimate Mobile plugin will check for the local purchase record and if it does not exists, it will send transaction to your observer.
But sometimes those products can come with a delay.

And once you are done processing and validating the transaction you can call FinsihTransaction.

Thanks everything works!