It looks like you're new here. If you want to get involved, click one of these buttons!
require "googlebilling" -------------------------------------------------- -- GOOGLE Billing -- <a href="https://forum.giderosmobile.com/profile/param" rel="nofollow">@param</a> event -- <a href="https://forum.giderosmobile.com/profile/return" rel="nofollow">@return</a> -------------------------------------------------- local function onRequestPurchaseComplete(event) if (event.responseCode == GoogleBilling.OK) then msg="ok" -- transaction has been sent to google (thanks Atilim) -- don't unlock items here else local msg = "purchase failed" if (event.responseCode == GoogleBilling.USER_CANCELED) then msg = "GoogleBilling.USER_CANCELED" end if (event.responseCode == GoogleBilling.SERVICE_UNAVAILABLE) then msg = "GoogleBilling.SERVICE_UNAVAILABLE" end if (event.responseCode == GoogleBilling.BILLING_UNAVAILABLE) then msg = "GoogleBilling.BILLING_UNAVAILABLE" end if (event.responseCode == GoogleBilling.ITEM_UNAVAILABLE) then msg = "GoogleBilling.ITEM_UNAVAILABLE" end if (event.responseCode == GoogleBilling.DEVELOPER_ERROR) then msg = "GoogleBilling.DEVELOPER_ERROR" end if (event.responseCode == GoogleBilling.ERROR) then msg = "GoogleBilling.ERROR" end end end -------------------------------------------------- -- GOOGLE Billing -- <a href="https://forum.giderosmobile.com/profile/param" rel="nofollow">@param</a> event -- <a href="https://forum.giderosmobile.com/profile/return" rel="nofollow">@return</a> -------------------------------------------------- local function onPurchaseStateChange(event) if (event.purchaseState == GoogleBilling.CANCELED) then if (event.productId == "your_product_001") then -- lock or don't unlock elseif (event.productId == "your_product_002") then -- lock or don't unlock elseif (event.productId == "test_001") then -- lock or don't unlock elseif (event.productId == "android.test.purchased") then -- lock or don't unlock end elseif (event.purchaseState == GoogleBilling.PURCHASED) then if (event.productId == "c001") then gameSaved.coin = gameSaved.coin + 250 dataSaver.saveValue("gameSaved", gameSaved) elseif (event.productId == "c002") then gameSaved.coin = gameSaved.coin + 500 dataSaver.saveValue("gameSaved", gameSaved) elseif (event.productId == "p001") then gameSaved.polipo = gameSaved.polipo + 50 dataSaver.saveValue("gameSaved", gameSaved) elseif (event.productId == "p002") then gameSaved.polipo = gameSaved.polipo + 100 dataSaver.saveValue("gameSaved", gameSaved) elseif (event.productId == "b001") then gameSaved.coin = gameSaved.coin + 500 gameSaved.polipo = gameSaved.polipo + 100 dataSaver.saveValue("gameSaved", gameSaved) end sceneManager:changeScene("store", 0, transition) elseif (event.purchaseState == GoogleBilling.REFUNDED) then if (event.productId == "your_product_001") then -- lock or don't unlock elseif (event.productId == "your_product_002") then -- lock or don't unlock elseif (event.productId == "android.test.purchased") then -- lock or don't unlock end elseif (event.purchaseState == GoogleBilling.EXPIRED) then -- for subscriptions else -- unknown state end googlebilling:confirmNotification(event.notificationId) end -- maybe it better to modify original publicKey by XOR or split into parts as google suggests if premium=="si" then googlebilling:setPublicKey("myrealkey") else googlebilling:setPublicKey("myrealkey") end googlebilling:addEventListener(Event.REQUEST_PURCHASE_COMPLETE, onRequestPurchaseComplete) googlebilling:addEventListener(Event.PURCHASE_STATE_CHANGE, onPurchaseStateChange) |
Comments
Likes: ar2rsawseen
https://play.google.com/store/apps/developer?id=Arcadia Solutions
I have the exact same problem, and i just tried your solution. Moved all the code to main.lua, i had it in my menu.lua.
But i still have the googlebilling:requestPurchase("android.test.purchased") line in menu.lua
Is this the problem?
I'm testing it on my Nexus 7.
onPurchaseStateChange doesn't get called ever.
You have to compile and install the apk on your device
https://play.google.com/store/apps/developer?id=Arcadia Solutions
No, i was trying on my device.
To make it work I had to first upload the app APK to the developer portal.
As suggested here:
http://www.giderosmobile.com/forum/discussion/2258/how-to-add-android-inapp-purchases
After that Event.PURCHASE_STATE_CHANGE is working. It seems Google Play checks package name and key public of app to send its response and generate response Events.
I use then same Gideros Android Player but installed in my real device to test billing from lua and Gideros Studio.