iap

Version: stable

FUNCTION
buy()
finish()
acknowledge()
get_provider_id()
list()
restore()
set_listener()
CONSTANT
PROVIDER_ID_AMAZON
PROVIDER_ID_APPLE
PROVIDER_ID_FACEBOOK
PROVIDER_ID_GOOGLE
REASON_UNSPECIFIED
REASON_USER_CANCELED
TRANS_STATE_FAILED
TRANS_STATE_PURCHASED
TRANS_STATE_PURCHASING
TRANS_STATE_RESTORED
TRANS_STATE_UNVERIFIED

Functions

buy()

buy(id,options)

Purchase a product.

PARAMETERS

id string product to buy
options table optional parameters as properties. The following parameters can be set

EXAMPLES

  local function iap_listener(self, transaction, error)
    if error == nil then
      -- purchase is successful.
      print(transaction.date)
      -- required if auto finish transactions is disabled in project settings
      if (transaction.state == iap.TRANS_STATE_PURCHASED) then
        -- do server-side verification of purchase here..
        iap.finish(transaction)
      end
    else
      print(error.error, error.reason)
    end
  end

  function init(self)
      iap.set_listener(iap_listener)
      iap.buy("my_iap")
  end

finish()

finish(transaction)

Explicitly finish a product transaction. [icon:attention] Calling iap.finish is required on a successful transaction if `auto_finish_transactions` is disabled in project settings. Calling this function with `auto_finish_transactions` set will be ignored and a warning is printed. The `transaction.state` field must equal `iap.TRANS_STATE_PURCHASED`.

PARAMETERS

transaction table transaction table parameter as supplied in listener callback

acknowledge()

acknowledge(transaction)

Acknowledge a transaction. [icon:attention] Calling iap.acknowledge is required on a successful transaction on Google Play unless iap.finish is called. The transaction.state field must equal iap.TRANS_STATE_PURCHASED.

PARAMETERS

transaction table transaction table parameter as supplied in listener callback

get_provider_id()

get_provider_id()

Get current iap provider

PARAMETERS

None

RETURNS

constant one of the following values - `iap.PROVIDER_ID_GOOGLE` - `iap.PROVIDER_ID_AMAZON` - `iap.PROVIDER_ID_APPLE` - `iap.PROVIDER_ID_FACEBOOK`

list()

list(ids,callback)

Get a list of all avaliable iap products.

PARAMETERS

ids table table (array) of identifiers to get products from
callback function result callback taking the following parameters
self object The current object.
products table a table describing the available iap products.
error table a table containing error information. `nil` if there is no error. - `error` (the error message)

EXAMPLES

  local function iap_callback(self, products, error)
    if error == nil then
      for k,p in pairs(products) do
        -- present the product
        print(p.title)
        print(p.description)
      end
    else
      print(error.error)
    end
  end

  function init(self)
      iap.list({"my_iap"}, iap_callback)
  end

restore()

restore()

Restore previously purchased products.

PARAMETERS

None

RETURNS

boolean value is `true` if current store supports handling restored transactions, otherwise `false`.

set_listener()

set_listener(listener)

Set the callback function to receive purchase transaction events.

PARAMETERS

listener function listener callback function. Pass an empty function if you no longer wish to receive callbacks.
self object The current object.
transaction table a table describing the transaction.
error table a table containing error information. `nil` if there is no error. `error` - the error message. `reason` - the reason for the error, value can be one of the following constants - `iap.REASON_UNSPECIFIED` - `iap.REASON_USER_CANCELED`

Constants

PROVIDER_ID_AMAZON

provider id for Amazon


PROVIDER_ID_APPLE

provider id for Apple


PROVIDER_ID_FACEBOOK

provider id for Facebook


PROVIDER_ID_GOOGLE

iap provider id for Google


REASON_UNSPECIFIED

unspecified error reason


REASON_USER_CANCELED

user canceled reason


TRANS_STATE_FAILED

transaction failed state


TRANS_STATE_PURCHASED

transaction purchased state


TRANS_STATE_PURCHASING

transaction purchasing state This is an intermediate mode followed by TRANS_STATE_PURCHASED. Store provider support dependent.


TRANS_STATE_RESTORED

transaction restored state This is only available on store providers supporting restoring purchases.


TRANS_STATE_UNVERIFIED

transaction unverified state, requires verification of purchase