# Amazon store plugin seems to be loading, but store.canLoadProducts returns false.  What am I doing wrong?

**URL:** <https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312>\
**Category:** Amazon IAP\
**Created:** [July 30, 2013, 2:45am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312 "2013-07-30T02:45:01Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 30, 2013, 2:45am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/1 "2013-07-30T02:45:01Z")

</div>

Blazing the beta trail here…

I read the plugin docs on this site and on Amazon’s re: getting IAP set up for testing. &nbsp;I’m at the stage where I’m testing it on an actual Kindle HD device, but the store.canLoadProducts is returning false even though the docs here say it should always return true. &nbsp;My app then fails to load the actual product skus for testing. &nbsp;Not sure what I’m doing wrong, but here’s what I did to set things up:

- created IAP skus (consumables) for my app on my Amazon dev. account console.
- created a JSON file called amazon.sdktester.json that contains the skus and parameters for each iap I want to test. &nbsp;I put this file in the …/sdcard/ folder on the device
- I downloaded the sdk tester .apk from Amazon’s SDK and installed it on the device
- In my app I require the amazon plugin in main.lua, and enable the plugin in build.settings
- In the store scene in my app I init the store if I detect store.target == “amazon” and if I detect store.isActive load the products skus with store.loadProducts and a callback. &nbsp;

But since the store.canLoadProducts is returning false it never gets to load the actual skus and instead loads some dummy default ones I set up to test the simulator.

I’m sure at any one of those steps I could have made a dumb mistake or typo but I’ve got debugging print statements throughout and don’t see where I’ve gone wrong. &nbsp;I’ve exercised and tested my IAP store scene pretty thoroughly and it works on devices/stores for Google Play and Apple so I don’t think the problem is there. &nbsp;Perhaps I’ve left out a crucial step, or there could be an issue with the plugin itself, but at this point I’m out of ideas. &nbsp;Anyone having success getting Amazon IAP to work have a clue where I might be going wrong?

---

<div class="post-metadata">

**Author:** ![tamkinp](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tamkinp](https://forums.solar2d.com/u/tamkinp)\
**Post date:** [July 30, 2013, 3:21am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/2 "2013-07-30T03:21:51Z")

</div>

Hello HardBoiledIndustries,

Just a clarification, in the first paragraph you mention ‘store.canLoadProducts’ returns false while later on you mention 'store.loadProducts 'is returning false. Which are you checking? ‘store.loadProducts’ has no return value

The field ‘canLoadProducts’ in the Amazon IAP plugin should indeed always equal true. Can you provide some sample code? Are you certain you are calling ‘store = require “plugin.amazon.iap”’ &nbsp;and ‘store.init( storeListener )’ before calling ‘store.loadProducts()’? It looks like the only way ‘store.canLoadProducts’ will equal ‘true’ is if you are using the Corona store API(instead of the Amazon IAP plugin).

&nbsp;  
&nbsp;

---

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 30, 2013, 4:10am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/3 "2013-07-30T04:10:25Z")

</div>

Hi tamkinp,

That was a typo (I fixed it in my original post). &nbsp;I am indeed checking store.canLoadProducts.

In terms of my code, since I’m doing a cross platform app it is a little messy with if thens to cover all the app stores and slightly different requirements for each, but I’ll snip out some of the relevant parts here:

_EDIT: &nbsp;ugh. &nbsp;This forum editor/tagging really screwed up the indentation of my code when I used the lua tags. &nbsp;Had to revert back to normal text for the lua code parts._

**from build.settings:**

```
&nbsp; &nbsp; &nbsp; &nbsp; ["plugin.amazon.iap"] = { publisherId = "com.amazon",}, --comment out when NOT building for Amazon store? &nbsp; &nbsp; &nbsp; &nbsp; --["CoronaProvider.gameNetwork.google"] = { publisherId = "com.coronalabs", }, -- comment out when building for iOS or Amazon Android, otherwise won't build for iOS. waiting for plugin to be enabled for iOS. &nbsp;App will force quit on Amazon Android version since it can't find google play store. &nbsp;How to do leaderboards on Amazon version? &nbsp; &nbsp; }, &nbsp;

```

**from main.lua:**

–in app purchases in Corona

local store = require(“store”) --covers Apple and Google Play stores

if store.target == “amazon” then&nbsp;

&nbsp; &nbsp; store = require “plugin.amazon.iap” --covers Android for Amazon store

end

**From my IAP scene: &nbsp;This is a little tough to follow but I’ll snip out the relevant bits in the order it runs:**

&nbsp; &nbsp; --initialize the store  
&nbsp; &nbsp; if Component:testNetworkConnection() == true then  
&nbsp; &nbsp; &nbsp; &nbsp; if store.availableStores.apple then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentProductList = appleProductList  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store.init(“apple”, transactionCallback)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“Using Apple’s in-app purchase system.”)  
&nbsp; &nbsp; &nbsp; &nbsp; elseif store.availableStores.google then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentProductList = googleProductList  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store.init(“google”, transactionCallback)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“Using Google’s Google Play Android In-App purchase system.”) &nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; elseif store.target == “amazon” &nbsp;then-- amazon IAP plugin doesn’t support store.availableStores API so need to use store.target  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --amazon store  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentProductList = amazonProductList  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store.init(transactionCallback)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“Using Amazon’s Android In-App purchase system.”) &nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; --elseif &nbsp; &nbsp; &nbsp; &nbsp;then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --TODO add Nook store IAP functionality

