IAP not working on Android

Hi there,

I’ve this piece of code…

local store = require("plugin.google.iap.v3") local function foo(event) print(event.transaction.state) end store.init("google", foo) print("purchasing ".. productID) store.consumePurchase(productID)

… but doesn’t work. When debugging, this is the traceback:

I/Corona (28152): purchasing: myProductID D/IabHelper(28152): Starting async operation: refresh inventory D/dchan (28152): Inventory refresh successful. (response: 0:OK) D/IabHelper(28152): Querying owned items, item type: inapp D/IabHelper(28152): Package name: com.myCompany.myApp D/IabHelper(28152): Calling getPurchases with continuation token: null D/Finsky (17304): [9156] InAppBillingUtils.getPreferredAccount: com.myCompany.myApp: Account from first account - [xxxxxxxxxxxxxxxxxxxxxxxxxxx] D/Finsky (17304): [9156] InAppBillingUtils.getPreferredAccount: com.myCompany.myApp: Account from first account - [xxxxxxxxxxxxxxxxxxxxxxxxxxx] D/IabHelper(28152): Owned items response: 0 D/IabHelper(28152): Continuation token: null D/IabHelper(28152): Querying SKU details. D/IabHelper(28152): queryPrices: nothing to do because there are no SKUs. D/IabHelper(28152): Querying owned items, item type: subs D/IabHelper(28152): Package name: com.myCompany.myApp D/IabHelper(28152): Calling getPurchases with continuation token: null D/Finsky (17304): [9132] InAppBillingUtils.getPreferredAccount: com.myCompany.myApp: Account from first account - [xxxxxxxxxxxxxxxxxxxxxxxxxxx] D/Finsky (17304): [9132] InAppBillingUtils.getPreferredAccount: com.myCompany.myApp: Account from first account - [xxxxxxxxxxxxxxxxxxxxxxxxxxx] D/IabHelper(28152): Owned items response: 0 D/IabHelper(28152): Continuation token: null D/IabHelper(28152): Querying SKU details. D/IabHelper(28152): queryPrices: nothing to do because there are no SKUs. D/IabHelper(28152): Ending async operation: refresh inventory D/IabHelper(28152): Starting async operation: consume D/IabHelper(28152): Ending async operation: consume

I wondered it could be some problem when adding the products in the Google Play Developer Console, but tried to purchase them through an Android native app and this works, but not using Corona…

The app key in config.lua is correct, the product id’s are also correct, I added “com.android.vending.BILLING” in userPermissions in build.settings… Don’t know what else may I miss…

Any idea?

Hi, did you ever figure out a solution to this?  I’m getting a similar log when I try to get the current prices of the IAP items in order to display them.  I’m using the IAP V3 plugin from Corona (non enterprise)

D/IabHelper( 4451): Calling getPurchases with continuation token: null

D/Finsky  ( 1496): [140] InAppBillingUtils.getPreferredAccount: com…

D/Finsky  ( 1496): [140] InAppBillingUtils.getPreferredAccount: com…

D/IabHelper( 4451): Owned items response: 0

D/IabHelper( 4451): Continuation token: null

D/IabHelper( 4451): Querying SKU details.

D/IabHelper( 4451): queryPrices: nothing to do because there are no SKUs.

D/IabHelper( 4451): Ending async operation: refresh inventory

If I attempt to purchase I get the google play popup message “The item you were attempting to purchase could not be found.”

I had this working fine a few weeks ago, worked on a bunch of stuff unrelated to IAP and now this stopped working.  Not sure what changed, but don’t think I messed with anything.

Thanks in advance for any insight you can provide.

-Stephen

Hi Steven,

Nope, still doesn’t work… Anyway, I don’t even reach at your point, my app doesn’t display any GooglePlay popup. Your error seems to be you have something misconfigured. Did you add your GooglePlay App ID at your config.lua? Are your products active? Do your product ID’s match?

Hi Roger, Thanks for the reply.

Actually, my problem seems to have fixed itself.  I had updated the production version # for the uploaded APK and I guess it takes a while for Google’s servers to synchronize everything.  Some products started showing up a few hours after I posted, and after waiting overnight all products are now showing up.

