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 )
You don’t need to use the v3 plugin unless you need to load your products from the server to get localized prices. However, there doesn’t seem to be a reason to not use the v3 plugin.
I’m not sure if this is a version number mismatch (I’m using a signed APK with the same version number as a published v2 version) or whether v3 code needs to handle the callback differently. I tried a v3 build with a new version number uploaded as an alpha test but it had the same issue…it may be I have to wait a few hours for the alpha to register with Google Play so it can be used to test in-app billing.
That was it. Thanks. It should have been obvious but I was affected by bracket blindness. Part of the problem was I was calling store.purchase{} without the parentheses so the brackets didn’t stand out as a table.
You don’t need to use the v3 plugin unless you need to load your products from the server to get localized prices. However, there doesn’t seem to be a reason to not use the v3 plugin.
I’m not sure if this is a version number mismatch (I’m using a signed APK with the same version number as a published v2 version) or whether v3 code needs to handle the callback differently. I tried a v3 build with a new version number uploaded as an alpha test but it had the same issue…it may be I have to wait a few hours for the alpha to register with Google Play so it can be used to test in-app billing.
That was it. Thanks. It should have been obvious but I was affected by bracket blindness. Part of the problem was I was calling store.purchase{} without the parentheses so the brackets didn’t stand out as a table.