Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Android InApp Purchases and Public Key - Page 2 — Gideros Forum

Android InApp Purchases and Public Key

2»

Comments

  • @mertocan,

    googlebilling:setApiVersion(2)

    works. Others don't..

    Michael
  • atilimatilim Maintainer
    @Radiesel and @mertocan,

    For api version, I know all values except 1 and 2 gives "developer error".

    I think you don't need to set api version to 2 if you're not using subscriptions (e.g. automated recurring billing).

    With v3, they've done many many changes. I'm not sure if it's worth to spend time and try to support it.
  • if i dont set api version 0 i am getting billingUnavailable. Is the reason for this that i am living in Turkey? @radiesel can you try my codes with your productId and Key?
  • RadieselRadiesel Member
    edited December 2012
    @mertocan, I doubt that. My code is slightly different from yours. I am globally adding EventListeners to googlebilling and just call purchase when needed. I am not setting ApiVersion at any time. Did you know that you can make static tests without having to add any kind of real product? Just try

    googlebilling:requestPurchase("android.test.purchased")
    for a purchased product and

    googlebilling:requestPurchase("android.test.canceled")
    for a canceled product

    see http://developer.android.com/google/play/billing/billing_testing.html

    Both are working in AndroidPlayer. There is no credit card needed and no debit made. My real products cannot be purchased in AndroidPlayer, I am getting message "item not available" (or not found) which I think is normal. If you testing your real products you have to upload a signed .apk to your googleplay account and install the signed .apk on your device having the same version number. You have to use a different account on the device (which is easy for me, because I am having a Nexus 7 with multiple accounts).

    I successfully bought an item 5 minutes ago with my credit card and refunded it (canceled order). So I can say it seems to work.

    However, strange thing is I am not getting a PURCHASE_STATE_CHANGE when successfully purchasing a product, only when I cancel the purchase I am getting a PURCHASE_STATE_CHANGE event. Maybe Atilim knows something about it?

    If my code works completely I will share it, then everybody can correct my code if needed.

    Michael
  • googlebilling:requestPurchase("android.test.purchased")


    googlebilling:requestPurchase("android.test.canceled")

    works good for me. So I think I have problem with my product. When i write my product id. App goes to the Google Play and Alerts Item not found. So codes are working.
  • I think I know your problem. Set your products (not the App) to "active". Then it should work. I have completed my first Step-by-Step instruction, please have a look:

    http://www.giderosmobile.com/forum/discussion/2258/how-to-add-android-inapp-purchases

    Hope that helps!
    Michael

    Likes: mertocan

    +1 -1 (+1 / -0 )Share on Facebook
  • gorkemgorkem Maintainer
    @Radiesel added your link to developer's faq, thanks for it.
  • atilimatilim Maintainer
    edited December 2012
    @Radiesel - I've read your tutorial and currently I'm not sure if we should unlock the item in Event.REQUEST_PURCHASE_COMPLETE or Event.PURCHASE_STATE_CHANGE. I'll read in-app billing documentation and example codes again and try to find the exact answer.

    Thank you again.

    Likes: mertocan

    +1 -1 (+1 / -0 )Share on Facebook
  • @Atilim, I can confirm that Event.PURCHASE_STATE_CHANGE happens >after< Event.REQUEST_PURCHASE_COMPLETE. But my tests showed, that Event.PURCHASE_STATE_CHANGE have not been called on a successful purchase. Even after a minute or so, item or message did not receive. It takes about 5-10 seconds until Event.PURCHASE_STATE_CHANGE happens when you cancel a purchase. So in my opinion I have to unlock the item as soon as possible. We can't let the user wait too long to get the item.

    Hmm, just thinking about if it has something to do with the Item-Type (managed or non-managed product). I purchased a managed item (in my case new levels), but even those should be immediately available.

    However, I will read google docs again, too. Maybe we can figure out together...

    Michael
  • @atilim, I think my workflow indeed is not ideal. I read somewhere that it might take up to 15 minutes until the product arrives....

    That also leads into an assumption, that you have to check state of orders each time you start the App. Because you might order levels, but before STATE_CHANGE arrived you closed the App.

    I refunded my ordered items, but App still says it's already bought, which is incorrect, because I never received payment....

    I am slightly confused...
  • atilimatilim Maintainer
    edited December 2012 Accepted Answer
    Now I'm pretty sure that you should deliver the item at PURCHASE_STATE_CHANGE. REQUEST_PURCHASE_COMPLETE only means that requestPurchase command is received by Google Play and it's being processed.

    I can receive PURCHASE_STATE_CHANGE after 2-3 seconds when testing with "android.test.purchased". Is it same on your side?

    Also I've noticed that when you don't set public key correctly, Gideros player crashes badly :) (with "Invalid key specification." message in LogCat) I'll give a meaningful Lua error here.
  • atilimatilim Maintainer
    edited December 2012
    btw, can you get PURCHASE_STATE_CHANGE if you call restoreTransactions()? So that you can understand if the item is already bought or not.
  • @Atilim, correct, just figured out the following minutes ago. onStateChanged() should look like this:
    local function onPurchaseStateChange(event)
        if (event.purchaseState == "canceled") then
            -- do not unlock
        elseif (event.purchaseState == "purchased") then
            -- unlock item
        elseif (event.purchaseState == "refunded") then
            -- lock or leave unlocked?
        elseif (event.purchaseState == "expired") then
            -- lock item
        else
            -- should not happen ;-)
    	end
    event.responseCode is not working as expected in this EventListener if you ask me. I also believe it shouldn't be used.

    Also I can say, that it does not fully work in Gideros Player on Android. Within Player, StateChanged() event is not called. If I test with .apk, it works like charm... I correctly receive purchased and canceled events in StateChange() function.

    That means, I have to adjust my Step-by-Step instruction...
  • atilimatilim Maintainer
    edited December 2012
    @Radiesel - That's great and thank you for your efforts :)

    Also I've realized that I haven't put the string constants GoogleBilling.PURCHASED, GoogleBilling.CANCELED, GoogleBilling.REFUNDED, GoogleBilling.EXPIRED to the reference manual. And both use of
    event.purchaseState == "purchased"
    and
    event.purchaseState == GoogleBilling.PURCHASED
    are totally valid. And there are only 4 cases as you've guessed.


    I think you're always receiving GoogleBilling.OK in event.responseCode. It means Google Play received the message and able to process it. I think it's only meaningful when you're using checkBillingSupported and nothing else.
  • Don't we have to put googlebilling:confirmNotification(event.notificationId) to the end of the onPurchaseStateChange function?
  • @mertocan, sure we have to... It will stay, just didn't added to the latest code portion...
  • @Atilim, my code looks pretty good right now. I only have one more problem.My testaccount has purchased a managed product, but I canceled and refunded it. Well, even when I reinstall the App and try to purchase that item again, it says "item already purchased". Do you know what I have to do to disabled that item again? Is it even possible?
  • @Atilim, I was trying intensively to get the googlebilling:restoreTransactions() working, but I wasn't successful. I have added a listener event

    googlebilling:addEventListener(Event.RESTORE_TRANSACTIONS_COMPLETE, onRestoreTransactionsComplete)

    and the corresponding function.

    Now, when I test on my device using gideros player using real products, the function successfully gets called, but productId or notificationId is empty (which is normal since InApp-Testing doesn't work with gideros player completely) - (This raises the question on how to identify which product was restored, btw). onRestoreTransactionsComplete() is followed by a onRequestPurchaseComplete() with a GoogleBilling.DEVELOPER_ERROR (which isn't the sequence based on what google pages say). However, Application is still working good.

    When I test using the App directly on the device and I call restoreTransactions(), Application simply crashes. I wasn't able to figure out what's causing the crash. Even if I leave the function onRestoreTransactionsComplete() empty, it crashes.

    I have absolutely no idea how to solve this. I am using gideros 09.2

    Any ideas? Thanks!
    Michael
Sign In or Register to comment.