Easy In App Purchases

The Starters Core kit comes with the Easy IAP module. It is a layer on top of IAP Badger to make it even easier to set up In App Purchases.

Project Settings

Please see the Corona docs for setting up the config.lua and build.settings files.


Basic Usage

Step 1 - Require Once As Global

To simplify using the module, just require it once as a global.

_G.easyIAP = require "easy.iap.easyIAP"

Now, it is available for use everywhere you might want it.

Step 2 - Get IAP IDs

Acquire IDs for all IAP items you intend to sell from the Apple and/or Google Play console.

How to do this is outside the scope of these docs and you are assumed to know how to do this already.

Step 3 - Add Item(s)

Example 1 - No Ads Non-Consumable

local ids = { android = {}, ios = {} }
ids.android.noads       = "com.yourcompany.appname.noads"

ids.ios.noads           = "com.yourcompany.appname.noads"

local os = utils.os()

if( os == "android" or os == "ios" ) then
   easyIAP.addItem( "noads", ids[os].noads, "non-consumable"  )
end

Tip: Use all lower case for ids when you make them and use all lowercase for item names when you add them. This ensures you don't make errors later.

Once this step is complete and once you have initilized the module, two new functions will automatically be available for use:

easyIAP.buy_noads()  - You can call this to buy the 'noads' IAP.
easyIAP.owns_noads() - You can call thos to see if you own the 'noads' IAP.

Example 2 - Consumable Coin Packs

local ids = { android = {}, ios = {} }
ids.android.coins100   = "com.yourcompany.appname.coins100"
ids.android.coins1000  = "com.yourcompany.appname.coins1000"
ids.android.coins5000  = "com.yourcompany.appname.coins5000"

ids.ios.coins100       = "com.yourcompany.appname.coins100"
ids.ios.coins1000      = "com.yourcompany.appname.coins1000"
ids.ios.coins5000      = "com.yourcompany.appname.coins5000"

local os = utils.os()

if( os == "android" or os == "ios" ) then
   easyIAP.addItem( "coins100", ids[os].coins100, "consumable"  )
   easyIAP.addItem( "coins1000", ids[os].coins1000, "consumable"  )
   easyIAP.addItem( "coins5000", ids[os].coins5000, "consumable"  )
end

Tip: Use all lower case for ids when you make them and use all lowercase for item names when you add them. This ensures you don't make errors later.

Once this step is complete and once you have initilized the module, six new functions will automatically be available for use:


-- Buy the items.
easyIAP.buy_coins100()
easyIAP.buy_coins1000()
easyIAP.buy_coins5000()

-- 
easyIAP.owns_coins100()
easyIAP.owns_coins1000()
easyIAP.owns_coins5000()

Step 4 - Initialize Easy Ads

easyIAP.init( 
   {
      salt               = "TypeSomeRandomStringHere",
      testMode           = true,
      doNotLoadInventory = false,
   } )

In this example, we passed three arguments:

Additional arguments you may want to use/pass are:

Lastly, the init() function takes a second argument: onCatalog which references an optional listener. If you provide this argument, IAP badger will query the store and some time later return a table of all known products, names, their IDs, and their localized prices. This information will be passed into the listener as a table.

local function onCatalog( catalog )
   utils.print_r( catalog )
end

easyIAP.init( 
   {
      salt               = "TypeSomeRandomStringHere",
      testMode           = true,
      doNotLoadInventory = false,
   }, onCatalog )

Automatically Generated Functions

As was mentioned above when describing 'adding items', adding a named item automatically creates two functions on the easyAds module.

easyAds.addItem( <name>, storeIAPID ) generates,

Restoring

Finally, any time after initializing, you can attempto to restore all non-consumable items by calling:


RoamingGamer Copyright © Roaming Gamer, LLC. 2008-2018; All Rights Reserved