It looks like you're new here. If you want to get involved, click one of these buttons!
require "googlebilling" function onRequestPurchaseComplete(event) if (event.responseCode == GoogleBilling.OK) then AlertDialog.new("title","successsfully purchased","ok"):show() -- 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 print(msg) end end -------------------------------------------------- -- GOOGLE Billing -- <a href="http://forum.gideros.rocks/profile/param" rel="nofollow">@param</a> event -- <a href="http://forum.gideros.rocks/profile/return" rel="nofollow">@return</a> -------------------------------------------------- function onPurchaseStateChange(event) AlertDialog.new(event.purchaseState,event.productId,"ok"):show() 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 == "android.test.purchased") then AlertDialog.new("cancelled","android.test.purchased","ok"):show() end elseif (event.purchaseState == GoogleBilling.PURCHASED) then if (event.productId == "your_product_001") then -- unlock -- show Message, item bought elseif (event.productId == "your_product_002") then -- unlock -- show Message, item bought elseif (event.productId == "android.test.purchased") then AlertDialog.new("purchased","android.test.purchased","ok"):show() -- unlock -- show Message, item bought end 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 AlertDialog.new("refunded","android.test.purchased","ok"):show() -- lock or don't unlock end elseif (event.purchaseState == GoogleBilling.EXPIRED) then -- for subscriptions else -- unknown state end googlebilling:confirmNotification(event.notificationId) end googlebilling:setPublicKey("longlongkey") googlebilling:addEventListener(Event.REQUEST_PURCHASE_COMPLETE, onRequestPurchaseComplete) googlebilling:addEventListener(Event.PURCHASE_STATE_CHANGE, onPurchaseStateChange) |
Comments
where is the whole require "googlebilling" etc code is palced?
It is better to place it in main.lua for loading and accessibility purpose
also do you use the same apk file that you uploaded to Google Play?
(the package name and certificate signature must match)/
What I inferred (as obvious as it looks) from these two functions is that onRequestPurchaseComplete is called when you purchase the item, and onPurchaseStateChange is called when the user changes the purchase by cancelling, refunding or some of the other states you can find there. Therefore you won't have that in your tests because you are testing if the item was purchased, not if the user cancelled afterwards, etc. You may do so, but as for testing the purchase itself I think it should be in the other function. However, I've only been able to test it using the "test" item so I might be completely wrong if this changes when using real items.