Initializing Store on Amazon for IAP

Hello!

I’ve worked with IAPs on iTunes and Google Play before and recently, I wanted to try IAPs with Amazon. After reading the docs, I understood that it’s not necessary to pass the target store when calling store.init. However, when I submitted my app to Amazon, this is the error I received:

1.Install and launch the app.
2.Tap on “Get More Coins”.
3.Tap on any of the IAP, an error message stating “This application does not support in-app purchase on this device” appears.

Since this doesn’t have to do with the actual purchase and probably just with starting the store, here’s the code I’m using to detect the store and the code to initialize the store.

local mystore = require "store" if(mystore.target == "amazon") then   store.init(transactionCallback) elseif(mystore.target == "google") then   store.init("google", transactionCallback) else   store.init("apple", transactionCallback) end  

Am I doing something wrote? Should I not be using .target?

Hi Daniel,

Your use of target should be fine, but you are not replacing the ‘mystore’ object with the plugin correctly.

Check out the tutorial: your code should look like this.

local mystore = require "store" if(mystore.target == "amazon") then mystore = require "plugin.amazon.iap" mystore.init(transactionCallback) elseif(mystore.target == "google") then mystore.init("google", transactionCallback) else mystore.init("apple", transactionCallback) end

Thank you! I’m running into other problems now. Here’s the problem I’m running into now:

1.Install and launch the app.
2.Tap on " More Coins".
3.Tap on any of the IAP icons.
4.It displays a run time error message stating “Runtime Error : bad argument#1 purchase”.

Re-reading the tutorial again, it looks like I need the following line:

mystore.loadProducts({“com.thatssopanda.games.mygame”}, loadProductsListener)

below the store init. I’ll try this.
 

Hi Daniel,

loadProducts simply tells you about the available items. This is not a required call.

The error message states that you are not calling purchase() correctly. The Amazon IAP plugin only takes a single string, and not a table.

Try this, from the tutorial:

if system.getInfo("targetAppStore") == "amazon" then store.purchase( "com.acme.superrunner.upgrade" ) else store.purchase( { "com.acme.superrunner.upgrade" } ) end

Hello!

Thank you so much for your responses! You are saving me a huge headache. I can’t believe I missed the curly braces! I’m going to try this out now.

Hi Daniel,

Your use of target should be fine, but you are not replacing the ‘mystore’ object with the plugin correctly.

Check out the tutorial: your code should look like this.

local mystore = require "store" if(mystore.target == "amazon") then mystore = require "plugin.amazon.iap" mystore.init(transactionCallback) elseif(mystore.target == "google") then mystore.init("google", transactionCallback) else mystore.init("apple", transactionCallback) end

Thank you! I’m running into other problems now. Here’s the problem I’m running into now:

1.Install and launch the app.
2.Tap on " More Coins".
3.Tap on any of the IAP icons.
4.It displays a run time error message stating “Runtime Error : bad argument#1 purchase”.

Re-reading the tutorial again, it looks like I need the following line:

mystore.loadProducts({“com.thatssopanda.games.mygame”}, loadProductsListener)

below the store init. I’ll try this.
 

Hi Daniel,

loadProducts simply tells you about the available items. This is not a required call.

The error message states that you are not calling purchase() correctly. The Amazon IAP plugin only takes a single string, and not a table.

Try this, from the tutorial:

if system.getInfo("targetAppStore") == "amazon" then store.purchase( "com.acme.superrunner.upgrade" ) else store.purchase( { "com.acme.superrunner.upgrade" } ) end

Hello!

Thank you so much for your responses! You are saving me a huge headache. I can’t believe I missed the curly braces! I’m going to try this out now.