Connecting to The Service

Once all the setup action is complete, you can try to connect to the payment service and get list of the all products that are available for your app.

Define your In-App products

Make sure you've list products for each platform you are going to use. That should be done using the plugin editor menu. You read more detailed guides for iOS and Android.

The products you define inside platform settings UI will be available in the runtime, even before you've connected to the payment service. Se the code sample how to print product's list. The code sample below demonstrates how to print all product's list.

using SA.CrossPlatform.GameServices;

foreach(UM_iProduct product in UM_InAppService.Client.Products) {
    Debug.Log("product.Id: " + product.Id);
    Debug.Log("product.Price: " + product.Price);
    Debug.Log("product.PriceInMicros: " + product.PriceInMicros);
    Debug.Log("product.Title: " + product.Title);
    Debug.Log("product.Description: " + product.Description);
    Debug.Log("product.PriceCurrencyCode: " + product.PriceCurrencyCode);
    Debug.Log("product.Icon: " + product.Icon);
    Debug.Log("product.Type: " + product.Type);
    Debug.Log("product.IsActive: " + product.IsActive);

There are a few properties I want to talk about a bit more.

  • Icon - The Icon will never come from the payment server. This is always the icon you have specified inside the editor settings.
  • IsActive - Once products are loaded from the server, products info is updated, and IsActive property is set to true. Otherwise, it's false.

Connecting to Payment Server

Before you can start any purchase flow, you need to connect to the Payment server. See the sample below:

 using SA.CrossPlatform.InApp;
 UM_InAppService.Client.Connect((connectionResult) => {
            if(connectionResult.IsSucceeded) {
        //You are now connected to the payment service.
        //Also all product's info are updated at this point from according to server values.
    } else {
        //Connection failed.
        Debug.Log("Connection failed: " + connectionResult.Error.FullMessage);

Frequently asked questions

How to set up app state based on purchases non-consumable products?

This is can be a little bit confusing, let's assume you have a resing game where a player can purchase an additional track, and once a track is purchased you want to have it's unlocked for a player all time.

The approach you should use 

  • Success Transaction complete event received (user just made a payment)
  • Validate the Transaction (in case you have implemented  server-side API, client-side validation already had been performed by a plugin)
  • Unlock item for a user and save that state. This is up to you how you will save unlocked item state since this is what you will rely on when you need to decide of an item is unlocked or not for your user. You can save item state using unity PlayerPrefs or save using a remote database, or in any other way that fits your application.

Why Ultimate Mobile UM_iProduct object does not have IsPurchased flag?

It's not because I want you to make part of the job, there are actually several reasons for that.

  1. We would only be able to get the state after connection to the Payment server, and in case connection to Payment server is failed, you probably still want your application to have a correct state based on user purchases.
  2. On iOS there is no way to retrieve user purchases slightly, which means in order to have  IsPurchased flag we would need to cache purchases. The only way to do it is to use unity PlayerPrefs . But that isn't safe, because I don't know if you will use PlayerPrefs.DeleteAll method in your application, and in this case, it will destroy local purchases cache and will cause a bug. 
  3. Even assuming you aren't using PlayerPrefs.DeleteAll method, in case of a user just launched your application on another device, we would not have purchased states local cache, and you would not able to set up purchased items states correctly. That's why in case you have non-consumable item's you should always provide Restore option for a player. Also, note that running the Restore purchase flow on the iOS device will lock your game and will ask a user for an AppStore password in order to start the restore flow. On Android, however, the restored flow will go silently.