Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Android InApp Purchases and Public Key — Gideros Forum

Android InApp Purchases and Public Key

RadieselRadiesel Member
edited December 2012 in General questions
Hi folks,

I successfully implemented InApp purchases for Android. What a stupid thing compared with iOS. I can share my experiences and problems if somebody has a needs for it.

However, I still have a question regarding GoogleBilling:setPublicKey(publicKey). I read several Pages on google, but wasn't able to fully understand the need of this function. Can anyone explain? InApp purchases still work without calling this function.

thanks in advance!
Michael

«1

Comments

  • Hi @Radiesel .Even at google search result there is nothing directly related to setPublicKey method :) and google suggest that "Did you mean: Google Billing getPublicKey ". Are you sure that getPublicKey is not absolute or not implemented.
  • ar2rsawseenar2rsawseen Maintainer
    edited December 2012
    @Radiesel I think many on forum would want to see a step by step tutorials and prerequisites. :)
  • gorkemgorkem Maintainer
    @radiesel yes yes yes! Please share your findings with the community <:-P
  • atilimatilim Maintainer
    You can find some information about public key here: http://developer.android.com/google/play/billing/v2/billing_integrate.html

    > What a stupid thing compared with iOS.
    Exactly :) I've read these pages https://developer.android.com/google/play/billing/index.html again and again to grasp the logic behind. And probably now I've forgotten everything. :)
  • Thanks! I will soon share my experience. Code part is really small (thanks to a fantastic SDK..), I basically only use requestPurchase() - most problems came from google itself...

    Hope I can put it together...

    best regards
    Michael

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook
  • atilimatilim Maintainer
    edited December 2012
    @mertocan, @Radiesel - you should call confirmNotification after receiving Event.PURCHASE_STATE_CHANGE event (just pass event.notificationId to confirmNotification function) This is the only trick you should be careful about.

    btw, I realized that the reference manual isn't really enough to implement google billing inside your applications :)
  • @Atilim, this is what for? After I call requestPurchase() I am only testing for GoogleBilling.OK. Either billing worked, or not... I am not testing for PURCHASE_STATE_CHANGED. Well, might be too simple... However, seems to work for me...
  • atilimatilim Maintainer
    From http://developer.android.com/google/play/billing/v2/api.html


    CONFIRM_NOTIFICATIONS
    This request acknowledges that your application received the details of a purchase state change. Google Play sends purchase state change notifications to your application until you confirm that you received them.

    and

    Keep in mind, you must send a confirmation when you receive transaction information from Google Play (step 8 in figure 2). If you don't send a confirmation message, Google Play will continue sending IN_APP_NOTIFY messages for the transactions you have not confirmed. As a best practice, you should not send a CONFIRM_NOTIFICATIONS request for a purchased item until you have delivered the item to the user. This way, if your application crashes or something else prevents your application from delivering the product, your application will still receive an IN_APP_NOTIFY broadcast intent from Google Play indicating that you need to deliver the product.


    It's very similar to the StoreKit:finishTransaction function.
  • got it, thanks! Will modify my code. Just realized, that I was implementing more or less the same as mertocan...
  • atilimatilim Maintainer
    edited December 2012
    It's correct. You just need to add one line of confirmNotification and that's all. Basically your listener function should be like:
    local function onPurchaseStateChange(event)	
    	if event.responseCode  == GoogleBilling.OK then
    		-- unlock
    	end
     
    	googlebilling:confirmNotification(event.notificationId)
    end
  • Aha ;-)) Just realized that in that case your sample code in the documentation is wrong :))

    Honestly, documentation of StoreKit function finishTransaction() says:

    Your application should call this function only after it has successfully processed the transaction and unlocked the functionality purchased by the user.

    Sample code in documenation is implemented that way, that finishTransaction is called if purchase failed or succeeded... correct?

    Same to your code above...

    Michael
  • atilimatilim Maintainer
    edited December 2012

    Your application should call this function only after it has successfully processed the transaction and unlocked the functionality purchased by the user.
    I've copy-pasted this information from Apple's reference manual :)

    But you should call finishTransaction even if your transaction is failed. If you look at this documentation: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/AddingaStoretoYourApplication/AddingaStoretoYourApplication.html finishTransaction is called in step 8 (completeTransaction), step 9 (restoreTransaction) and step 10 (failedTransaction).

    The only requirement for a failed purchase is that your application remove it from the queue. Therefore you should call finishTransaction to remove it from queue when your transaction fails.
  • So, to make sure, this is different between Android and iOS? Because the above Android documentation says:

    As a best practice, you should not send a CONFIRM_NOTIFICATIONS request for a purchased item until you have delivered the item to the user.

    So if it failed, I have not delivered it to the user and should not call
    googlebilling:confirmNotification(event.notificationId)

    Is that correct? Thanks for your quick replies!
    Michael
  • atilimatilim Maintainer
    edited December 2012 Accepted Answer
    I think documentation is not very clear about this situation. But google's official example code sends CONFIRM_NOTIFICATIONS even when the transaction fails.

    To summarize, If the transaction fails or user cancels, don't deliver to user but send CONFIRM_NOTIFICATIONS request.

  • @atilim
    Event.REQUEST_PURCHASE_COMPLETE
    Dispatched when requestPurchase function completes. It contains event.responseCode, event.productId, event.productType and event.developerPayload fields.

    There isn't event.notificationId in request purchase. There is a problem in my phone now i can not access it. So i can not try. Will it work although it doesnt contain event.notificationId??
  • atilimatilim Maintainer
    edited December 2012
    @mertocan - you need to call confirmNotification function in Event.PURCHASE_STATE_CHANGE event (not in Event.REQUEST_PURCHASE_COMPLETE event).
  • atilimatilim Maintainer
    And don't blame me about these confusing event names. It's all google's fault :)

    Likes: mertocan

    +1 -1 (+1 / -0 )Share on Facebook
  • Oh okay now i understand completely :) Thanks alot :)
  • damned! InApp Purchasing was no longer working after playing around with Event.PURCHASE_STATE_CHANGE.

    Whenever I click on "OK" to buy an item, Application crashed. Function onPurchaseStateChange() never called executed, although I set an Event Listener.

    Right now, I figure out that you have to set the PublicKey to get this event. So finally I answered my question myself. After setting the publicKey, App no longer crashes and onPurchaseStateChange() function is called correctly.

    regards
    Michael
  • atilimatilim Maintainer
    Oh.. I'll look at it. If the user doesn't set the public key, there should be a logical Lua error instead of crashing.
  • Well, I don't know how to debug that with LUA. Problem is, googlebilling does not work in an emulator, so I guess, it also does not work in GiderosPlayer, am I right? So I have to export the project and run it on a real device. Good thing is, I could use Android debug and that said:

    java.lang.RuntimeException: Unable to start service com.giderosmobile.android.plugins.googlebilling.BillingService@41591608 with Intent { act=com.android.vending.billing.PURCHASE_STATE_CHANGED cmp=.....

    As already mentioned, purchaseStateChanged() was never called in LUA (I added Alert boxes), but after I added the public key in googlebilling, there was no Android error any longer and also function got called correctly.

    Reproducable and just for you as a hint...

    best regards
    Michael
  • You dont have to export the project. You just need to run project on the android device from gideros. I mean if you , have the giderosplayer lastest version on your device , you can run the project from gideros. It will also work correctly.
  • Now I am getting developer Error. When I change the api version , I am getting BillingUnavailable error.

    require("googlebilling")
     
    googlebilling:setApiVersion(0)
    googlebilling:setPublicKey("...")
     
    local function requestPurchase(event)	
     
    	if event.responseCode ~= nil then
    		print("error", event.responseCode)
    		return
    	end
     
    	googlebilling:addEventListener(Event.PURCHASE_STATE_CHANGE,onPurchaseStateChange)
     
    end
     
    local function onPurchaseStateChange(event)	
     
    	if event.responseCode  == GoogleBilling.OK then
    		-- unlock
    	end
     
    	googlebilling:confirmNotification(event.notificationId)
    end
     
     
    if googlebilling:checkBillingSupported("productType") then
     
    	googlebilling:addEventListener(Event.REQUEST_PURCHASE_COMPLETE, requestPurchase)
    	stage:addEventListener(Event.MOUSE_DOWN, function()
    		googlebilling:requestPurchase("...", "productType", "mert")
    	end)
     
    end
  • @mertocan, why do you set ApiVersion? I didn't set it. If you do, shouldn't you set it to 2? Link above from Atilim showed, he implemented v2. I will also try the player on the device, thanks for the tip... I will bite my as if that works :((

    @Atilim, that raises the question gideros SDK shouldn't be upgraded to v3? Google suggests to upgrade to version 3 (not sure about this).

    best regards
    Michael
  • player on android and googlebilling works... gosh...
    no comment.png
    334 x 585 - 311K

    Likes: atilim, mertocan

    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.