&nbsp; &nbsp; &nbsp; &nbsp; elseif isSimulator == true then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentProductList = simulatorProductList  
&nbsp; &nbsp; &nbsp; &nbsp; else

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“In-app purchases is not supported on this system/device.”)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; native.showAlert(“Store purchases are not supported on this system/device.”,&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { “OK” }, onClose )  
&nbsp; &nbsp; &nbsp; &nbsp; end  
&nbsp; &nbsp; else  
&nbsp; &nbsp; &nbsp; &nbsp; native.showAlert( strings:getString(“alertNoNetworkDetected”), strings:getString(“alertNetworkRequiredForIAP”), { strings:getString(“alertNetworkCloseButton”) }, onClose )  
&nbsp; &nbsp; end  
&nbsp; &nbsp;&nbsp;  
timer.performWithDelay (500, setupMyStore)&nbsp;

**after the 500 ms delay, setupMyStore fires:**

&nbsp; &nbsp; function setupMyStore(event)

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; if store.isActive or isSimulator then

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("store.canLoadProducts = "…tostring(store.canLoadProducts))

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (store.canLoadProducts) then&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; – Property “canLoadProducts” indicates that localized product information such as name and price

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; – can be retrieved from the store (such as iTunes). Fetch all product info here asynchronously.

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store.loadProducts( currentProductList, loadProductsCall

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“can’t load products, either google play or simulator, or a problem!”)back )

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print (“After store.loadProducts, waiting for callback”)

**if store.canLoadProducts was true then it would continue to my loadProductsCallback function, but it never gets here since it store.canLoadProducts is false for some reason. &nbsp;But here’s the loadProductsCallback anyway:**

&nbsp; &nbsp; function loadProductsCallback( event )

&nbsp; &nbsp; &nbsp; &nbsp; local products = event.products

&nbsp; &nbsp; &nbsp; &nbsp; for i=1, #event.products do&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.products[i].title)&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.products[i].description)&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.products[i].localizedPrice)&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.products[i].productIdentifier)&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; end&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; for i=1, #event.invalidProducts do&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.invalidProducts[i])&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; end&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; – save for later use

&nbsp; &nbsp; &nbsp; &nbsp; validProducts = event.products

&nbsp; &nbsp; &nbsp; &nbsp; invalidProducts = event.invalidProducts &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; unpackValidProducts()

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; end

**I also have a transactionCallback function that I know functions correctly for the other app stores, so I won’t include it here, but so far it doesn’t matter since the product ids/skus are not being grabbed from the ones I set up for Amazon.**

**And here is the amazon.sdktester.json file (actual skus removed) I placed on the device inside the&nbsp;…/sdcard/ folder on the device.**

