I’m trying to implement in-app billing for Android for the first time and would welcome any advice.
First off, do I need to use the in-app billing v3 plug-in or is that now the default?
Then, how’s this as a callback?
Thanks.
function transactionCallback( event ) local transaction = event.transaction if transaction.state == "purchased" then print("Transaction succuessful!") if transaction.productIdentifier == products.packOne then --increment quality of bought item elseif transaction.productIdentifier == products.packTwo then --increment quality of bought item elseif transaction.productIdentifier == products.packThree then --increment quality of bought item elseif transaction.productIdentifier == products.packFour then --increment quality of bought item elseif transaction.productIdentifier == products.packFive then --increment quality of bought item end -- --Do I need a native alert here? local function onComplete( event ) if "clicked" == event.action then local i = event.index if 1 == i then -- Do nothing; dialog will simply dismiss end end end -- Show alert with one button local alert = native.showAlert( "Success!", "Transaction complete.", { "OK"}, onComplete ) -- elseif transaction.state == "refunded" then print ("Refunded", transaction.productIdentifier) if transaction.productIdentifier == products.packFive then --remove refunded product end elseif transaction.state == "restored" then if transaction.productIdentifier == products.packFive then --restore product, iOS only end elseif transaction.state == "cancelled" then -- Do I need a notification here? elseif transaction.state == "failed" then print("Transaction failed, type:", transaction.errorType, transaction.errorString) -- Do I need a notification here? else print("unknown event") end --should this be done with a timer? store.finishTransaction( transaction ) --save data here --update display text end store.init( transactionCallback )