Difference between revisions of "Iab"

From GiderosMobile
Line 1: Line 1:
 +
Interface usage is quite simple
 +
 +
<source lang="lua">
 +
IAB.new(iabframework) -- initialize specified IAB framework
 +
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
 +
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
 +
iab:restore() --raise purchase events for each previously purchases entitled (not consumed) items, raises two events:
 +
Event.RESTORE_COMPLETE
 +
Event.RESTORE_COMPLETE
 +
event.error
 +
</source>
 +
 
===== Code example: =====
 
===== Code example: =====
 
<source lang="lua">
 
<source lang="lua">

Revision as of 13:10, 7 March 2019

Interface usage is quite simple

IAB.new(iabframework) -- initialize specified IAB framework
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
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
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 = IAB.new("test")

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()