```
{ &nbsp; "...candy101": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 0.99, &nbsp; &nbsp; "title": "Candy Bag", &nbsp; &nbsp; "description": "Big bag with 1,000 pieces of Candy! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; "...candy201": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 1.99, &nbsp; &nbsp; "title": "Candy Bowl", &nbsp; &nbsp; "description": "Large bowl filled with 2,500 pieces of Candy! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; &nbsp; "...candy301": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 2.99, &nbsp; &nbsp; "title": "Candy Wagon", &nbsp; &nbsp; "description": "Huge wagon filled with 7,500 pieces of Candy! Get more and save! &nbsp;TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; &nbsp; "...candy401": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 3.99, &nbsp; &nbsp; "title": "Candy Barrel", &nbsp; &nbsp; "description": "Barrel bursting with 7,500 pieces of Candy! &nbsp;Get more and save! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; &nbsp; "...candy501": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 4.99, &nbsp; &nbsp; "title": "Candy Crate", &nbsp; &nbsp; "description": "Massive crate filled with 10,000 pieces of Candy. &nbsp;A steal! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; &nbsp; "...candy601": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 9.99, &nbsp; &nbsp; "title": "Candy Crane", &nbsp; &nbsp; "description": "Construction crane spilling with 25,000 pieces of Candy! &nbsp;Best deal! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; } } &nbsp;

```

At first I thought perhaps the delayed setupMyStore function was getting called to early, before the store.init fired, but checking the logcat debugging prints I see it is getting called after. &nbsp;Here’s part of the logcat log with my debugging statements:

```
I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Using Amazon's Android In-App purchase system. I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;GameStats:getDisplayAdsState() = false I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;removeBannerAd I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;removing cookie rotate listener I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;store.canLoadProducts = false I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;can't load products (google play or simulator... I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Loading product list I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Product list loaded I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Country: US I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Found 6 valid items&nbsp; &nbsp;

```

Thanks for taking a look.

---

<div class="post-metadata">

**Author:** ![tamkinp](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tamkinp](https://forums.solar2d.com/u/tamkinp)\
**Post date:** [July 30, 2013, 4:43am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/4 "2013-07-30T04:43:55Z")

</div>

Hello HardBoiledIndustries,

Are you certain ‘store.target == “amazon”’ and that &nbsp;‘store = require “plugin.amazon.iap”’ are being executed? It may be helpful to have a debugging statement right after ‘require “plugin.amazon.iap”’ to ensure this line is being executed.&nbsp;

Are you selecting ‘Amazon’ for ‘Target App Store’ when building the apk? This is what causes ‘store.target’ to equal ‘amazon’ in your first code snippet from your main.lua.

-Preston

---

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 30, 2013, 5:31am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/5 "2013-07-30T05:31:50Z")

</div>

Thanks Preston, you were correct. &nbsp;I had used this code in my main.lua from the Corona sample on the Amazon Plugin docs

```
store = require "store" if store.target == "amazon" or system.getInfo("environment") == "simulator" then store = require "plugin.amazon.iap"&nbsp; &nbsp;

```

but it looks like store = require “plugin.amazon.iap” never gets executed even though store.target is set to “amazon” when I build. &nbsp; I modified the code to this:

```
if device.isKindle then &nbsp; &nbsp; &nbsp;store = require "plugin.amazon.iap" --covers Android for Amazon store &nbsp; &nbsp; &nbsp;print("using amazon iap plugin") else &nbsp; &nbsp; &nbsp;store = require("store") --covers Apple and Google Play stores &nbsp; &nbsp; &nbsp;print("using regular corona iap") end &nbsp;

```

And now the skus from the amazon.sdktester.json are loading!

FYI, I have a module I require prior to this called “device.lua” where I discover if I’m running on a Kindle or not, so device.isKindle will be true if I’m running on a Kindle and I can then load the correct store. &nbsp;&nbsp;This is actually not a good solution since I want the amazon IAP to work on _any_ android device where the user has used the Kindle store to purchase my app, not just Kindle Fires. &nbsp;I need a way to detect the store.target \_before&nbsp;\_I require store so I know which store to require! &nbsp;Catch 22.

EDIT: &nbsp;oops. &nbsp;Forgot about&nbsp;system.getInfo(“targetAppStore”) &nbsp;That will get me the target app store. &nbsp;so this works well:

```
if system.getInfo("targetAppStore") == "amazon" then &nbsp; &nbsp; store = require "plugin.amazon.iap" --covers Android for Amazon store &nbsp; &nbsp; print("using amazon iap plugin") else &nbsp; &nbsp; store = require("store") --covers Apple and Google Play stores &nbsp; &nbsp; print("using regular corona iap") end &nbsp;

```

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 30, 2013, 7:36am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/6 "2013-07-30T07:36:34Z")

</div>

Beta test update…

I seem to have got it all working. &nbsp;I get the Amazon branded IAP popup for each of my test skus, and purchasing any of the IAP works like the real deal in my app. &nbsp;

A couple minor issues I noticed:

- If the user cancels the purchase by closing the IAP popup, the&nbsp;event.transaction.state seems to be “failed” rather than “cancelled”. &nbsp;&nbsp;
- The valid products table is in alphabetical order based on the title of the sku. &nbsp;This seems to be set automatically in the Amazon IAP dev. console with no way to change it. &nbsp;Google Play store lets me change the display order of the products (In my case I want to show them in price ascending order)

But otherwise seems like IAP for Amazon plugin is working well.

---

<div class="post-metadata">

**Author:** ![tamkinp](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tamkinp](https://forums.solar2d.com/u/tamkinp)\
**Post date:** [July 30, 2013, 4:30pm UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/7 "2013-07-30T16:30:03Z")

</div>

Hello HardBoiledIndustries,

I am happy you found the issue and a solution. ‘store.target’ is working correctly in my testing, but this is a Corona feature so I am unsure as to what your issue could have been.

As for your issues:

1. This is in the documentation. The Amazon IAP SDK does not differentiate between&nbsp; ‘cancelled’ and ‘failed’ purchases

2. Unfortunately the Amazon IAP SDK&nbsp; does not have this same functionality.

-Preston

---

<div class="post-metadata">

**Author:** ![ingemar](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/i/ba9def/32.png) [@ingemar](https://forums.solar2d.com/u/ingemar)\
**Post date:** [July 31, 2013, 12:40am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/8 "2013-07-31T00:40:48Z")

</div>

@hardboiledindustries It’s weird that the code (if store.target == “amazon” then…) isn’t working for you. I’ve used it exclusively throughout my code and it works on all my test devices. I’m on Mac OSX. The only reason I can think of is if during the build of the APK that Amazon wasn’t selected in the dialog, but you say you’ve checked that so I’m a bit stumped.

---

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 31, 2013, 1:56am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/9 "2013-07-31T01:56:59Z")

</div>

Hmmmm, &nbsp;that is weird. &nbsp;I include the plugin in main.lua but I don’t call store.init until later in another module, so maybe my earlier problems were due to some kind of scoping issue? &nbsp;Or perhaps I just did something dumb and fixed it without realizing it. &nbsp;(it was a late night coding session).

---

<div class="post-metadata">

**Author:** ![ingemar](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/i/ba9def/32.png) [@ingemar](https://forums.solar2d.com/u/ingemar)\
**Post date:** [July 31, 2013, 2:14am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/10 "2013-07-31T02:14:39Z")

</div>

It’s sounds like a scoping issue… but I know how late-night coding sessions tend to mess with logic 🙂

---

<div class="post-metadata">

**Author:** ![tamkinp](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tamkinp](https://forums.solar2d.com/u/tamkinp)\
**Post date:** [July 30, 2013, 3:21am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/11 "2013-07-30T03:21:51Z")

</div>

Hello HardBoiledIndustries,

Just a clarification, in the first paragraph you mention ‘store.canLoadProducts’ returns false while later on you mention 'store.loadProducts 'is returning false. Which are you checking? ‘store.loadProducts’ has no return value

The field ‘canLoadProducts’ in the Amazon IAP plugin should indeed always equal true. Can you provide some sample code? Are you certain you are calling ‘store = require “plugin.amazon.iap”’ &nbsp;and ‘store.init( storeListener )’ before calling ‘store.loadProducts()’? It looks like the only way ‘store.canLoadProducts’ will equal ‘true’ is if you are using the Corona store API(instead of the Amazon IAP plugin).

&nbsp;  
&nbsp;

---

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 30, 2013, 4:10am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/12 "2013-07-30T04:10:25Z")

</div>

Hi tamkinp,

That was a typo (I fixed it in my original post). &nbsp;I am indeed checking store.canLoadProducts.

In terms of my code, since I’m doing a cross platform app it is a little messy with if thens to cover all the app stores and slightly different requirements for each, but I’ll snip out some of the relevant parts here:

_EDIT: &nbsp;ugh. &nbsp;This forum editor/tagging really screwed up the indentation of my code when I used the lua tags. &nbsp;Had to revert back to normal text for the lua code parts._

**from build.settings:**

```
&nbsp; &nbsp; &nbsp; &nbsp; ["plugin.amazon.iap"] = { publisherId = "com.amazon",}, --comment out when NOT building for Amazon store? &nbsp; &nbsp; &nbsp; &nbsp; --["CoronaProvider.gameNetwork.google"] = { publisherId = "com.coronalabs", }, -- comment out when building for iOS or Amazon Android, otherwise won't build for iOS. waiting for plugin to be enabled for iOS. &nbsp;App will force quit on Amazon Android version since it can't find google play store. &nbsp;How to do leaderboards on Amazon version? &nbsp; &nbsp; }, &nbsp;

```

**from main.lua:**

–in app purchases in Corona

local store = require(“store”) --covers Apple and Google Play stores

if store.target == “amazon” then&nbsp;

&nbsp; &nbsp; store = require “plugin.amazon.iap” --covers Android for Amazon store

end

**From my IAP scene: &nbsp;This is a little tough to follow but I’ll snip out the relevant bits in the order it runs:**

&nbsp; &nbsp; --initialize the store  
&nbsp; &nbsp; if Component:testNetworkConnection() == true then  
&nbsp; &nbsp; &nbsp; &nbsp; if store.availableStores.apple then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentProductList = appleProductList  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store.init(“apple”, transactionCallback)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“Using Apple’s in-app purchase system.”)  
&nbsp; &nbsp; &nbsp; &nbsp; elseif store.availableStores.google then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentProductList = googleProductList  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store.init(“google”, transactionCallback)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“Using Google’s Google Play Android In-App purchase system.”) &nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; elseif store.target == “amazon” &nbsp;then-- amazon IAP plugin doesn’t support store.availableStores API so need to use store.target  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --amazon store  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentProductList = amazonProductList  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store.init(transactionCallback)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“Using Amazon’s Android In-App purchase system.”) &nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; --elseif &nbsp; &nbsp; &nbsp; &nbsp;then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --TODO add Nook store IAP functionality

