Hi Rob,
Here’s the actual code I’m using right now:
display.setStatusBar(display.HiddenStatusBar) -- hide the status bar display.setDefault("background", 0, 0, 0) -- set the background color of the screen to white --- Required for button local widget = require "widget" -----HANDLE ANDROID PURCHASES------ local function inAppPopUp(theState) if theState == "purchased" then native.showAlert("Purchase Window", "Purchase Successful!") elseif theState == "restored" then native.showAlert("Restored Window", "Restore Successful!") elseif theState == "refunded" then native.showAlert("Refunded Window", "Refund Successful!") elseif theState == "cancelled" then native.showAlert("Cancelled Window", "Cancelled!") elseif theState == "failed" then native.showAlert("Failed Window", "Failed!") end end local function transactionCallback(event) local transaction = event.transaction if transaction.state == "purchased" then -- Transaction was successful; unlock/download content now inAppPopUp(transaction.state) elseif transaction.state == "restored" then -- You\'ll never reach this transaction state on Android. elseif transaction.state == "refunded" then -- Android-only; user refunded their purchase --local productId = transaction.productIdentifier inAppPopUp(transaction.state) -- Restrict/remove content associated with above productId now elseif transaction.state == "cancelled" then -- Transaction was cancelled; tell you app to react accordingly here inAppPopUp(transaction.state) elseif transaction.state == "failed" then -- Transaction failed; tell you app to react accordingly here inAppPopUp(transaction.state) end -- The following must be called after transaction is complete. -- If your In-app product needs to download, do not call the following -- function until AFTER the download is complete: store.finishTransaction(event.transaction) end --- Android inApp purchase initialization local store = require("store") store.init("google", transactionCallback) --- Add button local onButtonEvent = function(event) store.purchase( { "purchase\_test" } ) end local myButton = widget.newButton{ id = "btn001", left = 100, top = 200, label = "Widget Button", width = 150, height = 28, cornerRadius = 8, onEvent = onButtonEvent }
“purchase_test” is the name of the in app product I added in my google play developer console. The price was set at .99 cents and the transaction was successful on Google’s side because my credit card was charged for the purchase, but my transaction callback returned a “failed” event. If I use Google’s “android.test.purchased” then it works and it returns a “purchased” event.
I’m not sure if Corona isn’t receiving confirmations from Google properly or if store.finishTransaction is not working properly. Again I’m using daily build 1054.