Android IAP doesn't work / How to test IAP without uploading the app ?

Hey there,

I have a few problems testing the inApp Purchases of my app.

I have an app for iOS and Android and theres one iap for “removing ads”.
Here’s my code so you can see if i do something wrong or not.

At first I create the store and productlist thing for each platform like this:

-- STORE -- local store local googleIAP = false local currentProductList = nil local appleProductList = {     "removeAds", } local googleProductList = "remove\_ads" if ( system.getInfo( "platformName" ) == "Android" ) then     store = require( "plugin.google.iap.v3" )     googleIAP = true     currentProductList = googleProductList     store.init( "google", storeTransaction ) elseif ( system.getInfo( "platformName" ) == "iPhone OS" ) then     store = require( "store" )     currentProductList = appleProductList     store.init( "apple", storeTransaction ) end

Later in the code I create the storeTransaction thing:

local function storeTransaction( event )    local transaction = event.transaction    if ( transaction.state == "purchased" ) then     purchased = true     elseif ( transaction.state == "cancelled" ) then    elseif ( transaction.state == "failed" ) then    end    store.finishTransaction( event.transaction ) end

So now when I call:

store.purchase( currentProductList )

The storeTransaction listener should start and look if the IAP was “purchased”, “cancelled” or “failed”.
In my case I only have a variable that is changing when the iap was purchased.
I uploaded the app in the play store, downloaded it and tested it.
I was able to purchase this iap but the variable doesn’t changed.

Like the listener is not working well.

Can you help me solve this problem ?
And is there maybe an easy way to test inapp purchases on Android AND on iOS without uploading it ?
I’m sure there is, but how ? 

Thank you in advance!!!
Dima

Its still doesn’t work on Android, I think on iOS too.
Now I now how to test IAPs on Android, I need another gmail account and put it in as a test account in my developer console.

So but this damn storeTransaction still doesn’t work.
The purchase is succeeded but the variable “purchase” doesn’t change to true.
 

My storeTransaction looks like this now.

local function storeTransaction( event )    local transaction = event.transaction    if ( transaction.state == "purchased" ) then     purchased = true     store.finishTransaction( event.transaction )    elseif ( transaction.state == "cancelled" ) then     store.finishTransaction( event.transaction )            elseif ( transaction.state == "failed" ) then     store.finishTransaction( event.transaction )      end end

PLLEASE help me to solve this annoying problem… :frowning:

Thanks in advance!

You say the storeTransaction function is “later” in the code, which I assume means after you are calling store.unit(). This won’t work because your storeTransaction function is defined as a local, so you must place the code that calls store.unit() after the storeTransaction function definition.

Aaaah so easy…
I just tested it and it works!

Thank you tonygod! :slight_smile:

Its still doesn’t work on Android, I think on iOS too.
Now I now how to test IAPs on Android, I need another gmail account and put it in as a test account in my developer console.

So but this damn storeTransaction still doesn’t work.
The purchase is succeeded but the variable “purchase” doesn’t change to true.
 

My storeTransaction looks like this now.

local function storeTransaction( event )    local transaction = event.transaction    if ( transaction.state == "purchased" ) then     purchased = true     store.finishTransaction( event.transaction )    elseif ( transaction.state == "cancelled" ) then     store.finishTransaction( event.transaction )            elseif ( transaction.state == "failed" ) then     store.finishTransaction( event.transaction )      end end

PLLEASE help me to solve this annoying problem… :frowning:

Thanks in advance!

You say the storeTransaction function is “later” in the code, which I assume means after you are calling store.unit(). This won’t work because your storeTransaction function is defined as a local, so you must place the code that calls store.unit() after the storeTransaction function definition.

Aaaah so easy…
I just tested it and it works!

Thank you tonygod! :slight_smile: