Simulator

Simulator & Device Build

Run with Simulator

  • loading main.lua of BookShelfEmbedded with Corona Simulator, clicking purchase text will show up the IAP dialog
  • Files > Show Project Sandbox, you find downloaded zip and bg.png.
  • If you want to refresh the state beginning, delete the files from the Sandbox folders. TemporaryFiles must be cleared because the files from Internet are cached there.

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.

  • App/TOC/components/store/IAP.lua
  • App/TOC/components/store/model.lua

components/store/IAP.lua

  • iapOptions.salt change it as your own text
  • iapOptions.debugMode false for device build
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

  • productNames.apple, productNames.google, productNames.amazon to be set for device build. If not used, make it empty string as ""
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" },
    }
}