Myket KB for Developers

View Categories

Unity With Gradle

Setup

To set up Myket in-app billing, open the project files using a version of Unity that has “build automation support with Gradle“. Make sure your Unity environment is configured to use Gradle as the build system, which will simplify automation and management of dependencies. Follow the setup instructions provided by Myket to ensure all components are correctly installed and configured for a seamless billing experience.

Function Descriptions

In this section, we will go over each main function provided by the Myket in-app billing library, which you can call in your Unity project. These functions are designed to handle various stages of the in-app purchase process, from initialization and logging to querying available products and completing purchases.

Functions in the MyketIAB Class

The MyketIAB class contains all the primary functions for integrating Myket’s in-app billing. You will use these functions to interact with Myket’s billing service, enabling your application to offer products for purchase within the app. Here is a breakdown of each function.

public static void init(string publicKey)

Before attempting to use any functions in this library, you must call this function once. The input for this function is your app’s public key, which you need to obtain from the Myket developer panel. If successful, the ” billingSupportedEvent” will be called, and if unsuccessful, the “billingNotSupportedEvent” will be called. Note that after calling the “init” function, your app will attempt to connect to the Myket in-app payment service, so the latest version of Myket must be installed on the device you are testing.

public static void enableLogging(bool shouldEnable)

This function enables logging for the helper files. Make sure that the value of “shouldEnable ” is set to False in Release mode.

public static void unbindService()

Call this function when you have finished working with the payment service.

public static void queryInventory(string[] skus)

Use this function to retrieve details of the products listed in your Myket in-app billing dashboard. It returns information about prices, titles and etc. This function also returns a list of all purchased products that have not yet been consumed (products within the inventory). This function takes a list of your product IDs as input.

public static void querySkuDetails(string[] skus)

Use this function to retrieve information about the products defined in the in-app payment panel, such as price, title, etc.

public static void purchaseProduct(string sku)public static void purchaseProduct(string sku, string developerPayload)

To initiate the purchase process for a product with the specified SKU, use this function. After attempting to purchase, two events may be called: “purchaseSucceededEvent”, which is called in the following cases:

  1.  When the purchase is successful.
  2. When you try to repurchase a product that you previously bought but haven’t consumed.

 

The other event, “purchaseFailedEvent”, is called if the purchase is unsuccessful.
Purchases are added to the inventory. If the product is consumable, you should use the “consumeProduct” function to consume it after the purchase process is successfully completed.

public static void consumeProduct(string sku)
public static void consumeProducts(string[] skus)

Use this function to consume a purchased product. Once the consumption process is successfully completed, the product will be removed from the inventory, and you will be allowed to purchase the same product again.

Event Descriptions

Events are accessible through the “MyketIABEventManager” class.

public static event Action billingSupportedEvent;

It is called when in-app payments are supported on the device.

public static event Action<string> billingNotSupportedEvent;

After calling the “init” function, if in-app purchases are not possible, this event will be called.

public static event Action<List<MyketPurchase>, List<MyketSkuInfo>> queryInventorySucceededEvent;

This event is triggered if the “queryInventory” function call is successful.

public static event Action<string> queryInventoryFailedEvent;

It is called when the attempt to retrieve product and purchase information fails.

public static event Action<MyketPurchase> purchaseSucceededEvent;

It is called when the purchase is successful.

public static event Action<string> purchaseFailedEvent;

It is called when the purchase is not successful.

public static event Action<MyketPurchase> consumePurchaseSucceededEvent;

It is called if the attempt to consume a purchased product is successful.

public static event Action<string> consumePurchaseFailedEvent;

It is called if the attempt to consume a purchased product fails.