Thanks for the name change
Here’s some of my code:
if(_LOCKED)then
if ( system.getInfo( “platformName” ) == “Android” ) then
store = require( “plugin.google.iap.v3” )
v3 = true
elseif ( system.getInfo( “platformName” ) == “iPhone OS” ) then
store = require( “store” )
else
--native.showAlert( “Notice”, “In-app purchases are not supported in the Corona Simulator.”, { “OK” } )
end
function transactionCallback( event )
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 (system.getInfo( “platformName” ) == “Android” and tstate == “purchased”) then
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.
tstate = “restored”
restoring = false
end
end
if tstate == “purchased” then
native.showAlert( “Purchase success”, “Purchase complete, app now unlocked”, { “OK” } )
mySettings.isPaid = true
utility.saveTable(mySettings, “settings.json”)
elseif tstate == “restored” then
native.showAlert( “Purchase restored”, “Purchase restored, app now unlocked”, { “OK” } )
mySettings.isPaid = true
utility.saveTable(mySettings, “settings.json”)
elseif tstate == “cancelled” then
native.showAlert( “Purchase was cancelled”, “App remains locked”, { “OK” } )
elseif tstate == “failed” then
print(“Transaction failed, type:”, transaction.errorType, transaction.errorString)
native.showAlert( "Error: "…transaction.errorType, transaction.errorString, { “OK” } )
else
print(“unknown event”)
end
store.finishTransaction( transaction )
end
if ( system.getInfo( “platformName” ) == “iPhone OS” ) then
store.init( “apple”, transactionCallback)
end
if ( system.getInfo( “platformName” ) == “Android” ) then
store.init( “google”, transactionCallback )
– doing a store.restore() here freezes the app
end
end
– later in the app in some button listeners I call
store.purchase( “android.test.purchased” ) --test
– and
store.restore() --results in app crash no matter if it’s at app start or in button listener
just in case this helps here is my config.lua:
application = {
content = {
width = 320,
height = 480,
scale = “letterbox”,
fps = 60
–[[
imageSuffix = {
["@2x"] = 2,
}
–]]
},
license =
{
google =
{
key = “my license key is here”,
},
},
launchPad = false,
}
and my build.settings:
settings = {
orientation = {
default = “landscapeRight”,
supported = { “landscapeRight”, }
},
iphone = {
plist = {
UIStatusBarHidden = false,
UIPrerenderedIcon = true, – set to false for “shine” overlay
–UIApplicationExitsOnSuspend = true, – uncomment to quit app on suspend
--[[
– iOS app URL schemes:
CFBundleURLTypes =
{
{
CFBundleURLSchemes =
{
“fbXXXXXXXXXXXXXX”, – example scheme for facebook
“coronasdkapp”, – example second scheme
}
}
}
--]]
}
},
android =
{
usesPermissions =
{
“android.permission.INTERNET”,
“com.android.vending.BILLING”,
“com.android.vending.CHECK_LICENSE”,
}
},
plugins =
{
[“plugin.google.iap.v3”] =
{
publisherId = “com.coronalabs”,
supportedPlatforms = { android=true }
},
}
}
thanks!