loadProduct() Loads No Products

Hi everyone,

I am new to Android’s IAP, and here is what happens:

  1. I call store.loadProducts(listOfProducts, productCallback)

  2. listOfProducts contains the IDS I specified on the developer console

  3. productCallback: #event.products is always zero, products don’t get loaded.

Info: When I write “android.test.purchased” inside the listOfProducts, it gets loaded correctly, with price and everything.

Code:

local testText = display.newText("info", 50,50, "Arial", 20) local listOfProducts = { "buy1c", "buy2c", "buy3c", "buy4c", "buy5c" } local function productCallback(e) testText.text = ("Showing valid products:" .. #e.products) for a = 1,#listOfProducts do qTextPrice[a+1] = e.products[a].localizedPrice end qPrice.text = qTextPrice[qPrice.tier+1] end ... store.init("google", transactionCallback) store.loadProducts(listOfProducts, productCallback)

Hi @philipp3,

You should be checking for and looping through the event’s .product table, not through your own “listOfProducts” table. For example:

[lua]

for a = 1,#e.products do

[/lua]

Please see the example code here:

http://docs.coronalabs.com/plugin/google-iap-v3/loadProducts.html

Best regards,

Brent

Brent,

Thank you very much for your support, much appreciated.

Another solution solved the problem though, after I pre-published the game for betatesting, everything worked.

EDIT: Products are loaded, but in a wrong order, I didn’t find any information about that… in the code, it says:

{ “buy1c”, “buy2c”, “buy3c” … }

, but they are loaded in a different order (always 1, 3, 2, 5, 2)

I have no clue how that happens. It wouldn’t be a problem to code around that though, it just scares me a bit.

Best, Philipp

Hi Philipp,

Well, I assume after you load them, you’d like to display them to the user somehow. This could be done in any number of ways depending on your app… you could sort them by the “title”, or “productIdentifier”, or you could create a simple lookup table in Lua that matches one of those properties with some other sorting parameters, etc.

Brent

Sorting them is no problem. I just wondered because on iPhone they were already sorted in the order of the listOfProducts-table.
Thanks for your time Brent!

Hi @philipp3,

You should be checking for and looping through the event’s .product table, not through your own “listOfProducts” table. For example:

[lua]

for a = 1,#e.products do

[/lua]

Please see the example code here:

http://docs.coronalabs.com/plugin/google-iap-v3/loadProducts.html

Best regards,

Brent

Brent,

Thank you very much for your support, much appreciated.

Another solution solved the problem though, after I pre-published the game for betatesting, everything worked.

EDIT: Products are loaded, but in a wrong order, I didn’t find any information about that… in the code, it says:

{ “buy1c”, “buy2c”, “buy3c” … }

, but they are loaded in a different order (always 1, 3, 2, 5, 2)

I have no clue how that happens. It wouldn’t be a problem to code around that though, it just scares me a bit.

Best, Philipp

Hi Philipp,

Well, I assume after you load them, you’d like to display them to the user somehow. This could be done in any number of ways depending on your app… you could sort them by the “title”, or “productIdentifier”, or you could create a simple lookup table in Lua that matches one of those properties with some other sorting parameters, etc.

Brent

Sorting them is no problem. I just wondered because on iPhone they were already sorted in the order of the listOfProducts-table.
Thanks for your time Brent!