plugin.amazon.iap.*

Type library
Revision 2014.2382
Keywords plugin.amazon.iap
Sample code
See also
Availability Basic, Pro, Enterprise

Overview

The Amazon In-App Purchasing plugin lets you sell digital content and subscriptions--such as in-game currency, expansion packs, upgrades, magazine issues and more--from within your apps.

Sign Up

To use the Amazon In-App Purchasing API, you must distribute your app with the Amazon Appstore. Please sign up for an account.

Platforms

The following platforms are supported:

Syntax

local amazonIAP = require "plugin.amazon.iap"

Functions

Before using the Amazon IAP plugin, please familiarize yourself with the Amazon In-App Purchasing workflows here. Please note, you must install the Amazon SDK Tester or publish your app through the Amazon Appstore to use the Amazon IAP plugin.

The Amazon IAP plugin provides most functions and fields provided by the core store library with some minor differences as detailed below:

The following functions and fields in the Corona store API are not supported by the Amazon IAP Plugin:

The following functions and fields are provided by the Amazon IAP Plugin and are additional to the Corona store API:

Project Settings

SDK

When you build using the Corona Simulator, the server automatically takes care of integrating the plugin into your project.

All you need to do is add an entry into a plugins table of your build.settings. The following is an example of a minimal build.settings file:

Amazon IAP plugin is not supported on any platform except android. On these platforms the library methods are stubbed.

settings =
{
    plugins =
    {
        -- key is the name passed to Lua's 'require()'
        ["plugin.amazon.iap"] =
        {
            -- required
            publisherId = "com.amazon",
        },
    },      
}

Enterprise

This plugin is prebundled in the Plugins-3rd-Party folder of the CoronaEnterprise download.

Copy the following JAR files to the libs directory of your Android project:

in-app-purchasing-1.0.3.jar
plugin.amazon.iap.jar 

Alternatively, you may wish to use the in-app-purchasing-1.0.3.jar directly. The documentation for the In-App Purchasing API can be found here.

Sample Code

local function storeListener( event ) 
    local transaction = event.transaction 
    if transaction.state == "purchased" then 
        print("productIdentifier", transaction.productIdentifier) 
        print("receipt", transaction.receipt) 
        print("transactionIdentifier", transaction.identifier) 
        print ("The user who made the purchase was", transaction.userId) 

        --Entitle this SKU here: 

    elseif  transaction.state == "restored" then 
        print("productIdentifier", transaction.productIdentifier) 
        print("receipt", transaction.receipt) 
        print("transactionIdentifier", transaction.identifier) 
        print ("The user who made the purchase was", transaction.userId) 
        --Entitle this SKU here: 

    elseif  transaction.state == "revoked" then 
        print("productIdentifier", transaction.productIdentifier) 
        print("receipt", transaction.receipt) 
        print("transactionIdentifier", transaction.identifier) 
        print ("The user who has a revoked purchase is", transaction.userId) 
        --Revoke this SKU here: 

    elseif transaction.state == "failed" then 
        print("Transaction failed", transaction.errorType, transaction.errorString) 
        --display an error message here 
    end 
end 

local function loadProductsListener( event ) 
    local products = event.products 
    for i=1, #event.products do 
        print(event.products[i].title) 
        print(event.products[i].description) 
        print(event.products[i].localizedPrice) 
        print(event.products[i].productIdentifier) 
    end 
    for i=1, #event.invalidProducts do 
        print(event.invalidProducts[i]) 
    end 
end 

store = require "store" 
if system.getInfo("targetAppStore") == "amazon"  or system.getInfo("environment") == "simulator" then 
    store = require "plugin.amazon.iap" 

    store.init( storeListener ) 
    print("The currently logged in user is: ", store.getUserId())
    store.restore() 

    if store.canLoadProducts == true then 
        store.loadProducts({"my_sku"}, loadProductsListener) 
    end 

    if store.isSandboxMode() == true then 
        store.purchase("my_test_sku") 
    else 
        store.purchase("my_real_sku") 
    end 
end 

Support

More support is available: