Last Modified: 2022-08-27

Simulator & Device Build

Run with Simulator

Build for device

After everything all right with simulator, turn off debug mode IAP.lua and set the valid product IDs of apple, google or amazon in the following lua files of BookShelfTOC project. You may edit the files in App/TOC.

components/store/IAP.lua

function M:init(catalogue, restoreAlert, purchaseAlert)
    print("iap init")
    self.catalogue       = catalogue
    self.restoreAlert  = restoreAlert
    self.purchaseAlert = purchaseAlert

    local iapOptions = {
        catalogue         = catalogue,
        filename          = "episodes_inventory.txt",
        --Salt for the hashing algorithm
        salt              = "something tr1cky to gue55!",
        failedListener    = failedListener,
        cancelledListener = failedListener,
        --Once the product has been purchased, it will remain in the inventory.  Uncomment the following line
        --to test the purchase functions again in future.  It's also useful for testing restore purchases.
        --doNotLoadInventory=true,
        debugMode        = true,
    }
    iap.init(iapOptions)
    print("iap init end")
end

components/store/model.lua

M.catalogue = {
    products = {
            Episode02 = {
            productNames = { apple="Episode02_apple", google="Episode02_googgle", amazon="Episode02_amazon"},
            productType  = "non-consumable",
            onPurchase   = function() IAP.setInventoryValue("unlock_Episode02") end,
            onRefund     = function() IAP.removeFromInventory("unlock_Episode02") end,
        },
            Episode03 = {
            productNames = { apple="Episode03_apple", google="Episode03_googgle", amazon="Episode03_amazon"},
            productType  = "non-consumable",
            onPurchase   = function() IAP.setInventoryValue("unlock_Episode03") end,
            onRefund     = function() IAP.removeFromInventory("unlock_Episode03") end,
        },
    },
    inventoryItems = {
            unlock_Episode02 = { productType="non-consumable" },
            unlock_Episode03 = { productType="non-consumable" },
    }
}