dev-masih/cafebazaar-iap/iapc
Functions and constants for doing Cafebazaar in-app purchases.
- GitHub: dev-masih/cafebazaar-iap — pinned to
v1.1(released while Defold 1.2.163 was current)- Pick a release from dev-masih/cafebazaar-iap releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as iapc from "iapc"
- Pick a release from dev-masih/cafebazaar-iap releases and add its Source code (zip) URL (or a packaged
- Asset Portal: cafebazaar-iap
Functions
iapc.buy(id: string, options: table)
Sets the listener function for In-app purchase events.
local function iapc_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 == iapc.TRANS_STATE_PURCHASED) then
-- do server-side verification of purchase here..
iapc.finish(transaction)
end
else
print(error.error, error.reason)
end
end
function init(self)
iapc.set_listener(iapc_listener)
iapc.buy("my_iap_id")
endParameters
id:string— product to buyoptions:table— optional parameters as properties. The following parameters can be setrequest_id:string
iapc.finish(transaction: table)
Explicitly finish a product transaction. Calling iapc.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 iapc.TRANS_STATE_PURCHASED.
Parameters
transaction:table— transaction table parameter as supplied in listener callback
iapc.list(ids: table, callback: function)
Get a list of all avaliable iapc products.
local function iapc_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)
iapc.list({"my_iap_id"}, iapc_callback)
endParameters
ids:table— table (array) of identifiers to get products fromcallback:function— result callback taking the following parametersself:object— The current object.products:table— a table describing the available iapc products.ident:string— The product identifier.title:string— The product title.description:string— The product description.price:number— The price of the product.price_string:string— The price of the product, as a formatted string (amount and currency symbol).currency_code:string— The currency code, this reflects the merchant's locale, instead of the user's.
error:table— a table containing error information.nilif there is no error. -error(the error message)
iapc.restore(): boolean
Restore previously purchased products.
Returns
success:boolean— value istrueif current store supports handling restored transactions, otherwisefalse.
iapc.set_listener(listener: function)
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.ident:string— The product identifier.state:string— The transaction state. One of the followingiapc.TRANS_STATE_FAILEDiapc.TRANS_STATE_PURCHASEDiapc.TRANS_STATE_PURCHASINGiapc.TRANS_STATE_RESTOREDiapc.TRANS_STATE_UNVERIFIED
date:string— The date and time for the transaction.trans_ident:string— The transaction identifier. This field is only set whenstateisTRANS_STATE_RESTORED,TRANS_STATE_UNVERIFIEDorTRANS_STATE_PURCHASED.receipt:string— The transaction receipt. This field is only set whenstateisTRANS_STATE_PURCHASEDorTRANS_STATE_UNVERIFIED.signature:string— A string containing the signature of the purchase data that was signed with the private key of the developer.
error:table— a table containing error information.nilif there is no error.error- the error message.reason- the reason for the error, value can be one of the following constantsiapc.REASON_UNSPECIFIEDiapc.REASON_USER_CANCELED
Constants
iapc.REASON_UNSPECIFIED
unspecified error reason
iapc.REASON_USER_CANCELED
user canceled reason
iapc.TRANS_STATE_FAILED
transaction failed state
iapc.TRANS_STATE_PURCHASED
transaction purchased state
iapc.TRANS_STATE_PURCHASING
transaction purchasing state This is an intermediate mode followed by TRANS_STATE_PURCHASED. Store provider support dependent.
iapc.TRANS_STATE_RESTORED
transaction restored state This is only available on store providers supporting restoring purchases.
iapc.TRANS_STATE_UNVERIFIED
transaction unverified state, requires verification of purchase