Skip to main content
Version: 5.18.17

In-app payments and receipt verifications

In-app payments are configured to only work in the Unity Editor by default.

An in-app payment logic has been implemented in the example project. However, it is only set to run on the Unity editor to prevent in-app payment through an actual BACKND account on an Android environment.

To test payments in an Android environment, register the app under your personal developer account and complete the in-app payment configurations.

Refer to Google Play Store on how to proceed with in-app payments and receipt verifications.

Note: You can check that the in-app payments and receipt verifications have been implemented by opening the relevant files and reviewing the code in the project.

 - CodeIAPManager.cs
- ShopManager.cs
- BackndPurchasing.cs
ProcessPurchase() //Receipt verification logic

The shop UI is configured to be disabled by default in the Android environment to prevent any unintended payments by users.

Open the ShopManager.cs file within the project and modify the SetActiveUI method as follows to properly test in-app payments in an Android environment.

The test can be performed normally in Unity Editor without any modifications.

        private void SetActiveUI(bool state)
{
//Conditional instruction compilation handled as comment
//#if UNITY_EDITOR
_ui.SetActive(state);
//#endif
}

By handling #if UNITY_EDITOR as comment like above, the UI will be displayed normally on Android environment.

Google Play Console settings​

To test in-app payment on an Android environment, the app must be registered on the Google Play Console, followed by in-app product configuration.

Refer to the information below for the product IDs and item names required for testing.

This information can also be found in the Excel file that was downloaded for the chart settings.

image

Product IDProduct name
xxgems_01Single Gem
xxgems_02Handful of Gems
xxgems_03Heap of Gems
xxgems_04Small box of Gems
xxgems_05Medium box of Gems
xxgems_06Trunks of Gems
xxbdl_stlarStarter Pack Large
xxbdl_stmedStarter Pack Medium
xxbdl_stminiStarter Pack Mini
xxbdl_fashmedFashion Pack Medium
xxbdl_fashminiFashion Pack Mini

Excel data file

  • GemsShopData.xlsx
  • BundleShopData.xlsx

Purchase restoration

When you open CodeIAPManager.cs file, it will be implemented in the OnInitialized method part.

The following is the implemented code part for purchase restoration. For more details, check the file.

        if (product.hasReceipt) // purchase restoration
{
if (iapItem.InAppProductType == ProductType.NonConsumable)
iapItem.InAppPurchaseIsOwned = true;

else if (iapItem.InAppProductType == ProductType.Subscription)
iapItem.InAppPurchaseIsOwned =
new SubscriptionManager(product, null).getSubscriptionInfo().isSubscribed() == Result.True;
}