Functions and constants for interacting with Apple's In-app purchases and Google's In-app billing.
provider id for Amazon
provider id for Apple
provider id for Facebook
iap provider id for Google
unspecified error reason
user canceled reason
transaction failed state
transaction purchased state
transaction purchasing state
This is an intermediate mode followed by TRANS_STATE_PURCHASED. Store provider support dependent.
transaction restored state
This is only available on store providers supporting restoring purchases.
transaction unverified state, requires verification of purchase
buy product
Perform a product purchase.
Calling iap.finish()
is required on a successful transaction if
auto_finish_transactions
is disabled in project settings.
id -
string product to buy
[options] -
table optional parameters as properties. The following parameters can be set:
request_id
( Facebook only. Optional custom unique request id to
set for this transaction. The id becomes attached to the payment within the Graph API.)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 buying product
Explicitly finish a product transaction.
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
.
transaction -
table transaction table parameter as supplied in listener callback
get current provider id
id -
constant provider id.
iap.PROVIDER_ID_GOOGLE
iap.PROVIDER_ID_AMAZON
iap.PROVIDER_ID_APPLE
iap.PROVIDER_ID_FACEBOOK
list in-app products
Get a list of all avaliable iap products. Products are described as a table with the following fields:
ident
title
description
price
price_string
currency_code
Nested calls, that is calling iap.list()
from within the callback is
not supported. Doing so will result in call being ignored with the engine reporting
"Unexpected callback set".
ids -
table table (array) of identifiers to get products from
callback -
function(self, products, error) result callback
self
products
error
nil
if there is no error.
- error
(the error message)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 products (non-consumable)
Restore previously purchased products.
success -
boolean true
if current store supports handling
restored transactions, otherwise false
.
set purchase transaction listener
Set the callback function to receive purchase transaction events. Transactions are described as a table with the following fields:
ident
state
iap.TRANS_STATE_*
.date
trans_ident
state
is TRANS_STATE_RESTORED,
TRANS_STATE_UNVERIFIED or TRANS_STATE_PURCHASED.receipt
state
is TRANS_STATE_PURCHASED
or TRANS_STATE_UNVERIFIED.original_trans
state
is
TRANS_STATE_RESTORED.signature
request_id
request_id
if set in the iap.buy()
call parameters.user_id
is_sandbox_mode
true
, the SDK is running in Sandbox mode. This only allows
interactions with the Amazon AppTester. Use this mode only for testing locally.cancel_date
canceled
true
if the receipt was canceled or has expired;
otherwise false
.listener -
function(self, transaction, error) listener callback function. Pass an empty function if you no longer wish to receive callbacks.
self
transaction
error
nil
if there is no error.
- error
(the error message)
- reason
(the reason for the error, see iap.REASON_*
)