&nbsp; &nbsp; &nbsp; &nbsp; elseif isSimulator == true then  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentProductList = simulatorProductList  
&nbsp; &nbsp; &nbsp; &nbsp; else

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“In-app purchases is not supported on this system/device.”)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; native.showAlert(“Store purchases are not supported on this system/device.”,&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { “OK” }, onClose )  
&nbsp; &nbsp; &nbsp; &nbsp; end  
&nbsp; &nbsp; else  
&nbsp; &nbsp; &nbsp; &nbsp; native.showAlert( strings:getString(“alertNoNetworkDetected”), strings:getString(“alertNetworkRequiredForIAP”), { strings:getString(“alertNetworkCloseButton”) }, onClose )  
&nbsp; &nbsp; end  
&nbsp; &nbsp;&nbsp;  
timer.performWithDelay (500, setupMyStore)&nbsp;

**after the 500 ms delay, setupMyStore fires:**

&nbsp; &nbsp; function setupMyStore(event)

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; if store.isActive or isSimulator then

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("store.canLoadProducts = "…tostring(store.canLoadProducts))

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (store.canLoadProducts) then&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; – Property “canLoadProducts” indicates that localized product information such as name and price

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; – can be retrieved from the store (such as iTunes). Fetch all product info here asynchronously.

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store.loadProducts( currentProductList, loadProductsCall

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(“can’t load products, either google play or simulator, or a problem!”)back )

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print (“After store.loadProducts, waiting for callback”)

**if store.canLoadProducts was true then it would continue to my loadProductsCallback function, but it never gets here since it store.canLoadProducts is false for some reason. &nbsp;But here’s the loadProductsCallback anyway:**

&nbsp; &nbsp; function loadProductsCallback( event )

&nbsp; &nbsp; &nbsp; &nbsp; local products = event.products

&nbsp; &nbsp; &nbsp; &nbsp; for i=1, #event.products do&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.products[i].title)&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.products[i].description)&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.products[i].localizedPrice)&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.products[i].productIdentifier)&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; end&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; for i=1, #event.invalidProducts do&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(event.invalidProducts[i])&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; end&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; – save for later use

&nbsp; &nbsp; &nbsp; &nbsp; validProducts = event.products

&nbsp; &nbsp; &nbsp; &nbsp; invalidProducts = event.invalidProducts &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; unpackValidProducts()

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; end

