Version: stable
FUNCTION | |
---|---|
buy() | |
finish() | |
acknowledge() | |
get_provider_id() | |
list() | |
restore() | |
set_listener() |
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(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(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 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(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
|
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 previously purchased products.
PARAMETERS
None
RETURNS
boolean |
value is `true` if current store supports handling restored transactions, otherwise `false`. |
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.
|
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