Release Notes: (1.2.5)
  • Updated to ChinaMobile MM IAP SDK 3.1.7.

Integration Guide - ChinaMobile In-App Purchase (MM) Plugin

Platforms: Android only
Plugin version: 1.2.5
MMIAP SDK version: 3.1.7

Generally you don't have to dive into the documentation from ChinaMobile, simply follow a few steps below to get the plugin integrated in your App in minutes:

[1] Import the ChinamobileIAPAndroid.unitypackage file to your project;

[2] Click on the menu item of Unity top menu bar: NeatPlug -> ChinamobileIAP -> Patch Android Configuration. This is for generating a valid AndroidManifest.xml or patching the existing file with ChinamobileIAP support.

[3] Find ChinamobileIAPAgent Prefab and ChinamobileIAPListener Prefab in Assets/Plugins/NeatPlug/IAP/ChinamobileIAP/Prefabs/, open the first scene of your game, drag & drop those two prefabs into the scene. Select the ChinamobileIAPAgent gameObject in Hierarchy Window and fill in the public "App Id" and "App Key" fields with the information you got from ChinaMobile publisher account; Fill in Consumable Skus, Nonconsumable Skus and Subscription Skus, these properties are intended for registering your skus that need to be queried automatically when App starts. (Please note that currently the MM SDK doesn't support IAP item details query, this is merely a placeholder for further implementation)

[4] To deliver your in-app items when a purchase has successfully completed, you need to handle purchase events, to do so:

  Follow the instructions to handle purchase events:

  · Select the dropped ChinamobileIAPListener gameObject, locate the ChinamobileIAPListener.cs script, open it and make some modifications.

  These callbacks are exposed in the script, you can supply your own implementations in them.
Show All   
void OnPurchaseCompleted(ChinamobileIAPReceipt receipt) { ... }
/**
 * Fired when the purchase successfully completed.
 *
 * This is where you should deliver the item to the user.
 *	 
 * @param receipt
 *           ChinamobileIAPReceipt - An object which contains the purchase information. 
 *                             { sku, purchaseTime, orderId, purchaseToken, 
 *                               purchaseState, packageName, developerPayload }
 */
void OnPurchaseCompleted(ChinamobileIAPReceipt receipt)
{
    /// Your code here...   
}
void OnPurchaseFailed(string sku, string err) { ... }
/**
 * Fired when the purchase failed.
 *
 * @param sku
 *           string - IAP item identifier, the Product ID (PayCode) you got from ChinaMobile's publisher site.
 *
 * @param err
 *           string - The reason for failure.
 */
void OnPurchaseFailed(string sku, string err)
{
    /// Your code here...
}
void OnPurchaseCancelled(string sku) { ... }
/**
 * Fired when the purchase cancelled by the user.
 *
 * @param sku
 *           string - IAP item identifier, the Product ID (PayCode) you got from ChinaMobile's publisher site.
 */
void OnPurchaseCancelled(string itemId)
{
    /// Your code here...   
}
void OnBillingSupported(bool supported, string response) { ... }
/**
 * Fired when the check for the In-App Purchase support is done.
 * 
 * By default, the plugin will check if In-App Purchase is supported on current
 * device as soon as App launches. There are a few cases the check may return false:
 * The version of ChinaMobile MM Software installed on the device is too old, or the
 * user is using the device with the operator that In-App Purchase is not supported.
 * For other possible cases, please refer to ChinaMobile android developer site.
 * 
 * @param supported
 *             bool - true for supported, false for unsupported.
 * 
 * @param response
 *             string - The response code returned from ChinaMobile IAP API.
 *
 */
void OnBillingSupported(bool supported, string response)
{
    /// Your code here...   
}
void OnSubscriptionSupported(bool supported, string response) { ... }
/**
 * Fired when the check for subcription support is done. 
 *
 * @param supported
 *             bool - true for supported, false for unsupported.
 * 
 * @param response
 *             string - The response code returned from ChinaMobile IAP API.
 */
void OnSubscriptionSupported(bool supported, string response)
{
    /// Your code here...
}
void OnOwnedItemReported(string sku) { ... }
/**
 * Fired when receiving an owned item report event.
 * 
 * This indicates that the item type is "NonConsumable" or "Subscription" and the user has already 
 * owned the item. By default the plugin gets notified with the event every time your 
 * app launches, it is suggested that you should redeliver the item to the user here 
 * if the locally saved data record cannot be found. (Probably the user cleared the 
 * PlayerPrefs data or a new device is being used) 
 * 
 * @param sku
 *           string - IAP item identifier, the sku you got from ChinaMobile's publisher site.	
 */
void OnOwnedItemReported(string sku)
{
    /// Your code here...
}
void OnItemAlreadyOwned(string sku) { ... }
/**
 * Fired if the user has already owned this NonConsumable item when a corresponding
 * purchase is attempted.
 *
 * This indicates that the item type is "NonConsumable" or "Subscription" and the user has already owned
 * the item. This event is only triggered in case you ignored the default automatic
 * owned item reporting happened in OnOwnedItemReported() at app launches, but 
 * you are not suggested to do so since requiring the user who has already purchased 
 * the NonConsumable item to perform the purchase again, and tell the user "You have already
 * owned the item", is obviously causing confusion.
 *
 * In most cases you should only play with the "OnOwnedItemReported()" event.
 * But you can use this where you really need it to be that way.
 *
 * @param sku
 *           string - IAP item identifier, the sku you got from ChinaMobile's publisher site.	
 */
void OnItemAlreadyOwned(string sku)
{
    /// Your code here...
}
void OnItemUnsubscribed(string sku) { ... }
/**
 * Fired when the purchased item successfully unsubscribed.
 * 
 * @param sku
 *           string - IAP item identifier, the sku you got from ChinaMobile's publisher site.	
 * 	
 */
void OnItemUnsubscribed(string sku)
{
    /// Your code here...
}
void OnItemFailedToUnsubscribe(string sku) { ... }
/**
 * Fired when the purchased item failed to be unsubscribed.
 * 
 * @param sku
 *           string - IAP item identifier, the sku you got from ChinaMobile's publisher site.	
 * 	 
 */
void OnItemFailedToUnsubscribe(string sku)
{
    /// Your code here...
}

[5] Call ChinamobileIAP.Instance().Purchase(string sku) function in your code to initiate a purchase request.

  Initiate a purchase request:

  · ChinamobileIAP.Instance().Purchase(string sku);

  There are useful public methods that ChinamobileIAP provides, to use them, simply call ChinamobileIAP.Instance().methodName().
Show All   
public void Purchase(string sku, string payload = null)
/**
 * Initiate a purchase request to the plugin.
 *
 * @param sku
 *           string - IAP item identifier, the Product ID (PayCode) you got from ChinaMobile's publisher site.
 *
 * @param payload (optional)
 *          string -  a developer payload that is associated with a given purchase,
 *          if null, no payload is sent. Developer Payload is a developer-specified
 *          string that contains supplemental information about a purchase.
 *          This parameter is optional.
 */
public void Purchase(string sku, string payload = null)
public void Purchase(string sku, int count, string payload = null)
/**
 * Initiate a purchase request to the plugin.
 *
 * @param sku
 *           string - IAP item identifier, the Product ID (PayCode) you got from ChinaMobile's publisher site.
 *
 * @param count
 *           int - The number of items to be purchased, only valid for items that support batch purchasing. 
 *
 *
 * @param payload (optional)
 *          string -  a developer payload that is associated with a given purchase,
 *          if null, no payload is sent.Developer Payload is a developer-specified
 *          string that contains supplemental information about a purchase.
 *          This parameter is optional.
 */
public void Purchase(string sku, int count, string payload = null)
public void Unsubscribe(string sku)
/**
 * Unsubscribe a product.
 * 
 * This function is only valid for subscriptions.
 * 
 * @param sku
 *           string - IAP item identifier, the Product ID (PayCode) you got from ChinaMobile's publisher site.
 * 			 
 */
public void Unsubscribe(string sku)

[6] Test your In-App Purchase functionality. Before you can test, you should create your IAP products and get the Product IDs (PayCodes) at ChinaMobile MM publisher site. Also it would be helpful for you to address issues if you take a look at the logcat output to find the debug / error / warning messages.

[EOF] If you encounter any problems while integrating the plugin, please do not hesitate to shoot us an email at support@neatplug.com, we will be helping you as soon as possible.Thanks for choosing NeatPlug solutions!