Android: In App Purchasing doesnt work

Hi,

i want to implement In App  Purchasing but it does not work. In the simulator there is the error “This library is not available on this platform”, that understandable because of the simulator. Now I uploaded a Alpha Test in Google Play Store and test it there. But when i klick on my checkbox nothing happend. Why?

build.settings

settings = { plugins = { ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["CoronaProvider.native.popup.social"] = { -- required publisherId = "com.coronalabs", }, ["plugin.google.iap.v3"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, }, android = { usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", "com.android.vending.BILLING", }, }, }

config.lua

application = { content = { width = 720, height = 1280, scale = "letterbox", xAlign = "left", yAlign = "top" }, license = { google = { key = "my64 Bit code from Google", }, }, }

start.lua

function transactionCallback( event ) -- Log transaction info. print("transactionCallback: Received event " .. tostring(event.name)) print("state: " .. tostring(event.transaction.state)) print("errorType: " .. tostring(event.transaction.errorType)) print("errorString: " .. tostring(event.transaction.errorString)) local productID= event.transaction.productIdentifier; if event.transaction.state == "purchased" then print("Product Purchased: ", productID) checkbox:setState( { isOn= false }) preference.save{adsOnOff = false} elseif event.transaction.state == "restored" then print("Product Restored", productID) elseif event.transaction.state == "refunded" then print("Product Refunded") elseif event.transaction.state == "cancelled" then print("Transaction cancelled") elseif event.transaction.state == "failed" then print("Transaction Failed") else print("Some unknown event occured. This should never happen.") end -- Tell the store we are done with the transaction. -- If you are providing downloadable content, do not call this until -- the download has completed. store.finishTransaction( event.transaction ) end local function purchaseItem(event) --make sure you add { } around your product id as you need to send a table value... not a string! store.purchase( {"packagename + name/Id from Developer Console"}) end local function restorePurchases(event) --no need to sepcify a product store.restore() end function scene:create( event ) local sceneGroup = self.view store.init("google", transactionCallback) print("Using Google's Android In-App Billing system.") local checkboxSheet = graphics.newImageSheet( "checkbox.png", options ) -- Create the widget checkbox = widget.newSwitch( { left = display.contentCenterX \* 1.3, top = display.contentCenterY \* 1.55, style = "checkbox", id = "Checkbox", width = 50, height = 50, onPress = purchaseItem, sheet = checkboxSheet, frameOff = 1, frameOn = 2 } ) checkbox:setState( { isOn= adsOnOff} ) sceneGroup:insert(checkbox ) end

Your store.purchase looks odd
https://docs.coronalabs.com/plugin/google-iap-v3/purchase.html

Scott, I suspect he masked out his purchase for a perceived security need, though doing so does make it harder for people to trouble shoot.

My advice, add more print statements. Use “adb logcat” with no other parameters and look for your prints as well as other messages from the purchasing activity.  You must test this on a device. You cannot in the simulator.

Rob

Ok rob it looked like he was using a table which it should just be a string

Good point.

Your store.purchase looks odd
https://docs.coronalabs.com/plugin/google-iap-v3/purchase.html

Scott, I suspect he masked out his purchase for a perceived security need, though doing so does make it harder for people to trouble shoot.

My advice, add more print statements. Use “adb logcat” with no other parameters and look for your prints as well as other messages from the purchasing activity.  You must test this on a device. You cannot in the simulator.

Rob

Ok rob it looked like he was using a table which it should just be a string

Good point.