Release Notes: (1.1.1)
  • Upgraded to Amazon IAP Android SDK 1.0.3

Integration Guide - Amazon In-App Purchasing Plugin

Platforms: Android only
Plugin version: 1.1.1
Amazon Android SDK version: 1.0.3

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

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

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

If you are using Unity3.4.x(or earlier) and having UnityPlayerNativeActivity in your AndroidManifest.xml, please backup your original file, let NeatPlug menu tool generate a new one for you, to avoid UI unclickable issue.

[3] Find AmazonIAPAgent Prefab and AmazonIAPListener Prefab in Assets/Plugins/NeatPlug/IAP/AmazonIAP/Prefabs/, open the first scene of your game, drag & drop those two prefabs into the scene. Select the AmazonIAPAgent gameObject in Hierarchy Window and fill in the public "Skus" field with all your item skus that you want the plugin to automatically retreive information for you. (sku is your IAP item identifier which you defined at Amazon Developer Site)

[4] Select the dropped AmazonIAPListener gameObject, locate the AmazonIAPListener.cs script, open it and make some modifications:

These callbacks are exposed in the script, you can supply your own implementations in them:

void OnPurchaseCompleted(string sku) { ... }
/**
 * Fired when the purchase successfully completed.
 *
 * @param sku
 *           string - IAP item identifier, the sku you defined at amazon's developer site. 
 */
void OnPurchaseCompleted(string sku)
{
    /// Your code here...   
}
void OnPurchaseFailed(string sku) { ... }
/**
 * Fired when the purchase failed.
 *
 * Please note that currently Amazon does not send a separate event indicating purchase 
 * cancelation, when the user closes the IAP popup window, you still receive this purchase
 * failed event. To deliver better user experience, it is suggested that you should make 
 * the failure message a little bit "softer". For example, don't display "Purchase failed",
 * just say "Purchase cancelled, try again if you still want.".
 *
 * @param sku
 *           string - IAP item identifier, the sku you defined at amazon's developer site.
 */
void OnPurchaseFailed(string sku)
{
    /// Your code here...
}
void OnEntitledItemReported(string sku) { ... }
/**
 * Fired when receiving an ENTITLED item report event.
 *
 * This indicates that the item type is "ENTITLED" 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 re-entitle 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 defined at amazon's developer site.
 */
void OnEntitledItemReported(string sku)
{
    /// Your code here...   
}
void OnItemAlreadyEntitled(string sku) { ... }
/**
 * Fired if the user has already been entitled to this ENTITLED item when a corresponding
 * purchase is attempted.
 *
 * This indicates that the item type is "ENTITLED" and the user has already owned
 * the item. This event is only triggered in case you ignored the default automatic
 * entitled item reporting happened in OnEntitledItemReported() at app launches, but 
 * you are not suggested to do so since requiring the user who has already purchased 
 * the ENTITLED 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 "OnEntitledItemReported()" event.
 * But you can use this where you really need it to be that way.
 *
 * @param sku
 *           string - IAP item identifier, the sku you defined at amazon's developer site.	
 */	
void OnItemAlreadyEntitled(string sku)
{
    /// Your code here...   
}
void OnItemDataReady() { ... }
/**
 * Fired when the item data is ready to query.
 * Do your item query then if you need.
 */
void OnItemDataReady()
{
    /// Your code here...
}

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

public void Purchase(string sku)
/**
 * Initiate a purchase request to the plugin.
 *
 * @param sku
 *           string - IAP item identifier, the sku you defined at amazon's developer site.
 */
public void Purchase(string sku)

[6] Basically a runnable integration is done here, but if you need some advanced features. for example, display dynamic item information (like price can be possibly changed) or handle subscriptions, you will need to look into the following methods in class AmazonIAP. Calling these methods is simple: AmazonIAP.Instance().methodName(...);

public AmazonIAPItem GetItemInfo(string sku)
/**
 * Get the specified item information.
 *
 * The item information is retrieved at app launch and it is cached in plugin for better performance.
 * You should always call this function in AmazonIAPListener::OnItemDataReady() to make sure the data
 * has been ready for you to query.
 * 
 * @param sku
 *         string - IAP item identifier, the sku you defined at amazon's developer site.
 * 
 * @return
 *        AmazonIAPItem - A Amazon IAP Item which contains { title, description, price, type }
 */
public AmazonIAPItem GetItemInfo(string sku)
public float GetItemPrice(string sku)
/**
 * Get the price of specified item.
 * 
 * The item information is retrieved at app launch and it is cached in plugin for better performance.
 * You should always call this function in AmazonIAPListener::OnItemDataReady() to make sure the data
 * has been ready for you to query.
 *
 * @param sku
 *         string - IAP item identifier, the sku you defined at amazon's developer site.
 *
 * @return
 *        float - The price of the item
 */	
public float GetItemPrice(string sku)
public bool GetItemSubscriptionStatus(string sku)
/**
 * Query the item subscription status.
 *
 * Get if the subscription is active for the user. Deliver the subscription
 * if the status is active (true).
 *
 * The item information is retrieved at app launch and it is cached in plugin for better performance.
 * You should always call this function in AmazonIAPListener::OnItemDataReady() to make sure the data
 * has been ready for you to query. 
 *
 * @param sku
 *           string - IAP item identifier, the sku you defined at amazon's developer site.
 *
 * @return 
 *        bool - true for active, false for inactive.
 */
public bool GetItemSubscriptionStatus(string sku)
public ArrayList GetItemSubscriptionHistory(string sku)
/**
 * Query the item subscription history.
 * 
 * Applications that unlock content based on past active subscription
 * periods, should create purchasing history for the customer.
 * For example, if the customer has a magazine subscription for a year,
 * even if they do not have a currently active subscription,
 * they still have access to the magazines from when they were subscribed.
 *
 * The item information is retrieved at app launch and it is cached in plugin for better performance.
 * You should always call this function in AmazonIAPListener::OnItemDataReady() to make sure the data
 * has been ready for you to query. 
 *
 * @param sku
 *          string - IAP item identifier, the sku you defined at amazon's developer site.
 *
 * @return 
 *          ArrayList -  An array containing all historical subscriptions' periods.
 *                       The type of the array item is AmazonIAPSubscriptionPeriod.
 */
public ArrayList GetItemSubscriptionHistory(string sku)

[7] Test your IAP functionality. Download the test tool AmazonSDKTester.zip. Unzip it, there are two files in the package: amazon.sdktester.json and AmazonSDKTester.apk. Open amazon.sdktester.json, read and modify the test sample data, and then put it in the SDCARD root of your Android device; Install AmazonSDKTester.apk on your device using adb, and run the apk on your device. Now it is time to run your own app and see if your IAP feature works! 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!