Page Lock&Unlock with In App Purchase

In App Purchase

Preposition: Before you start this tutorial, create an IAP setting in iTune Connect/Apple Developer service or Google Play Developer console or Amazon developer service.

how to setup an IAP configuration

Please read Montization page and iap tools section too

In App Purchase - Adding Products

From Monetization tab, choose Simple Unlock as In-APP type,

then please click plus(+) icon to add a product

Register a product name and ID by clicking pluse icon. Dummy IDs are OK. Later you set official IDs from apple, google or amazon in components/store/model.lua and build the app for device testing. Device testing allows you to connect to App store APIs with the sandbox environment.

Latest Kwik4 has each ID field of apple, google and amazon

For example, an officail product ID should be like this

Page Properites

You can specify the page to be locked from page properites

go down to In-App Unlock section

Set the product name and redirect page

Page structures

when user tries to go to page 3 from page 2 by swipping the screen, Kwik shows the page 3 for a second and instantly rewinds back to page2.

So page 4 is completely hidden but page 3, user can see the content for a moment.

Unlock & Restore Button

You need these two buttons. Restore button works if user renew his/her device or uninstall and re-install the app, and the purchased items are retrived from the database of Apple store.

Montization > Buy Product

Montization > Restore Product

Build for device

setting official product IDs

In components/store/model.lua, please set the product ID from Apple, Google and Amazon in model.lua.

iap tools section describes how to configure IAP products in their developer sites.

For example, “com.kwiksher.bookshelf.book01” is the prodcut id of iTune store.

M.catalogue = {
    products = {
            test = {
            productNames = { apple="com.kwiksher.bookshelf.book01", google="test_googgle", amazon="test_amazon"},
            productType  = "non-consumable",
            onPurchase   = function() IAP.setInventoryValue("unlock_test") end,
            onRefund     = function() IAP.removeFromInventory("unlock_test") end,
    inventoryItems = {
            unlock_test = { productType="non-consumable" },

you may set “consumable” to productType if you desire. Please read the iap badger document.

debug mode false

In components/store/model.lua, please change debug to false

local M = {}
local IAP             = require("")
M.bookShelfType  = 0 --{none = -1, pages = 0, embedded = 1, tmplt=2}
M.debug     = true

In components/store/IAP.lua, please change the text in salt field.

function M:init(catalogue, restoreAlert, purchaseAlert)
    local iapOptions = {
        catalogue         = catalogue,
        filename          = "epsodes_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.
        debugMode        = debug,

Now Build for Device in Corona Simulator. Choose Code Signing Signature(iOS) or keystore(Android) for your IAP app. Don’t use normal debug signature or key store.

If user reaches the locked page, the dialog pops up. This comes from system, you don’t need to create it.

The purchase button will brign up the confirmation dialog too.