Iab
From GiderosMobile
Interface usage is quite simple:
- IAB.new(iabframework) -- initialize specified IAB framework
Available frameworks: 'amazon', 'google', 'ios'
- IAB:setUp(value1, value2, ..., valueN) -- provide all the keys/devids/appids/etc needed for the framework, which you will get in same order on Native part in Map object
- IAB:setProducts({internalId1 = "storeId1", internalId2 = "storeId2", ..., internalIdn = "storeIdn"}) -- provide list of products you will be using (key is your internal products id, value is store specific product id)
- IAB:setConsumables({"internalId1", "internalId2", ..., "internalIdn"}) -- which of your products are consumables, that people can buy many times (provide internal product ids)
- IAB:isAvailable() --check if IAB is available, raises event:
- Event.AVAILABLE --iab is available
- IAB:requestProducts() --request information for products provided in setProducts method
- Event.PRODUCT_COMPLETE
- event.productId
- event.title
- event.description
- event.price
- Event.PRODUCT_ERROR
- event.error
- Event.PRODUCT_COMPLETE
- IAB:purchase(prodId) --purchase product by providing your internal product id, raises two events:
- Event.PURCHASE_COMPLETE
- event.productId
- event.receiptId
- Event.PURCHASE_ERROR
- event.error
- Event.PURCHASE_COMPLETE
- iab:restore() --raise purchase events for each previously purchases entitled (not consumed) items, raises two events:
- Event.RESTORE_COMPLETE
- Event.RESTORE_COMPLETE
- event.error
Code example:
local test
if application:getDeviceInfo() == "Android" then
test = IAB.new("google")
test:setUp("keys")
elseif application:getDeviceInfo() == "iOS" then
test = IAB.new("storekit")
test:setUp("keys")
end
--and here comes completely same code for both frameworks to request products/buy stuff etc
test:addEventListener(Event.AVAILABLE, function(e)
--provide setup stuff (framework specific)
test:setUp("value1", "value2", "value3")
test:purchase("product1") --purchase something
end)
test:addEventListener(Event.PURCHASE_COMPLETE, function(e)
--unlock your purchase here
print(e.productId, e.receiptId)
test:confirm(e.productId)
end)
test:isAvailable()
test:restore()