Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to add Android InApp purchases - Page 2 — Gideros Forum

How to add Android InApp purchases

2

Comments

  • hgvyas123hgvyas123 Guru
    edited January 2013
    @mertocan :-

    yes it shutdown after the message like your item will appear shortly.

    googlebilling:setPublicKey("yourverylongpublickey") --do you have replaced this with your key?

    also i think so it is necessary to upload apk on google play and same apk (as per my thought same package name and same keystore also atleast it would be worth to try) should be used for testing purpose.

    :)
  • I think problem is my country. In Turkey Android in-app purchases not allowed yet. So if it is working on your device, there is no problem with codes. Thanks @hgyyas123
  • yeah really android market is like hell (it is my feeling for it currently otherwise i love it)
    bcoz as per my knowledge india was not allowed to sell iap or paid apps in android market so i had setteled my game viking runner for that and when i was about to upload it on market i found hell i can now sell iaps and paid apps in market :D
    obviously it is a good thing for me but i can not publish my game on that day and now i am waiting for saturday-sunday :(

    i hope turkey and all other will added soon to sell apps

    :)
  • great it was there since October and i found it just 1 day ago :D

    :)
  • hgvyas123hgvyas123 Guru
    edited January 2013
    @Radiesel and @all

    i had tried this code last night still i had not tried real products just android.test.purchase it works for me i can get success message but if i minimize the apk with home button (i think so after purchasing test product from market but didn't get any confirmation) sometimes later my game get forceclose even though it is not running so do you have any idea what to do for this case.

    also

    googlebilling:addEventListener(Event.REQUEST_PURCHASE_COMPLETE, onRequestPurchaseComplete)
    googlebilling:addEventListener(Event.PURCHASE_STATE_CHANGE, onPurchaseStateChange)

    above two lines add listener is there any need to remove this listener i am confused bcoz sometimes it takes approx 1 minute or even more to get confirmation about purchase so i assume it is a not good idea to remove this listener and making related function global right?

    edit : may be putting this code in init.lua or main.lua will and just requestPurchase on any scene will do the trick?
    :)
  • Hmm, maybe that should be answered by a real LUA expert? (which I am not.. :\"> ). Actually, I have put the EventListener functions in main.lua. Purchase is called in one of my scenes using SceneManager. I am having several places calling "Purchase", but I guess a good idea would be, to only change the state of purchased items in the event listener and not inform the user in the listener function. If user reaches some special scenes (like "main menu"), you can inform the user: "item received".

    But actually I am a bit stumped for the answer how to handle "home button". I just realized, that when purchasing a real product, the StateChange Event happens usually within a second (more or less immediately). But that's only experience with a few tests...

    Maybe some Gurus like ar2rsawseen have the "correct" answer? ;-)
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    It would definitely make sense to make the callback event global, because the user may go to other scene, etc.

    Good question about home button. I guess when there is a situation when you know that purchase was made, but you have not received a confirmation, you could use GoogleBilling:restoreTransactions() when the app starts or reloads to check if purchase was actually made
  • @ar2rsawseen, exactly what I thought... Thanks to the Guru ;-)
  • GoogleBilling:restoreTransactions() will not work for me as i have un managed iap that needed to be purchase again and again like coins.

    and i am not confused about that i am confused about crash when user quickly close the game after iap with home button might be my game can not handle this when it is in background not sure what is the exact situation i am just guessing the problem.

    for now i am thinking to give message to not close the game until you receive your payment as @radiesel says it will not take much time when it is in live state so i think it will be ok for now.

    :)
  • hgvyas123hgvyas123 Guru
    edited January 2013
    and dear @mertocan you also have this problem. :D
  • @hgvyas, I am having the same issue. Selling unmanaged IAP... I am not 100% sure, but my understanding is, that google will send messages until the message is confirmed. So when you close the App, there will be no

    googlebilling:confirmNotification(event.notificationId)

    from your App called. Later on when you start the App again, you might get the message (but that's only a guess). I will make more tests on this, also on restoreTransaction() which is difficult to test, too.

    Michael
  • ok plz dont take my above posts seriously it is not taking that much of long time to give purchase state it is almost instant i had tested lots of time last day and all the time i had got result at the same time so there might be some issue on that day sorry for any confusion caused by me

    :)
  • unlyingunlying Guru
    edited January 2013
    @Radiesel Hello. Thank you for this guide. It almost work for me.
    1. I tap on icon to buy item.
    2. It goes to google play.
    3. I pay money for my item
    4. Back to App
    5. But purchase doesn't gave me what it should.
    6. After that i have message in status bar "Mobile dungeons it is impossible to make a purchase"
    Do you know why it can happens?
  • require "googlebilling"
     
    --------------------------------------------------
    -- GOOGLE Billing
    -- <a href="https://forum.gideros.rocks/profile/param" rel="nofollow">@param</a> event
    -- <a href="https://forum.gideros.rocks/profile/return" rel="nofollow">@return</a>
    --------------------------------------------------
    local function onRequestPurchaseComplete(event)
        if (event.responseCode == GoogleBilling.OK) then
    		-- transaction has been sent to google (thanks Atilim)
    		-- don't unlock items here
    		-- 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.gideros.rocks/profile/param" rel="nofollow">@param</a> event
    -- <a href="https://forum.gideros.rocks/profile/return" rel="nofollow">@return</a>
    --------------------------------------------------
     
    local function onPurchaseStateChange(event)
    	if (event.purchaseState == GoogleBilling.CANCELED) then
                if (event.productId == "mobiledungeons200") then
    			-- lock or don't unlock
    		elseif (event.productId == "your_product_002") then
    			-- lock or don't unlock
    		end
    	elseif (event.purchaseState == GoogleBilling.PURCHASED) then
                if (event.productId == "mobiledungeons200") then
    			-- unlock 
    			coins=coins+200
    			coins = dataSaver.loadValue("coins")
    			-- show Message, item bought
    		elseif (event.productId == "your_product_002") then
    			-- unlock 
    			coins=coins+500
    			coins = dataSaver.loadValue("coins")
    			-- show Message, item bought
    		end
    	elseif (event.purchaseState == GoogleBilling.REFUNDED) then
                if (event.productId == "mobiledungeons200") then
    			-- lock or don't unlock
    			coins=coins-200
    			coins = dataSaver.loadValue("coins")
    		elseif (event.productId == "your_product_002") then
    			-- lock or don't unlock
    			coins=coins-500
    			coins = dataSaver.loadValue("coins")
    		--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
    googlebilling:setPublicKey("myverylongkey")
    googlebilling:addEventListener(Event.REQUEST_PURCHASE_COMPLETE, onRequestPurchaseComplete)
    googlebilling:addEventListener(Event.PURCHASE_STATE_CHANGE, onPurchaseStateChange)]]
    It is code. It is pretty same. But coins doesn't increase. Where this code should be?
    Thank you.
  • @unlying, looks pretty OK to me.

    Did you get the "item will appear soon" message after buying the item? Does it show up in your "google checkout" as a bought item? Did you use a different user to buy the item?

    Also, I would add an alert box within each state (PURCHASED, etc.) to test if the InApp purchase reached the correct part of the code. Also, make alertBoxes in onRequestPurchaseComplete(). Most frequent error that happens in my code is GoogleBilling.DEVELOPER_ERROR....

    And maybe there is something wrong with your coins (local, global problem)?

    Michael
  • Look like i'm just lame. This is my problem... coins = dataSaver.loadValue("coins")
    Sorry for bother
  • It works! Awesome!

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
  • ;-) while I am having problems with another test-account... Damned InApp Purchasing...
    Just says: "This purchase is not possible for this user"... Argh!!!!
  • Guess it's because my other user is not added to the "Testuser" in developer console. Seems this is required for InApp Purchases as long as the App is not published...
  • I never use test account, but in my testing i have another problem. May be everybody knows about it, but for me it was surprise.
    When i create a new app version and test it on my device it always say "This version doesn't support google billing". I was curious because previous version works fine. Solution was to upload new version to Google Play.
  • Maybe it's related to the Version of your App. I somewhere read that the Uploaded App in the Store should have the same version as the one on the device.

    BTW, successfully got RestoreTransactions() working. It took me a felt "forever" to figure this out. YES!!!
  • @Radiesel

    I've followed the instructions, and i'm using android.test.purchased as the product id.
    I'm testing on the device (Nexus 7) using the latest ADT (eclipse + developer tools).
    I'm using my public key.

    Everything works as expected, but as others have experienced, the onPurchaseStateChange method is never called, no mater how long i wait for the response.

    By reading the thread i can't find the solution, or what i'm doing wrong.
  • Just tried to move all googlebilling code to main.lua as suggested here:
    http://www.giderosmobile.com/forum/discussion/2915

    Still onPurchaseStateChange doesn't get called. :(
  • nat12nat12 Member
    Hi hugocosta

    I encountered the same problem, solved with the help of Atilim, do you have uploaded the app in google play? inapp work only if the app is loaded (not published, a draft will suffice) to enable them.
  • No, i did not.
    But as i'm testing only with android.test.purchased it should not matter. But i will try it. :)
  • nat12nat12 Member
    I also was testing with android.test.purchased, for some strange reason uploading the app is needed also in this case...
  • @nat12

    It worked.
    But I had to wait some time after uploading the apk, it didn't worked right away.

    Thank you. :)
  • arcadiaarcadia Member
    edited April 2013
    GoogleBilling:restoreTransactions() will not work for me as i have un managed iap that needed to be purchase again and again like coins.

    and i am not confused about that i am confused about crash when user quickly close the game after iap with home button might be my game can not handle this when it is in background not sure what is the exact situation i am just guessing the problem.

    for now i am thinking to give message to not close the game until you receive your payment as @radiesel says it will not take much time when it is in live state so i think it will be ok for now.

    :)
    This is what happened to me:
    - I made a payment.
    - Before was called the event onPurchaseStateChange the phone has crashed and it has been turned off.
    - When I restarted the phone and I opened my application has been called the event onPurchaseStateChange and the transaction was completed.

    All this without using GoogleBilling:restoreTransactions()
  • Hello, i followed the instructions in detail, and finally i got the iap working. But, always the first time i press my control to buy coins, the Google windows doesn't appears, i have to click again the button to get working the Google Checkout window. That means i have to execute 2 times googlebilling:requestPurchase(myiap). I tested the first time the click listener execute googlebilling:requestPurchase(myiap), but for some reason there are no answer from android system.

    This always happens the first time i execute the app. After that the iap buttons works fine with google checkout window system. What can i do here?
Sign In or Register to comment.