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:
Should store.init( transactionListener ) only exist in main.lua? (not in the scenes where store.purchase() is called)
Is store.loadProducts() necessary? Since I already know what my productIDs are, do I really have to load their strings from the app store?
If there are multiple IAPs, will they call the same transactionListener function, and will the unique IAP determination be made there? (using transaction.productIdentifier)
Does my app have to do anything with the receipt that is sent from apple in JSON format?
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.
Let me add some additional context to Scott’s great answers.
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.
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.
Yes, Your one transactionListener function will get all purchases directed to it and you can determine what was purchased using the event.transaction.productIdentifier.
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.
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.
Let me add some additional context to Scott’s great answers.
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.
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.
Yes, Your one transactionListener function will get all purchases directed to it and you can determine what was purchased using the event.transaction.productIdentifier.
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.
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.