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)

Sets the listener function for In-app purchase events.

PARAMETERS

id product to buy
options 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 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 transaction table parameter as supplied in listener callback

get_provider_id()

get_provider_id()

Get current iap provider

PARAMETERS

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 (array) of identifiers to get products from
callback result callback taking the following parameters

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

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 listener callback function. Pass an empty function if you no longer wish to receive callbacks.

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