Virtual Store #

Listing store items #

You can list available store items.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
foreach (var storeItem in economySystem.StoreItems)
{
    Debug.Log($"{storeItem.Name} - {storeItem.Description}). Cost: ");

    if (!string.IsNullOrEmpty(storeItem.Cost.Sku))
    {
        Debug.Log($"{storeItem.Cost.Sku}");
    }
    else
    {
        foreach (var currencyKvp in storeItem.Cost.Currencies)
        {
            Debug.Log($"{currencyKvp.Key}: {currencyKvp.Value}");
        }
    }
}

Refreshing the store #

You can refresh the economy system’s store data.

1
await economySystem.RefreshStoreAsync();

Making a purchase intent #

You can make a purchase intent for a user, which is useful to differentiate product purchases that use the same SKU code.

1
await economySystem.PurchaseIntentAsync(storeItem);

Alternatively you can specify a store item id and SKU code.

1
await economySystem.PurchaseIntentAsync("<itemId1>", "<sku>");

Purchasing a store item #

You can purchase a store item for a user.

1
await economySystem.PurchaseStoreItemAsync("<itemId1>", "<receipt>");

Getting the active store type #

You can get the active store type.

1
Debug.Log($"Active store type is {economySystem.ActiveStoreType}");

Soft/Hard Currency Purchase #

This example shows how you could trigger a purchase with either “Soft” or “Hard” currency, based on the configuration of the store item.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public async Task BuyStoreItem(EconomyListStoreItem storeItem)
{
    if (string.IsNullOrEmpty(storeItem.Cost.Sku))
    {
        IEconomyPurchaseAck result = await _economySystem.PurchaseStoreItemAsync(storeItem.Id);

        // Show reward animation UI.
        ShowRewardAnimationUI(result.Reward); // Your custom function.
    }
    else 
    {
        try
        {
            var result = await _unityPurchasingSystem.BuyProductByIdAsync(storeItem.Id);
            AnalyticsSendReceipt(result.receipt); // Your custom function.

            // Show reward animation UI.
            ShowRewardAnimationUI(storeItem.Reward); // Your custom function.
        }
        catch (PurchaseFailureException e)
        {
            switch (e.Reason)
            {
                case UnityEngine.Purchasing.PurchaseFailureReason.UserCancelled:
                    // Popup some UI.
                    break;
                case UnityEngine.Purchasing.PurchaseFailureReason.PaymentDeclined:
                    // Popup some UI.
                    break;
                case UnityEngine.Purchasing.PurchaseFailureReason.ExistingPurchasePending:
                    // Popup some UI.
                    break;
                case UnityEngine.Purchasing.PurchaseFailureReason.PurchasingUnavailable:
                case UnityEngine.Purchasing.PurchaseFailureReason.ProductUnavailable:
                case UnityEngine.Purchasing.PurchaseFailureReason.SignatureInvalid:
                case UnityEngine.Purchasing.PurchaseFailureReason.DuplicateTransaction:
                case UnityEngine.Purchasing.PurchaseFailureReason.Unknown:
                    break;
            }
        }
    }
}