It looks like I might have misunderstood the loadProducts() function of the Google IAP plugin. https://docs.coronalabs.com/plugin/google-iap-v3/loadProducts.html
This is the brunt of what I have:
local iapStore = require( "plugin.google.iap.v3" ) local function iapDisableAdsListener( event ) -- if product is available to purchase, it's because the user hasn't yet purchased it so make sure adverts are enabled if(#event.products == 1) then globals.settings.adverts = true globals.iaps["disable adverts"].price = event.products[1].localizedPrice else globals.settings.adverts = false end globals.writeSettingsFile() end local function storeTransactionListener( event ) if(event.name == "init") then -- Check to see if the user has purchased the disable advers IAP iapStore.loadProducts({ globals.iaps["disable adverts"].id }, iapDisableAdsListener ) elseif(event.name == "storeTransaction") then -- Calling iapStore.purchase() ends up here if not ( event.transaction.state == "failed" ) then if( event.transaction.productIdentifier == globals.iaps["disable adverts"].id ) then globals.settings.adverts = false globals.writeSettingsFile() end end end end iapStore.init( storeTransactionListener )
So, I’m calling .init() with storeTransactionListener() as the callback. Then I’m doing a loadProducts() call within that, where globals.iaps[“disable adverts”].id is the IAP product ID (this is definitely correct - other parts of the code use the same variable and work just fine), and iapDisableAdsListener() is its callback.
Ref https://docs.coronalabs.com/plugin/google-iap-v3/event/productList/index.html I thought that iapDisableAdsListener() would receive two lists - event.products being the list of valid products and event.invalidProducts being the list of invalid. I expected that an invalid product would be one that’s been purchased already, so the filtered-to-one-product call should result in one or zero products in the valid list, depending on whether the player has already purchased that product or not?
Currently, when I call .purchase() everything works as expected and my globals.settings.adverts variable is set to false but when I restart the app and this code runs, #event.products is still at 1 so the variable is set back to true again. The variable is actually part of a settings file which is correctly rewritten at the appropriate times and is still at false before this code runs.
So, it looks like I might have misunderstood the valid and invalid product lists. But currently the build is in internal testing and payment is via test cards, so it could be that I’ve understood correctly but that the product simply remains in the valid list until a real purchase is made?
Thoughts please?