In-App Purchases workflow on Android

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 :slight_smile:

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!

2 Likes

For permanent IAPs it’s your job to save the data and not let them redeem it multiple times.

That’s related to selling on Google Play vs Amazon Appstore.

There should be callback that you just have to wait on.

5 ) Maybe it makes sense to add this line to extension-iap AndroidManifest by default?

This should be added automatically when using the IAP extension. You can bundle your APK and then check the manifest inside of it to see what ends up in there.

This might be helpful to reference but it’s been a few years since I messed with Android IAP.

5 Likes

@Pkeod thanks a lot!

3 Likes