As to your issue,  Maybe I’m not understanding what you are trying to do but I see in your sample code you never actually purchase an item.  Something like

store.purchase(productID)

Shouldn’t you still have to do that prior to consuming a purchase?

-Stephen

Nope, I don’t use the store.purchase function since I’m purchasing consumables, so I use the store.consumePurchase

That gets to the heart of a question I have on another thread regarding consumables and the Google IAP V3 api.  From the Google docs for consumables and V3, you first need to purchase the item, and then, using the custom token returned from a successful purchase, you need to make a separate call to consumePurchase in order to actually consume it.  But the Corona docs suggest you just pass the product SKU in to store.consumePurchase.  I’m wondering if Corona’s implementation is correct or not.  Love to know if anyone has any success with consumables and the V3 plugin using Corona, and if so, how they did it.

Ok, I get it… I need to purchase it the very first time, but then use the consumePurchase function to unlock the purchase in order to call the purchase function once again, is that correct?

Yep, that’s what’s working for me. 

Ok, done and working! “Luckily I had Corona documentation”…

Good to hear that, Roger.  I got mine working as well and a few days later it got all sorts of broken again.  I found out Google recently made some changes that now require using beta builds to test real IAP.  Here’s another thread detailing what I found out:

http://forums.coronalabs.com/topic/48254-google-iap-heads-up/

Hi, did you ever figure out a solution to this?  I’m getting a similar log when I try to get the current prices of the IAP items in order to display them.  I’m using the IAP V3 plugin from Corona (non enterprise)

D/IabHelper( 4451): Calling getPurchases with continuation token: null

D/Finsky  ( 1496): [140] InAppBillingUtils.getPreferredAccount: com…

D/Finsky  ( 1496): [140] InAppBillingUtils.getPreferredAccount: com…

D/IabHelper( 4451): Owned items response: 0

D/IabHelper( 4451): Continuation token: null

D/IabHelper( 4451): Querying SKU details.

D/IabHelper( 4451): queryPrices: nothing to do because there are no SKUs.

D/IabHelper( 4451): Ending async operation: refresh inventory

If I attempt to purchase I get the google play popup message “The item you were attempting to purchase could not be found.”

I had this working fine a few weeks ago, worked on a bunch of stuff unrelated to IAP and now this stopped working.  Not sure what changed, but don’t think I messed with anything.

Thanks in advance for any insight you can provide.

-Stephen

Hi Steven,

Nope, still doesn’t work… Anyway, I don’t even reach at your point, my app doesn’t display any GooglePlay popup. Your error seems to be you have something misconfigured. Did you add your GooglePlay App ID at your config.lua? Are your products active? Do your product ID’s match?

Hi Roger, Thanks for the reply.

Actually, my problem seems to have fixed itself.  I had updated the production version # for the uploaded APK and I guess it takes a while for Google’s servers to synchronize everything.  Some products started showing up a few hours after I posted, and after waiting overnight all products are now showing up.

As to your issue,  Maybe I’m not understanding what you are trying to do but I see in your sample code you never actually purchase an item.  Something like

store.purchase(productID)

Shouldn’t you still have to do that prior to consuming a purchase?

-Stephen

Nope, I don’t use the store.purchase function since I’m purchasing consumables, so I use the store.consumePurchase

That gets to the heart of a question I have on another thread regarding consumables and the Google IAP V3 api.  From the Google docs for consumables and V3, you first need to purchase the item, and then, using the custom token returned from a successful purchase, you need to make a separate call to consumePurchase in order to actually consume it.  But the Corona docs suggest you just pass the product SKU in to store.consumePurchase.  I’m wondering if Corona’s implementation is correct or not.  Love to know if anyone has any success with consumables and the V3 plugin using Corona, and if so, how they did it.

Ok, I get it… I need to purchase it the very first time, but then use the consumePurchase function to unlock the purchase in order to call the purchase function once again, is that correct?

Yep, that’s what’s working for me. 

Ok, done and working! “Luckily I had Corona documentation”…

Good to hear that, Roger.  I got mine working as well and a few days later it got all sorts of broken again.  I found out Google recently made some changes that now require using beta builds to test real IAP.  Here’s another thread detailing what I found out:

http://forums.coronalabs.com/topic/48254-google-iap-heads-up/