Lua
Other Lua files
extlib/iap_badger.lua and extlib/spinner.lua are used. If you want to change the spinner animation during downloading, please edit the spinner.lua.
model.lua - tmplt/components/store/
- please set your host URL of web server to YourHost variable

if model.URL = nil
- this means simple IAP store without network download like Kwik3 IAP
- downloadBtn, savingTxt won’t be used. You don’t need to create them.
local M = {}
--
local IAP = require("components.store.IAP")
--
local YourHost = "http://localhost:8080"
M.URL = YourHost.."/bookShelf/"
M.backgroundImg = "bg.png"
M.bookShelfType = {{bookShelfType}} --{pages = 0, embedded = 1, tmplt=2}
How it works
Shelf.psd is internally handled as page01. Let’s show some codes that creates purchase-buttons for Episode2 and Episode3 automatically.
table of pages
1 | Shelf.psd | table of contents, user to read an episode or to purchase an episode |
2 | ep01.psd | Episode1 |
3 | ep02_info.psd | Episode2 Purchase Information |
4 | ep02_1 | Episode2-1 |
5 | ep02_2 | Episode2-2 |
6 | ep03 | Episode3 |
page_IAP.lua - componens/page01/
- creates instances of displayObject and eventListener of restoreBtn for Episode2 automatically referencing to “restoreBtn” layer
- creates instances of displayObjects and eventListeners of purchase/download/savingTxt/savedBtn for Episode2 automatically referencing to “Episode02Icon” layer
- creates displayObjects and eventListeners of purchase/download/savingTxt/savedBtn for Episode3 automatically referencing to “Episode03Icon” layer

- Episode1 is free and there is no button
- the purchase buttons for Episode2 and Episode3 are created

this UI creation also works for page03 of ep02_info.psd that has “Episode02Icon” layer.
CMD.init
Inside CMD.init calls IAP.init to set up the product table from model.lua. For external codes, you may call the following function to check whether a product has been purchased or not.
- local IAP = require(“components.store.IAP”)
- local productName = “Episode02”
- IAP.getInventoryValue(“unlock_”..productName) returns true or false