Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Google inApp onPurchaseStateChange — Gideros Forum

Google inApp onPurchaseStateChange

arcadiaarcadia Member
edited March 2013 in General questions
The in-app purchase don't work for me.
I've tryed with android.test.purchased and with real product and onRequestPurchaseComplete is always called but onPurchaseStateChange is NEVER CALLED! I've tryed with real products and money...google send me the e-mail that confirm the purchase, my money in my credit card was taken but onPurchaseStateChange is never called! Why?
Here my code taken in a post in this forum:
require "googlebilling"
 
--------------------------------------------------
-- GOOGLE Billing
-- <a href="http://forum.giderosmobile.com/profile/param" rel="nofollow">@param</a> event
-- <a href="http://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="http://forum.giderosmobile.com/profile/param" rel="nofollow">@param</a> event
-- <a href="http://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)

Dislikes: AhBadiane, zoolax

+1 -1 (+0 / -2 )Share on Facebook

Comments

Sign In or Register to comment.