Ok, I removed it entirely and it worked! Thank you everyone!
But how can I test the “refund” state?
Also, unrelated question, but how do I call a composer.gotoscene from the module myData?
Ok, I removed it entirely and it worked! Thank you everyone!
But how can I test the “refund” state?
Also, unrelated question, but how do I call a composer.gotoscene from the module myData?
Just out of curiosity, can you erase and retype the line:
if tstate == “purchased” then
just to make sure there are no weird characters or any thing in there.
Hi, I’m currently having the same problem, the only way for the callback to appear is to cancel the purchase. Whenever I make a purchase with test mode the callback is not called.
Any relevant messages in your device’s console log?
Maybe post some relevant code…
Here is my callback function:
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 successful!") myData.unlockVids(transaction.productIdentifier) native.showAlert("Thank you!", "Your support is greatly appreciated!", {"Okay"}) store.finishTransaction( transaction ) elseif tstate == "restored" then print("Transaction restored (from previous session)") myData.unlockVids(transaction.productIdentifier) utility.saveTable(mySettings, "settings.json") store.finishTransaction( transaction ) elseif tstate == "refunded" then print("User requested a refund -- locking app back") myData.lockVids(transaction.productIdentifier) 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.lockVids(transaction.productIdentifier) 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 goToMenu() print("done with store business for now") end
I’m requiring the store in two different composer scenes, with local. The callback print only appears if I cancel the purchase.
So if you “require()” it twice, then do you also attempt to call “store.init()” twice? If so, are you then defining a different listener function for each instance of the init()?
Best regards,
Brent
Yes, I’m using store.init() on two different composer scenes, but the transactionCallback has the same name in both. Maybe I just need to init the store once in the app?
You should only init once. You should only have one transaction call back function. These should either be in main.lua or alternately in a store module (that’s not a scene) and called from main.lua.
Rob
Thanks! I initialized in main.lua and put the transactioncallback function in another module. Is still not working right. Do I have to in each composer scene that makes a purchase require the store? If so, is it local or not?
Can you post your init code?
Init code?
I put the transactionCallback function in a separate module, one where I do all the inside work, like saving and loading, achievements, etc… (it’s a small app) and I’m now calling it like this:
store.init( "google", myData.transactionCallback )
I tested it a little further and it is now reaching that function whenever I make a purchase. But it’s not executing the code inside the “if tstate == “purchased””
function M.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 text8 = display.newText( "available", 300, 300 , "Calibri", 100 ) 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 print(tstate) --it prints "purchased" if tstate == "purchased" then -- but doesn't reach here print("Transaction succuessful!") print(transaction.productIdentifier) myData.unlockPurchase(transaction.productIdentifier) composer.gotoScene( "menu" ) native.showAlert("Thank you!", "Your support is greatly appreciated!", {"Okay"}) store.finishTransaction( transaction ) elseif tstate == "restored" then print("Transaction restored (from previous session)") myData.unlockPurchase(transaction.productIdentifier) composer.gotoScene( "menu" ) store.finishTransaction( transaction ) elseif tstate == "refunded" then print("User requested a refund -- locking app back") myData.lockVids(transaction.productIdentifier) 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.lockVids(transaction.productIdentifier) 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
You should get a table printing function (see: https://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/))
and print out the event table being passed into the callback function.
Rob
I/Corona (10882): PURCHASE \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* I/Corona (10882): pacote002 I/Corona (10882): \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*In transactionCallback purchase d I/Corona (10882): table: 0x791ef320 { I/Corona (10882): [name] =\> "storeTransaction" I/Corona (10882): [transaction] =\> table: 0x791ef320 { I/Corona (10882): [identifier] =\> "GPA.1324-6945-0148-8986 4" I/Corona (10882): [packageName] =\> "pt.nerdmonkeys.piropos " I/Corona (10882): [receipt] =\> "{"orderId":"GPA.1324-6945- 0148-89864","packageName":"pt.nerdmonkeys.piropos","productId":"pt.nerdmonkeys.p iropos.pacote002","purchaseTime":1438868938078,"purchaseState":0,"purchaseToken" :"jpnnjfdcbomaaafelkahfnab.AO-J1Ox6FITahkXRFMVWlRJZl5lS1EW1\_g9MU3iQVND6AJ1y3-9kq \_gN6z59o3FuTQRneQ3f37FaCMLZAhRHiwz-LTNx84fici9kEeuaQfsBacTMsy2VYlG2LwUW5BvbjEy9v bZCFwDi3w8X1K5j2r765ZxWOkJJ7A"}" I/Corona (10882): [state] =\> "purchased" I/Corona (10882): [originalJson] =\> "{"orderId":"GPA.1324- 6945-0148-89864","packageName":"pt.nerdmonkeys.piropos","productId":"pt.nerdmonk eys.piropos.pacote002","purchaseTime":1438868938078,"purchaseState":0,"purchaseT oken":"jpnnjfdcbomaaafelkahfnab.AO-J1Ox6FITahkXRFMVWlRJZl5lS1EW1\_g9MU3iQVND6AJ1y 3-9kq\_gN6z59o3FuTQRneQ3f37FaCMLZAhRHiwz-LTNx84fici9kEeuaQfsBacTMsy2VYlG2LwUW5Bvb jEy9vbZCFwDi3w8X1K5j2r765ZxWOkJJ7A"}" I/Corona (10882): [token] =\> "jpnnjfdcbomaaafelkahfnab.AO- J1Ox6FITahkXRFMVWlRJZl5lS1EW1\_g9MU3iQVND6AJ1y3-9kq\_gN6z59o3FuTQRneQ3f37FaCMLZAhR Hiwz-LTNx84fici9kEeuaQfsBacTMsy2VYlG2LwUW5BvbjEy9vbZCFwDi3w8X1K5j2r765ZxWOkJJ7A" I/Corona (10882): [productIdentifier] =\> "pt.nerdmonkeys.p iropos.pacote002" I/Corona (10882): [signature] =\> "bRYvIXI32oN2iaTSopKHLqT0 OC9Ydl1BGvta8SOMA/r1Lpgf03IMSJg2ZC7t0BhIz9tz4z6Wsqx9LMoMbnZUILECusYrQiHYQEKbjIyq IcJ0RkoEBW3Y6FZt83wS0/l7k0OqG34d0pFR010IHhhvLB9+0KgCEYs24hsduTV1i/6gZwDHWAO6wb+L i9qTFenm69xEBNzdNPtNuUeYwgUgq9Qnnb3H64e6vzrJB9pq7RtvoVopdnLUUul6B76vwF6YKUnntYTZ 3EVBQMghsOm2NfhbhyR5HfrCbFUnwUfOF1eYrIBRZMHlUpc812s+Z48h3AMjGngBBpYPp0//ctM1Nw== " I/Corona (10882): [type] =\> "inapp" I/Corona (10882): [date] =\> 1438868938078 I/Corona (10882): } I/Corona (10882): }
Ok, so this is what happens when I print the table. The identifier and state are okay. The table printer is before the tsate if’s and it’s still not reaching them. I don’t get “Transaction succuessful!” or the print after the restore check.
Change this line:
if store.availableStores.google and tstate == “purchased” then
store.avalaibleStores.google only works in the older plugin. You will need to do some other test to see if you’re on Google play or not. If you’re not doing Amazon, a simple test of system.getInfo(“platformName”) == “Android” would suffice as the test. I think system.getInfo() may also have a way to get what store it was compiled for.
Rob
That part of the code is only to test if the transaction is a restore or a purchase, it is taken from a tutorial. I’m doing a iOS and android version separately. I tried commenting that part of the code and it still doesn’t reach the if part.
Can you show the debug output again with the “restore checking” code commented out?
It just prints the event table and nothing else (the table is before that part of the code)
Ok, I removed it entirely and it worked! Thank you everyone!
But how can I test the “refund” state?
Also, unrelated question, but how do I call a composer.gotoscene from the module myData?
Just out of curiosity, can you erase and retype the line:
if tstate == “purchased” then
just to make sure there are no weird characters or any thing in there.