Quick Questions about IAPs and where to locate their Functions

Hi,

I just started going through the process of adding IAPs to my app, and I’d like to understand some things before I start my coding. I am only using the iOS store, in case that makes any difference in these questions. Here they are:

  1. Should store.init( transactionListener ) only exist in main.lua? (not in the scenes where store.purchase() is called)

  2. Is store.loadProducts() necessary? Since I already know what my productIDs are, do I really have to load their strings from the app store?

  3. If there are multiple IAPs, will they call the same transactionListener function, and will the unique IAP determination be made there? (using transaction.productIdentifier)

  4. Does my app have to do anything with the receipt that is sent from apple in JSON format? 

  5. As far as failed/cancelled transactions, is there anything my app has to do when they occur besides not give the attempted purchase item?

Thanks for all the help! I know there are quite a few questions, but I tried to keep them short so it wouldn’t take too long. If you can’t answer all of them, I’m fine with individual answers.

Thanks again,

Dan

  1. it is up to you

  2. yep it is required by apple

  3. yep, productIdentifier is different

  4. You don’t have to do anything with it. Some people store it for analytics and verifying on a server that is legit ( google it if you are interested server validation apple in app purchase corona sdk site:forums.coronalabs.c…)

5.Nothing you have to do, just notify customer purchase failed.

Rob pointed me out on this. 2. it is not “required” but I you absolutely still should load products.

Let me add some additional context to Scott’s great answers.

  1. store.init() has to be called once, before you use IAP the first time. It’s recommended that you do so in main.lua, since it’s a great place to initialize things. But it’s not a requirement. Sometimes people can try and do too much in main.lua. If you find your startup times are becoming problematic, then you can drop this into a timer or defer it to your menu scene or to your purchase scene if needed.

  2. There isn’t much harm in calling store.loadProducts() and if you ever want your app to run outside of the United States, it’s highly recommended that you do.  That way if someone from Germany is playing, prices will be in Euros, if they are playing from Japan it will be in Yen. Also you can localize the descriptions in the store too which is important if you’re going to support multiple languages. Also you can disable items, add new items after the fact and by loading products you can make some changes to your store without having everyone update, if you plan ahead for that.  For instance, the game I’m tinkering with has products with productIdentifiers like:

com.mydomain.mygame.10000coins

com.mydomain.mygame.50000coins

If I were to add a simple parser to my transactionListener function, then I could add a weekend special:

com.mydomain.mygame.75000coins

and my game would be able to realize it needs to add 75,000 to the bank when it sees that transaction ID. 

  1. Yes, Your one transactionListener function will get all purchases directed to it and you can determine what was purchased using the event.transaction.productIdentifier.

  2. Scott’s right, you don’t have to do anything with it. I believe that both PlayFab and GameSparks have facilities in their plugin/service that can help you implement receipt checking.  

Rob

Thanks for your great answers Scott and Rob! They are very helpful for me. I have one more thing:

I will include store.loadProducts() then. Can this be called in each scene where there is an IAP, or is it only able to be called once in main.lua?

You don’t need load products on every scene. You need to load products to get pricing and currency.

Personally I would defer any network activity that you can until later in your app instead of packing in main.lua. In the game I’m working on, I call load products when I go to my shop scene. You don’t need the data prior to that and loadProducts is a great network based call that can be put of until you need it.

Rob

Ok. I’ll make sure not to put too much in main.lua.

Thanks for all the help Rob and Scott. You’ve allowed me to make a lot of progress this week.

Hi Rob! 

Just wanted to chime in and say this is correct, we can indeed help with receipt checking =)

Clare

  1. it is up to you

  2. yep it is required by apple

  3. yep, productIdentifier is different

  4. You don’t have to do anything with it. Some people store it for analytics and verifying on a server that is legit ( google it if you are interested server validation apple in app purchase corona sdk site:forums.coronalabs.c…)

5.Nothing you have to do, just notify customer purchase failed.

Rob pointed me out on this. 2. it is not “required” but I you absolutely still should load products.

Let me add some additional context to Scott’s great answers.

  1. store.init() has to be called once, before you use IAP the first time. It’s recommended that you do so in main.lua, since it’s a great place to initialize things. But it’s not a requirement. Sometimes people can try and do too much in main.lua. If you find your startup times are becoming problematic, then you can drop this into a timer or defer it to your menu scene or to your purchase scene if needed.

  2. There isn’t much harm in calling store.loadProducts() and if you ever want your app to run outside of the United States, it’s highly recommended that you do.  That way if someone from Germany is playing, prices will be in Euros, if they are playing from Japan it will be in Yen. Also you can localize the descriptions in the store too which is important if you’re going to support multiple languages. Also you can disable items, add new items after the fact and by loading products you can make some changes to your store without having everyone update, if you plan ahead for that.  For instance, the game I’m tinkering with has products with productIdentifiers like:

com.mydomain.mygame.10000coins

com.mydomain.mygame.50000coins

If I were to add a simple parser to my transactionListener function, then I could add a weekend special:

com.mydomain.mygame.75000coins

and my game would be able to realize it needs to add 75,000 to the bank when it sees that transaction ID. 

  1. Yes, Your one transactionListener function will get all purchases directed to it and you can determine what was purchased using the event.transaction.productIdentifier.

  2. Scott’s right, you don’t have to do anything with it. I believe that both PlayFab and GameSparks have facilities in their plugin/service that can help you implement receipt checking.  

Rob

Thanks for your great answers Scott and Rob! They are very helpful for me. I have one more thing:

I will include store.loadProducts() then. Can this be called in each scene where there is an IAP, or is it only able to be called once in main.lua?

You don’t need load products on every scene. You need to load products to get pricing and currency.

Personally I would defer any network activity that you can until later in your app instead of packing in main.lua. In the game I’m working on, I call load products when I go to my shop scene. You don’t need the data prior to that and loadProducts is a great network based call that can be put of until you need it.

Rob

Ok. I’ll make sure not to put too much in main.lua.

Thanks for all the help Rob and Scott. You’ve allowed me to make a lot of progress this week.

Hi Rob! 

Just wanted to chime in and say this is correct, we can indeed help with receipt checking =)

Clare