**I also have a transactionCallback function that I know functions correctly for the other app stores, so I won’t include it here, but so far it doesn’t matter since the product ids/skus are not being grabbed from the ones I set up for Amazon.**

**And here is the amazon.sdktester.json file (actual skus removed) I placed on the device inside the&nbsp;…/sdcard/ folder on the device.**

```
{ &nbsp; "...candy101": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 0.99, &nbsp; &nbsp; "title": "Candy Bag", &nbsp; &nbsp; "description": "Big bag with 1,000 pieces of Candy! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; "...candy201": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 1.99, &nbsp; &nbsp; "title": "Candy Bowl", &nbsp; &nbsp; "description": "Large bowl filled with 2,500 pieces of Candy! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; &nbsp; "...candy301": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 2.99, &nbsp; &nbsp; "title": "Candy Wagon", &nbsp; &nbsp; "description": "Huge wagon filled with 7,500 pieces of Candy! Get more and save! &nbsp;TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; &nbsp; "...candy401": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 3.99, &nbsp; &nbsp; "title": "Candy Barrel", &nbsp; &nbsp; "description": "Barrel bursting with 7,500 pieces of Candy! &nbsp;Get more and save! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; &nbsp; "...candy501": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 4.99, &nbsp; &nbsp; "title": "Candy Crate", &nbsp; &nbsp; "description": "Massive crate filled with 10,000 pieces of Candy. &nbsp;A steal! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; }, &nbsp; &nbsp; "...candy601": { &nbsp; &nbsp; "itemType": "CONSUMABLE", &nbsp; &nbsp; "price": 9.99, &nbsp; &nbsp; "title": "Candy Crane", &nbsp; &nbsp; "description": "Construction crane spilling with 25,000 pieces of Candy! &nbsp;Best deal! TEST AMAZON", &nbsp; &nbsp; "smallIconUrl": "http://www.hardboiledindustries.com/page4/files/stacks\_image\_19.png" &nbsp; } } &nbsp;

```

At first I thought perhaps the delayed setupMyStore function was getting called to early, before the store.init fired, but checking the logcat debugging prints I see it is getting called after. &nbsp;Here’s part of the logcat log with my debugging statements:

```
I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Using Amazon's Android In-App purchase system. I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;GameStats:getDisplayAdsState() = false I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;removeBannerAd I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;removing cookie rotate listener I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;store.canLoadProducts = false I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;can't load products (google play or simulator... I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Loading product list I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Product list loaded I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Country: US I/Corona &nbsp;( 4827):&nbsp; I/Corona &nbsp;( 4827): Output string :: &nbsp;&nbsp;&nbsp;&nbsp;Found 6 valid items&nbsp; &nbsp;

```

Thanks for taking a look.

---

<div class="post-metadata">

**Author:** ![tamkinp](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tamkinp](https://forums.solar2d.com/u/tamkinp)\
**Post date:** [July 30, 2013, 4:43am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/13 "2013-07-30T04:43:55Z")

</div>

Hello HardBoiledIndustries,

Are you certain ‘store.target == “amazon”’ and that &nbsp;‘store = require “plugin.amazon.iap”’ are being executed? It may be helpful to have a debugging statement right after ‘require “plugin.amazon.iap”’ to ensure this line is being executed.&nbsp;

Are you selecting ‘Amazon’ for ‘Target App Store’ when building the apk? This is what causes ‘store.target’ to equal ‘amazon’ in your first code snippet from your main.lua.

-Preston

---

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 30, 2013, 5:31am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/14 "2013-07-30T05:31:50Z")

</div>

Thanks Preston, you were correct. &nbsp;I had used this code in my main.lua from the Corona sample on the Amazon Plugin docs

```
store = require "store" if store.target == "amazon" or system.getInfo("environment") == "simulator" then store = require "plugin.amazon.iap"&nbsp; &nbsp;

```

but it looks like store = require “plugin.amazon.iap” never gets executed even though store.target is set to “amazon” when I build. &nbsp; I modified the code to this:

```
if device.isKindle then &nbsp; &nbsp; &nbsp;store = require "plugin.amazon.iap" --covers Android for Amazon store &nbsp; &nbsp; &nbsp;print("using amazon iap plugin") else &nbsp; &nbsp; &nbsp;store = require("store") --covers Apple and Google Play stores &nbsp; &nbsp; &nbsp;print("using regular corona iap") end &nbsp;

```

