Someone do a idiots guide to Android IAP please?

Monkey Forums/Monkey Programming/Someone do a idiots guide to Android IAP please?

caffeinekid(Posted 2013) [#1]
Much appreciated if you do! I did kind of ask in this thread: http://www.monkeycoder.co.nz/Community/posts.php?topic=7537

..but there were not really many replies so I'm hoping if I post in here more people will see it, and someone can help make this more understandable.

A step by step of getting an IAP to work on something on Google Play would probably help a lot of people I think.

I don't know why it refuses to work for me - I'm using practically the same code as the OUYA set up, and that works fine.

I just get thrown a 500 error no matter what I try when it attempts to initialise the store.

So yes, a step by step idiots guide please, if someone has this working and can help us less fortunate ones. :)

Many thanks!


silentshark(Posted 2013) [#2]
Seconded.. any kind soul out there feel like producing a noob's guide to this, as an early xmas present to us beginners?


Paul - Taiphoz(Posted 2013) [#3]
Yeah I thankfully have not needed to try it myself yet, but I do have plans to at some stage and having a really straight forward step by step would be amazing.


Xaron(Posted 2013) [#4]
Will do it, still a bit limited in my time atm ...


caffeinekid(Posted 2013) [#5]
Seems that a few people need this not just me so I hope one does appear at some point.

Thanks Xaron, but if anyone else knows and has a bit of free time to put this together please do. :)


Xaron(Posted 2013) [#6]
Yes yes yes, need this soon as well! ;) Hang on, looking into this now...


Xaron(Posted 2013) [#7]
Ok, the tutorial comes along nicely. Atm I just stumble a bit across that my products are not listed... Will post more tomorrow!


Xaron(Posted 2013) [#8]
Alright, here we go!

First of all, this is ONLY for Android. Here's the code I use, it's mainly the same as Mark's example:



So far so good, that was the easy part. Compile it to Android and sign it with your release key as you have to upload it to the store. YES, there is no other way to test it with real product ids, but don't worry, you won't have to publish it!

Ok, so go to your developer console and go to "InApp Products"


Ahhh you see, we have to upload the apk first! I select beta testing for that purpose.


Done!


Now go to InApp Products again:


Let's add our product IDs as managed products. As far as I understand starting with API V3 everything is managed which means that you can only buy consumables ONCE and you must consume it before you can buy the next consumable of the same type. Luckily Mark already handles this for us!
The product IDs MUST be the same as in your app defined. In our example:
Global CONSUMABLES:String[] = [ "bulletboost", "speedboost" ]
Global NON_CONSUMABLES:String[] = [ "shipupgrade" ]



Add title, description, price and set it to ACTIVE:


Alright, now your list should look like this:


Finally, to enable TESTING of your purchases you have to add beta testers to your account details. All Google accounts listed there will be able to purchase your items WITHOUT being charged for it. So the buy process will look exactly like the real one with the exception that your credit card isn't debited.


That's it! Actually you have to wait an hour or two till the product list is really available.


Snader(Posted 2013) [#9]
Thank you Xaron, very nice!


bruZard(Posted 2013) [#10]
very usefull. Thx!


Supertino(Posted 2013) [#11]
Saved in my fav's for later thanks Xaron I have put in a good word for you with Santa.


Paul - Taiphoz(Posted 2013) [#12]
bookmarked for when I need it. thanks mate.


Paul - Taiphoz(Posted 2013) [#13]
Wondering about saving the purchase some one has, say for example I buy a bullet booster, but don't consume it in game, at some point I then delete the game or drop my phone down the toilet and need a new one.

What would be the process for that user to get that boost back, as I think that's one of the IAP requirements is it not ? that players should always be able to get their purchases back ?

or is this not really an issue.


smilertoo(Posted 2013) [#14]
Aren't most IAP consumables to avoid that issue?


Xaron(Posted 2013) [#15]
The way Mark handles it is that any purchase is consumed instantly so you can buy another one right away (this has changed with V3 API). In that case you have to check it on your client side for recovery. Of course as soon as you deinstall the game all is gone.

I see no way how one could request already purchased stuff from the Google store that has been consumed already. So you have to set up your own server. Other games use Facebook or Google+ to store your game state permanently.

Google says about that:

* All purchases are “managed” (that is, Google Play keeps track of the user's ownership of in-app products). The user cannot own multiple copies of an in-app item; only one copy can be owned at any point in time

* Purchased items can be consumed. When consumed, the item reverts to the "unowned" state and can be purchased again from Google Play



Snader(Posted 2013) [#16]
Somehow the example won't compile. Any idea?

-pre-compile:

-compile:
    [javac] Compiling 4 source files to D:\Programming\Projects\IAPtest\IAPtest.build\android\bin\classes
    [javac] D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java:5130: error: cannot find symbol
    [javac] 			m_data=(String[])bb_std_lang.resizeStringArray(m_data,m_length*2+10);
    [javac] 			                            ^
    [javac]   symbol:   method resizeStringArray(String[],int)
    [javac]   location: class bb_std_lang
    [javac] D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java:6571: error: cannot find symbol
    [javac] 			m_data=(c_Product[])bb_std_lang.resizeArray(m_data,m_length*2+10);
    [javac] 			                               ^
    [javac]   symbol:   method resizeArray(c_Product[],int)
    [javac]   location: class bb_std_lang
    [javac] D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java:6608: error: cannot find symbol
    [javac] 				m_data=(c_Product[])bb_std_lang.resizeArray(m_data,bb_math.g_Max(m_length*2+10,t_newlength));
    [javac] 				                               ^
    [javac]   symbol:   method resizeArray(c_Product[],int)
    [javac]   location: class bb_std_lang
    [javac] D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java:5367: error: cannot find symbol
    [javac] 			m_data=(c_JsonValue[])bb_std_lang.resizeArray(m_data,m_length*2+10);
    [javac] 			                                 ^
    [javac]   symbol:   method resizeArray(c_JsonValue[],int)
    [javac]   location: class bb_std_lang
    [javac] D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java:6132: error: cannot find symbol
    [javac] 			m_data=(c_DataBuffer[])bb_std_lang.resizeArray(m_data,m_length*2+10);
    [javac] 			                                  ^
    [javac]   symbol:   method resizeArray(c_DataBuffer[],int)
    [javac]   location: class bb_std_lang
    [javac] D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java:6176: error: cannot find symbol
    [javac] 				m_data=(c_DataBuffer[])bb_std_lang.resizeArray(m_data,bb_math.g_Max(m_length*2+10,t_newlength));
    [javac] 				                                  ^
    [javac]   symbol:   method resizeArray(c_DataBuffer[],int)
    [javac]   location: class bb_std_lang
    [javac] D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java:6692: error: cannot find symbol
    [javac] 			m_data=(c_IAsyncEventSource[])bb_std_lang.resizeArray(m_data,m_length*2+10);
    [javac] 			                                         ^
    [javac]   symbol:   method resizeArray(c_IAsyncEventSource[],int)
    [javac]   location: class bb_std_lang
    [javac] D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java:6729: error: cannot find symbol
    [javac] 				m_data=(c_IAsyncEventSource[])bb_std_lang.resizeArray(m_data,bb_math.g_Max(m_length*2+10,t_newlength));
    [javac] 				                                         ^
    [javac]   symbol:   method resizeArray(c_IAsyncEventSource[],int)
    [javac]   location: class bb_std_lang
    [javac] Note: D:\Programming\Projects\IAPtest\IAPtest.build\android\src\com\monkeycoder\monkeygame\MonkeyGame.java uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 8 errors

BUILD FAILED
d:\android-sdk\tools\ant\build.xml:720: The following error occurred while executing this line:
d:\android-sdk\tools\ant\build.xml:734: Compile failed; see the compiler error output for details.

Total time: 18 secondsTRANS FAILED: Android build failed.

Abnormal program termination. Exit code: -1



Snader(Posted 2013) [#17]
I reverted back to Monkey 75d and it is working now.


Paul - Taiphoz(Posted 2013) [#18]
Xaron, I think you need to take your post and pump it over into the tutorials section of the forum, that way people in the future will find it a lot quicker.


Snader(Posted 2013) [#19]
Got it all working, but the shop keeps being 'busy', so no buying yet. No idea why this is happening...