IAP Badger + Composer question

Hey all!  So, I’m tinkering with IAP Badger, which is pretty impressive, but I have a question about using it with Composer scenes.  I am working on an app that checks if various items are unlocked across 6+ scenes, as well as a store scene.  Given this, how should I initialize IAP Badger in my app?  

Should I initialize it in main.lua or include my functions in a separate file and just require it when a scene needs it or is there some other best-practice here?

Would love to see how you all have done it!

Thanks!

If you look in the catalogue table, this contains callbacks (onPurchase, onRefund) that you can use to update your preference file and save the data, so basically the business end of things.  Add this to your main.lua so its always running.  Here is the code from their site:

--Create the catalogue local catalogue = { --Information about the product on the app stores products = { --removeAds is the product identifier. --Always use this identifier to talk to IAP Badger about the purchase. removeAds = { --A list of product names or identifiers specific to apple's App Store or Google Play. productNames = { apple="remove\_ads", google="REMOVE\_BANNER", amazon="Banner\_Remove"}, --The product type productType = "non-consumable", --This function is called when a purchase is complete. onPurchase=function() iap.setInventoryValue("unlock", true) end, --The function is called when a refund is made onRefund=function() iap.removeFromInventory("unlock", true) end, } }, --Information about how to handle the inventory item inventoryItems = { unlock = { productType="non-consumable" } } }

Then in your scenes you can pass a listener to the purchase function, again taken from their site:

--Called when the relevant app store has completed the purchase local function purchaseListener(product) --Save the inventory change iap.saveInventory() --Give the user a message saying the purchase was successful native.showAlert("Info", "Your purchase was successful", {"Okay"}) end --Tell IAP to initiate a purchase iap.purchase("removeAds", purchaseListener)

So in this example you can use the purchase listener to update the UI in your scene(s) to reflect the purchase.

You can also use iap.getInventoryValue() to verify if an item was purchased.

Hopefully that makes some sense?!

Good stuff, Supertap!

So, run iap.init(iapOptions) in main.lua then, too or just initialize then nil it in each scene that I need it?

Initialise it once in main.lua :slight_smile: