I’ve tried to purchase a product, when success, the apps does nothing! Not even the “transactionCallBack” triggered! I put a native.showalert inside the function for checking the tstate, however not a single code after succesfull purchase was executed! Simply, nothing! But when I try to purchase again, it’s triggered “failed” and cannot purchased that “managed product”… other than success purchase or restore(), “trasactionCallBack” works nice! :’( Why this can happen? any clue?
Still didn’t have any clue at all… I did follow according to the tutorial, however, it can purchase only, after “Payment sucessful”, it didn’t call the transactionCallBack() at all
local restoring -- STORE -- -- 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 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 native.showAlert("Transaction", "Your Status is : "..tstate, {"Okay"}) -- \<\< THIS LINE DIDN'T Executed :(, I think this callBack didn't called after purchase successed.. if tstate == "purchased" then print("Transaction succuessful!") --myData.settings.isPaid = true myData.settings.premiumChara[transaction.productIdentifier] = true utility.saveTable(myData.settings, "settings.json") native.showAlert("Thank you!", "Your support is greatly appreciated! -"..transaction.originalDate, {"Okay"}) store.finishTransaction( transaction ) elseif tstate == "restored" then print("Transaction restored (from previous session)") --myData.settings.isPaid = true myData.settings.premiumChara[transaction.productIdentifier] = true utility.saveTable(myData.settings, "settings.json") store.finishTransaction( transaction ) elseif tstate == "refunded" then print("User requested a refund -- locking app back") --myData.settings.isPaid = false myData.settings.premiumChara[transaction.productIdentifier] = false utility.saveTable(myData.settings, "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: --myData.settings.isPaid = false myData.settings.premiumChara[transaction.productIdentifier] = false utility.saveTable(myData.settings, "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 store.init("google", transactionCallback) store.restore() -- Is this function really call transactionCallback() ? function scene:create( event ) local sceneGroup = self.view . . . local function handleBuyChara(event) if event.phase == "began" then event.target:setLabel("Purchasing...") elseif event.phase == "ended" then --event.target:setLabel("...") if system.getInfo("targetAppStore") == "amazon" or system.getInfo("targetAppStore") == "google" then store.purchase(listProdukTS[myData.settings.lastselectedchara]) else store.purchase( { listProdukTS[myData.settings.lastselectedchara] } ) end print("Product processed: "..listProdukTS[myData.settings.lastselectedchara]) end return true end local tmbPurchase = widget.newButton({ id = "tmbPurchase", label = "Buy", defaultFile = "btn.png", overFile = "btnHover.png", font = native.systemFontBold, fontSize = 20, width = 80, height = 40, onEvent = handleBuyChara }) tmbPurchase.x = display.contentCenterX tmbPurchase.y = display.contentCenterY - 100 sceneGroup:insert(6, tmbPurchase ) ,,,,,
I confused… @.@a… thx for reply!
So far, I think I did what the docs and tutorial say…
Do you get this when testing on both iOS and Google Play devices?
(By the way, I think you’re getting fails on your subsequent purchases because, on Google Play at least, your app has to consume a managed product before it can be purchased again. I think this was something introduced into the Google Play API after the tutorial you are following was published).
I didn’t have an Apple Device. Also, the problem is :
the apps does nothing! Not even the “transactionCallBack” triggered!
As I said, nothing is triggered after “purchased” status appear from google API. So, even if it is managed or un-managed product, it’s just the same problem, I can’t (for example) increase player “gold” or give them “upgrade” inside the game, since the game didn’t trigger the call back after the purchase…
I got confused, why my code didn’t call the callBack function? :’(
Still didn’t have any clue at all… I did follow according to the tutorial, however, it can purchase only, after “Payment sucessful”, it didn’t call the transactionCallBack() at all
local restoring -- STORE -- -- 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 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 native.showAlert("Transaction", "Your Status is : "..tstate, {"Okay"}) -- \<\< THIS LINE DIDN'T Executed :(, I think this callBack didn't called after purchase successed.. if tstate == "purchased" then print("Transaction succuessful!") --myData.settings.isPaid = true myData.settings.premiumChara[transaction.productIdentifier] = true utility.saveTable(myData.settings, "settings.json") native.showAlert("Thank you!", "Your support is greatly appreciated! -"..transaction.originalDate, {"Okay"}) store.finishTransaction( transaction ) elseif tstate == "restored" then print("Transaction restored (from previous session)") --myData.settings.isPaid = true myData.settings.premiumChara[transaction.productIdentifier] = true utility.saveTable(myData.settings, "settings.json") store.finishTransaction( transaction ) elseif tstate == "refunded" then print("User requested a refund -- locking app back") --myData.settings.isPaid = false myData.settings.premiumChara[transaction.productIdentifier] = false utility.saveTable(myData.settings, "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: --myData.settings.isPaid = false myData.settings.premiumChara[transaction.productIdentifier] = false utility.saveTable(myData.settings, "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 store.init("google", transactionCallback) store.restore() -- Is this function really call transactionCallback() ? function scene:create( event ) local sceneGroup = self.view . . . local function handleBuyChara(event) if event.phase == "began" then event.target:setLabel("Purchasing...") elseif event.phase == "ended" then --event.target:setLabel("...") if system.getInfo("targetAppStore") == "amazon" or system.getInfo("targetAppStore") == "google" then store.purchase(listProdukTS[myData.settings.lastselectedchara]) else store.purchase( { listProdukTS[myData.settings.lastselectedchara] } ) end print("Product processed: "..listProdukTS[myData.settings.lastselectedchara]) end return true end local tmbPurchase = widget.newButton({ id = "tmbPurchase", label = "Buy", defaultFile = "btn.png", overFile = "btnHover.png", font = native.systemFontBold, fontSize = 20, width = 80, height = 40, onEvent = handleBuyChara }) tmbPurchase.x = display.contentCenterX tmbPurchase.y = display.contentCenterY - 100 sceneGroup:insert(6, tmbPurchase ) ,,,,,
I confused… @.@a… thx for reply!
So far, I think I did what the docs and tutorial say…
Do you get this when testing on both iOS and Google Play devices?
(By the way, I think you’re getting fails on your subsequent purchases because, on Google Play at least, your app has to consume a managed product before it can be purchased again. I think this was something introduced into the Google Play API after the tutorial you are following was published).
I didn’t have an Apple Device. Also, the problem is :
the apps does nothing! Not even the “transactionCallBack” triggered!
As I said, nothing is triggered after “purchased” status appear from google API. So, even if it is managed or un-managed product, it’s just the same problem, I can’t (for example) increase player “gold” or give them “upgrade” inside the game, since the game didn’t trigger the call back after the purchase…
I got confused, why my code didn’t call the callBack function? :’(