Hi,
I am implementing in-app purchases in my app.
So, I read the tutorial “Understanding In-App purchases”:
https://coronalabs.com/blog/2013/09/03/tutorial-understanding-in-app-purchases/
Today, I tried the code in my app but I code an error line 32.
Here is the message I get:
And I don’t understand how to fix it.
local store = require( "store" ) local utility = require( "utility" ) local mySettings local restoring mySettings = utility.loadTable("settings.json") if mySettings == nil then mySettings = {} mySettings.isPaid = false utility.saveTable(mySettings, "settings.json") end local function transactionCallback( event ) print("In transactionCallback", event.transaction.state) local transaction = event.transaction local tstate = event.transaction.state -- --Google does not return a "restored" state when you call store.restore() --You're only going to get "purchased" with Google. This is a work around --to the problem. -- --The assumption here is that any real purchase should happen reasonably --quick while restores will have a transaction date sometime in the past. --5 minutes seems sufficient to separate a purchase from a restore. -- if store.availableStores.google and tstate == "purchased" then local tdate = math.floor( transaction.date /1000 ) local timeStamp = utility.makeTimeStamp(transaction.date,"ctime") if timeStamp + 360 < os.time() then -- if the time stamp is older than 5 minutes, we will assume a restore. print("map this purchase to a restore") tstate = "restored" print("I think tstate is ", tstate) restoring = false end end if tstate == "purchased" then print("Transaction succuessful!") mySettings.isPaid = true utility.saveTable(mySettings, "settings.json") native.showAlert("Thank you!", "Your support is greatly appreciated!", {"Okay"}) store.finishTransaction( transaction ) elseif tstate == "restored" then print("Transaction restored (from previous session)") mySettings.isPaid = true utility.saveTable(mySettings, "settings.json") store.finishTransaction( transaction ) elseif tstate == "refunded" then print("User requested a refund -- locking app back") mySettings.isPaid = false utility.saveTable(mySettings, "settings.json") store.finishTransaction( transaction ) elseif tstate == "revoked" then -- Amazon feature print ("The user who has a revoked purchase is", transaction.userId) --Revoke this SKU here: mySettings.isPaid = false utility.saveTable(mySettings, "settings.json") elseif tstate == "cancelled" then print("User cancelled transaction") store.finishTransaction( transaction ) elseif tstate == "failed" then print("Transaction failed, type:", transaction.errorType, transaction.errorString) store.finishTransaction( transaction ) else print("unknown event") store.finishTransaction( transaction ) end print("done with store business for now") end local function loadProductsListener( event ) print("In loadProductsListener") local products = event.products for i=1, #event.products do print(event.products[i].title) print(event.products[i].description) print(event.products[i].localizedPrice) print(event.products[i].productIdentifier) end for i=1, #event.invalidProducts do print(event.invalidProducts[i]) end end if system.getInfo("targetAppStore") == "amazon" then store = require "plugin.amazon.iap" store.init( transactionCallback ) print("The currently logged in user is: ", store.getUserId()) store.loadProducts({"com.yourcompany.yourapp"}, loadProductsListener) store.restore() else if store.availableStores.apple and not mySettings.isPaid then timer.performWithDelay(1000, function() store.init( "apple", transactionCallback); end) end if store.availableStores.google and not mySettings.isPaid then timer.performWithDelay( 1000, function() store.init( "google", transactionCallback ); restoring = true; store.restore(); end ) end end
Thanks in advance for you replies
Pierre