Hello all. Hopefully someone will be able to help out with this…as I’d like to launch my game soon and this is really the last piece of the puzzle that’s giving me problems.
My game crashes whenever I try to go to the screen with the in-app purchasing…as in it never leaves the screen with my “store” button. However when I comment out the store.init call, it loads up with no problem…but obviously I can’t make any purchases without initializing the store.
I have 3 purchasable items and they are all consumable (game credits basically). So there’s no need for a “restore” as they are all non-managed items.
Here’s the code: (yes, there’s a require(“store”) up at the top of the script that I just didn’t cut and paste here.
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 print("Transaction succuessful!") native.showAlert("Thank you!", "Your support is greatly appreciated!", {"Okay"}) store.finishTransaction( transaction ) elseif tstate == "restored" then print("Transaction restored (from previous session)") store.finishTransaction( transaction ) elseif tstate == "refunded" then print("User requested a refund -- locking app back") store.finishTransaction( transaction ) elseif tstate == "revoked" then -- Amazon feature print ("The user who has a revoked purchase is", transaction.userId) --Revoke this SKU here: 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 if store.availableStores.apple then timer.performWithDelay(1000, function() store.init( "apple", transactionCallback); end) end if store.availableStores.google then timer.performWithDelay( 1000, function() store.init( "google", transactionCallback ); end ) end
The base code is straight out of the in-app purchase tutorial on the Corona site…and I’m not even trying to make purchases yet…since I can’t even get to the screen.
Basically…if I comment out the last section that inits the store…the screen at least loads properly.
Thanks,
Todd