Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How I do IAP? — Gideros Forum

How I do IAP?

edited April 2014 in General questions
I should have asked this BEFORE starting with Gideros... But now the app is almost done anyway...

So, how I do IAP? What I want to do is that you download the full app, and use IAP to unlock the demo version to full version (our game is a story-based game, you will see roughly 2/7 of the story, and then must pay to see the remaing 5/7)
I make games for children: http://www.kidoteca.com

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited April 2014
    Well from logical point of view, most probably you will have a file saved in the |D| folder which stores values, including if the game is unlocked or not.
    Upon app start you load values and check if game is unlocked
    Upon IAP purchase you store value true to unlock the game there
    Additionally you may choose to encrypt this file (there are plenty of lua based encryption libs/modules, most probably some members can suggest something).

    But if you mean from implementation point of view, then go to Gideros Labs and download IAB interface:
    http://giderosmobile.com/labs/iab

    It provides store detection and same interface and workflow for different stores.
    The docs and state of stores can be seen here:
    http://docs.giderosmobile.com/interface/iab

    And here is a draft code to support GooglePlay, Amazon and IOS
    require "iab"
    local iaps = IAB.detectStores()
    iab = nil
    if iaps[1] == "google" then
    	iab = IAB.new(iaps[1])
    	iab:setUp("google-key")
    	--using google product identifiers
    	iab:setProducts({p1 = "googleprod1", p2 = "googleprod2", p3 = "googleprod3"})
    elseif iaps[1] == "amazon" then
    	iab = IAB.new(iaps[1])
    	--using amazon product identifiers
    	iab:setProducts({p1 = "amazonprod1", p2 = "amazonprod2", p3 = "amazonprod3"})
    elseif iaps[1] == "ios" then
    	iab = IAB.new(iaps[1])
    	--using ios product identifiers
    	iab:setProducts({p1 = "iosprod1", p2 = "iosprod2", p3 = "iosprod3"})
    end
    --load previous purchases
    purchases = dataSaver.loadValue("purchases")
    --if there were no purchases
    if not purchases then
    	--create and store empty table
    	purchases = {}
    	dataSaver.saveValue("purchases", purchases)
    end
     
    --if we have a supported store
    if iab then
    	--set which products are consumables
    	iab:setConsumables({"p1", "p2"})
     
    	--if iab is available/loaded
    	iab:addEventListener(Event.AVAILABLE, function(e)
    		iab.loaded = true
    		--if purchase complete
    		iab:addEventListener(Event.PURCHASE_COMPLETE, function(e)
    			--if it was not previousle purchases
    			if not purchases[e.receiptId] then
    				--save purchase
    				purchases[e.receiptId] = true
    				dataSaver.saveValue("purchases", purchases)
     
    				if (e.productId == "p1") then
    					--p1 was purchased
    				elseif (e.productId == "p2") then
    					--p2 was purchased
    				elseif (e.productId == "p3") then
    					--p3 was purchased
    				end
    				AlertDialog.new("Purchase Completed", "Purchase successfully completed", "Ok"):show()
    			end
    		end)
     
    		--if there was an error
    		iab:addEventListener(Event.PURCHASE_ERROR, function(e)
    			AlertDialog.new("Purchase Canceled", e.error, "Ok"):show()
    		end)
     
    		--call restore on each app starts
    		--or make a button to allow users to restore purchases
    		iab:restore()
    	end)
    	iab:isAvailable()
    end
     
    --some where in your code to make a purchase
    stage:addEventListener(Event.MOUSE_UP, function()
    	if iab and iab.loaded then
    		iab:purchase("p1")
    	end
    end)
  • simwhisimwhi Member
    edited February 2015
    Hi @ar2rsawseen

    I'm trying to get IAB working but I have one issue that I'm not sure how to resolve.

    I have followed the installation instructions (on Github) and I've also double checked all the lib and src files. The APK compiles without any errors but when I install it on a device it crashes. The reason for the crash is on:
    require "iab"
    It must be something very simple. Maybe something is not being exported or referenced correctly.

    I also noticed that the instructions specifically for Google billing are as follows:

    Google

    src\com\android\vending\billing folder
    src\com\giderosmobile\android\plugins\iab\google folder
    src\com\giderosmobile\android\plugins\iab\IabGoogle.java

    However, the files are located in the frameworks folder. Is this correct?

    Should it be?:

    Google

    src\com\android\vending\billing folder
    src\com\giderosmobile\android\plugins\iab\frameworks\google folder
    src\com\giderosmobile\android\plugins\iab\frameworks\IabGoogle.java

    Many thanks in advance.

    PS. I will be testing Fortumo in the future so I will be more than happy to tell you about my experience.
  • From further research it looks as if there is a file dependency/linking issue. Can someone help me find the file(s) that are missing? I removed Google billing v2, so I ave may have removed files that are still required. Please help me!

  • Here is my project setup:
    2.JPG
    318 x 641 - 41K
    1.JPG
    420 x 572 - 55K
    2.JPG 40.7K
    1.JPG 55.4K
  • From further research it looks as if there is a file dependency/linking issue. Can someone help me find the file(s) that are missing? I removed Google billing v2, so I ave may have removed files that are still required. Please help me!

    Have you copied libiap.so file into libs/arm and libs/armv7 folders?

    Have you loaded iap library from main Activity: System.loadLibrary("iap")?
  • @jdbc I followed all the instructions several times but I couldn't get it to work, so I decided to start over.

    I created a new export from Gideros and after I added the IAB plugin. This resolved my issue. I must have messed up the previous project some how. At the moment I only have the IAB plugin but I need to add flurry and ads plugin to completely test everything.
  • jdbcjdbc Member
    edited October 2015
    Apple has changed the way to define product ID.

    Now prefix with app bundle id is not needed, you only have to provide the product ID as Google does. You can test the list of products in your device emulator from Xcode.
Sign In or Register to comment.