google.iap.billing.v2.*

Type Library
Revision Release 2024.3703
Keywords Google, IAP, in-app purchases
Platforms Android

Overview

The Google IAP plugin allows you to support in-app purchasing on Android, including in-game currency, upgrades, and more.

For in-app purchasing on other platforms, see the documentation for Apple IAP, Samsung IAP or Amazon IAP.

Notes
Compatibility with IAPv3

This plugin is a drop in replacement for previous IAP plugin. It would even respond to require( "plugin.google.iap.v3" ) code. But there are couple differences:

Syntax

local store = require( "plugin.google.iap.billing.v2" )

Properties

store.target

store.isActive

store.canLoadProducts

Functions

store.init()

store.loadProducts()

store.purchase()

store.purchaseSubscription()

store.restore()

store.consumePurchase()

store.finishTransaction()

Events

init

storeTransaction

productList

Project Settings

To use this plugin, add an entry into the plugins table of build.settings. When added, the build will integrate the plugin during the build phase.

settings =
{
    plugins =
    {
        ["plugin.google.iap.billing.v2"] =
        {
            publisherId = "com.solar2d"
        },
    },
}

This will add mandatory com.android.vending.BILLING permission to your app.

Finally, the license table may be added to the project config.lua file if you want your purchases to be verified. Inside this table, the key value should be set to the corresponding key obtained from the Google Play Developer Console. In the Console, select your app, then click on “Monetization setup” section. Copy key from the “Licensing” section.

application =
{
    license =
    {
        google =
        {
            key = "YOUR_KEY",
        },
    },
}