extension-iap

Namespace: iap Language: Lua Type: Extension

Functions and constants for doing in-app purchases. Supported on iOS, Android (Google Play and Amazon) and Facebook Canvas platforms. [icon:ios] [icon:googleplay] [icon:amazon] [icon:facebook]

API

iap.buy

Type: FUNCTION Purchase a product.

Parameters

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

iap.finish

Type: FUNCTION 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

iap.acknowledge

Type: FUNCTION 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

iap.get_provider_id

Type: FUNCTION Get current iap provider

Returns

iap.list

Type: FUNCTION Get a list of all avaliable iap products.

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

iap.restore

Type: FUNCTION Restore previously purchased products.

Returns

iap.set_listener

Type: FUNCTION Set the callback function to receive purchase transaction events.

Parameters

PROVIDER_ID_AMAZON

Type: VARIABLE provider id for Amazon

PROVIDER_ID_APPLE

Type: VARIABLE provider id for Apple

PROVIDER_ID_FACEBOOK

Type: VARIABLE provider id for Facebook

PROVIDER_ID_GOOGLE

Type: VARIABLE iap provider id for Google

REASON_UNSPECIFIED

Type: VARIABLE unspecified error reason

REASON_USER_CANCELED

Type: VARIABLE user canceled reason

TRANS_STATE_FAILED

Type: VARIABLE transaction failed state

TRANS_STATE_PURCHASED

Type: VARIABLE transaction purchased state

TRANS_STATE_PURCHASING

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

TRANS_STATE_RESTORED

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

TRANS_STATE_UNVERIFIED

Type: VARIABLE transaction unverified state, requires verification of purchase