This is the first time I’m implementing in-game purchases, currently on the Android platform.
I’m a little confused, so I need help from those who have had experience to see if I’m doing it right.
So, imagine that we have 3 items available for in-game purchases with the following ID’s
-
COINS_ID
(pack of 1000 coins, CONSUMABLE) -
NOADS_ID
(no ads, NON_CONSUMABLE) -
NOADS_COINS_ID
(pack of 1000 coins + no ads, NON_CONSUMABLE)
1 ) let’s see at our main callback iap.set_listener(iap_listener)
:
function iap_listener(self, transaction, error)
...
elseif transaction.state == iap.TRANS_STATE_PURCHASED then
if transaction.ident == M.NOADS_ID then
print('[NOADS_ID] - Purchased')
iap.acknowledge(transaction) -- because NON_CONSUMABLE
-- set flag to not show ads
elseif transaction.ident == M.COINS_ID then
print('[COINS_ID] - Purchased')
iap.finish(transaction) -- because CONSUMABLE
-- add N coins
elseif transaction.ident == M.NOADS_COINS_ID then
print('[NOADS_COINS_ID] - Purchased')
iap.acknowledge(transaction) -- because NON_CONSUMABLE
-- set flag to not show ads
-- and
-- add N coins ( <-- not the right decision at the moment, see point 2 for more details. )
end
end
...
2 ) with item NOADS_COINS_ID each time a player opens the game (if he has purchased this purchase before) he will receive 1000 coins.
or each time by clicking the restore purchase button.
how to implement it correctly? looks like need to do something like that:
elseif transaction.ident == M.NOADS_COINS_ID then
print('[NOADS_COINS_ID] - Purchased')
iap.acknowledge(transaction) -- because NON_CONSUMABLE
-- set flag to not show ads
-- and
if [flag_is_clicked_button_buy_NOADS_COINS_ID] or [flag_start_game] then
-- add N coins
-- flag_is_clicked_button_buy_NOADS_COINS_ID = false
end
end
flag_start_game
- on case if we removed the app and install again need to restore purchased items at start the game. Good idea?
3 ) Checking the official example of the extension, I found the following line:
iap.get_provider_id() == iap.PROVIDER_ID_GOOGLE
?
what does this function mean?
it looks like the example is incomplete because the NON_CONSUMABLE purchase is not called anywhere, and there is no gui.get_node("reset/larrylabel")
button
4 ) if to select the following payment method during testing:
“Slow test card, approves after a few minutes”, we will get:
transaction.state == iap.TRANS_STATE_PURCHASING
need to call iap.process_pending_transactions()
with timer every 1 sec for example. or just wait?
5 ) Maybe it makes sense to add this line to extension-iap AndroidManifest by default?
<uses-permission android:name="com.android.vending.BILLING" />
6 ) If I missed something else, let me know! Any advice would be greatly appreciated!