And now the skus from the amazon.sdktester.json are loading!

FYI, I have a module I require prior to this called “device.lua” where I discover if I’m running on a Kindle or not, so device.isKindle will be true if I’m running on a Kindle and I can then load the correct store. &nbsp;&nbsp;This is actually not a good solution since I want the amazon IAP to work on _any_ android device where the user has used the Kindle store to purchase my app, not just Kindle Fires. &nbsp;I need a way to detect the store.target \_before&nbsp;\_I require store so I know which store to require! &nbsp;Catch 22.

EDIT: &nbsp;oops. &nbsp;Forgot about&nbsp;system.getInfo(“targetAppStore”) &nbsp;That will get me the target app store. &nbsp;so this works well:

```
if system.getInfo("targetAppStore") == "amazon" then &nbsp; &nbsp; store = require "plugin.amazon.iap" --covers Android for Amazon store &nbsp; &nbsp; print("using amazon iap plugin") else &nbsp; &nbsp; store = require("store") --covers Apple and Google Play stores &nbsp; &nbsp; print("using regular corona iap") end &nbsp;

```

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 30, 2013, 7:36am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/15 "2013-07-30T07:36:34Z")

</div>

Beta test update…

I seem to have got it all working. &nbsp;I get the Amazon branded IAP popup for each of my test skus, and purchasing any of the IAP works like the real deal in my app. &nbsp;

A couple minor issues I noticed:

- If the user cancels the purchase by closing the IAP popup, the&nbsp;event.transaction.state seems to be “failed” rather than “cancelled”. &nbsp;&nbsp;
- The valid products table is in alphabetical order based on the title of the sku. &nbsp;This seems to be set automatically in the Amazon IAP dev. console with no way to change it. &nbsp;Google Play store lets me change the display order of the products (In my case I want to show them in price ascending order)

But otherwise seems like IAP for Amazon plugin is working well.

---

<div class="post-metadata">

**Author:** ![tamkinp](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tamkinp](https://forums.solar2d.com/u/tamkinp)\
**Post date:** [July 30, 2013, 4:30pm UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/16 "2013-07-30T16:30:03Z")

</div>

Hello HardBoiledIndustries,

I am happy you found the issue and a solution. ‘store.target’ is working correctly in my testing, but this is a Corona feature so I am unsure as to what your issue could have been.

As for your issues:

1. This is in the documentation. The Amazon IAP SDK does not differentiate between&nbsp; ‘cancelled’ and ‘failed’ purchases

2. Unfortunately the Amazon IAP SDK&nbsp; does not have this same functionality.

-Preston

---

<div class="post-metadata">

**Author:** ![ingemar](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/i/ba9def/32.png) [@ingemar](https://forums.solar2d.com/u/ingemar)\
**Post date:** [July 31, 2013, 12:40am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/17 "2013-07-31T00:40:48Z")

</div>

@hardboiledindustries It’s weird that the code (if store.target == “amazon” then…) isn’t working for you. I’ve used it exclusively throughout my code and it works on all my test devices. I’m on Mac OSX. The only reason I can think of is if during the build of the APK that Amazon wasn’t selected in the dialog, but you say you’ve checked that so I’m a bit stumped.

---

<div class="post-metadata">

**Author:** ![Stephen\_Lewis](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Stephen\_Lewis](https://forums.solar2d.com/u/Stephen_Lewis)\
**Post date:** [July 31, 2013, 1:56am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/18 "2013-07-31T01:56:59Z")

</div>

Hmmmm, &nbsp;that is weird. &nbsp;I include the plugin in main.lua but I don’t call store.init until later in another module, so maybe my earlier problems were due to some kind of scoping issue? &nbsp;Or perhaps I just did something dumb and fixed it without realizing it. &nbsp;(it was a late night coding session).

---

<div class="post-metadata">

**Author:** ![ingemar](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/i/ba9def/32.png) [@ingemar](https://forums.solar2d.com/u/ingemar)\
**Post date:** [July 31, 2013, 2:14am UTC](https://forums.solar2d.com/t/amazon-store-plugin-seems-to-be-loading-but-store-canloadproducts-returns-false-what-am-i-doing-wrong/316312/19 "2013-07-31T02:14:39Z")

</div>

It’s sounds like a scoping issue… but I know how late-night coding sessions tend to mess with logic 🙂
