Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local store = require("store")
- local listOfProducts = {
- "com.yourcompany.app.productID",
- }
- ----------------------------------
- -- In-App area
- ----------------------------------
- local validProducts, invalidProducts = {}, {}
- function unpackValidProducts()
- print ("Loading product list")
- if not validProducts then
- native.showAlert( "In-App features not available", "initStore() failed", { "OK" } )
- else
- for i=1, #invalidProducts do
- native.showAlert( "Item " .. invalidProducts[i] .. " is invalid.",{ "OK" } )
- end
- end
- end
- function loadProductsCallback( event )
- validProducts = event.products
- invalidProducts = event.invalidProducts
- unpackValidProducts ()
- end
- function savePurchase(product)
- --function on what should be save when user buy a product
- end
- function transactionCallback( event )
- if event.transaction.state == "purchased" then
- savePurchase("product") --you should enter here the product being purchased
- elseif event.transcation.state == "restored" then
- savePurchase("product") --you should enter here the product being purchased
- elseif event.transaction.state == "cancelled" then
- elseif event.transaction.state == "failed" then
- infoString = "Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString
- local alert = native.showAlert("Failed ", infoString,{ "OK" })
- else
- infoString = "Unknown event"
- local alert = native.showAlert("Unknown ", infoString,{ "OK" })
- end
- store.finishTransaction( event.transaction )
- end
- function setupMyStore (event)
- store.loadProducts( listOfProducts, loadProductsCallback )
- end
- local onbuyButTouch = function(event)
- if event.phase=="ended" then
- local buyThis = function ( product )
- if store.canMakePurchases then
- store.purchase( {product} )
- else
- native.showAlert("Store purchases are not available, please try again later", { "OK" } )
- end
- end
- -- Enter your product id here
- store.init(transactionCallback)
- timer.performWithDelay (1000, setupMyStore)
- buyThis ("com.youcompany.app.productID")
- end
- end
- buyBut = ui.newButton{
- defaultSrc="p1_buyBut.png",
- defaultX = 272,
- defaultY = 68,
- overSrc="p1_buyBut.png",
- overX = 272,
- overY = 68,
- onRelease=onbuyButTouch,
- id="buyButButton"
- }
Add Comment
Please, Sign In to add comment