InApp Purchase module for Android and iOS

Monkey Programming Forums/User Modules/InApp Purchase module for Android and iOS

Xaron(Posted 2013) [#1]
Well so here it is. An InApp purchase module! Tested with Monkey v72a.

At the moment it is only available for Android (it uses Google's API v3) and you need to do some tweaks to trans to make it compile.

The source: https://github.com/Xaron/iap

Copy the folders "target" and "modules_ext" to your monkey pro folder. There will be a new custom target called Android_IAP_Game.

Now you have to change trans which shouldn't be necessary in one of the next versions I hope!

Open MonkeyPro/src/transcc/builders/android.monkey and look for the following lines:

format_code('
If GetCfgVar( "ANDROID_NATIVE_GL_ENABLED" )="1"
CopyDir "nativegl/libs","libs",True
CreateDir "src/com"
CreateDir "src/com/monkey"
CopyFile "nativegl/NativeGL.java","src/com/monkey/NativeGL.java"
Endif
')

Replace them with:

format_code('
If GetCfgVar( "ANDROID_NATIVE_GL_ENABLED" )="1"
CopyDir "nativegl/libs","libs",True
CreateDir "src/com"
CreateDir "src/com/monkey"
CopyFile "nativegl/NativeGL.java","src/com/monkey/NativeGL.java"
Endif
If GetCfgVar( "IN_APP_BILLING" )="1"
Print "Copy in app billing..."
DeleteDir "src/com/android", True
CreateDir "src/com/android"
CreateDir "src/com/android/vending"
CreateDir "src/com/android/vending/billing"
CopyFile "iap/IInAppBillingService.aidl", "src/com/android/vending/billing/IInAppBillingService.aidl"
Endif
')

Now compile transcc using the C++_Tool target and replace your /bin/transcc_winnt.exe with the new compiled one.

You should be able to compile the example.monkey file for Android.

Replace in the example the string APP_KEY with a unique identifier for your app. The string ITEM_ID has the value "android.test.purchased" and should be replaced by real items as soon as you have some. The current value is a Google test value which you can use to test any purchases without really buying anything!

Regarding the Google API and how billing works, look here:
http://developer.android.com/google/play/billing/billing_overview.html

I hope the source is somewhat self explanatory. Feel free to ask any questions here! It might still have some bugs!

iOS comes next!


Raul(Posted 2013) [#2]
Nice one. Not yet tested but I will try to play a little with it these days.

Waiting for the iOS release, too!

Anyway thank you for sharing this with us.


Soap(Posted 2013) [#3]
Great to see this!

GitHub and Bitbucket are good options which allow downloads, and the community features for GitHub make it easier for anyone to contribute.


Xaron(Posted 2013) [#4]
Thanks! Right, might choose GitHub then!


MikeHart(Posted 2013) [#5]
I have a zip download here because google code UNFORTUNATELY doesn't support downloads anymore


Well, still works for fantomEngine. :-)


MikeHart(Posted 2013) [#6]
...


Xaron(Posted 2013) [#7]
Yeah Mike, they will disable it starting 2014 for all existing projects...


MikeHart(Posted 2013) [#8]
No problem, I will find another place.


mjcamerer(Posted 2013) [#9]
I followed the instructions above and this works great on Monkey v72a here! Thanks for taking the time to do this!


Armoured(Posted 2013) [#10]
Hi Xaron,
With this target you can sell your app or only additional content?

Thanks


Xaron(Posted 2013) [#11]
It's just to do in app purchases so additional content. I don't understand what you mean with "sell your app" because that is done via the store...


rIKmAN(Posted 2013) [#12]
How are things looking on the iOS front?


Xaron(Posted 2013) [#13]
I moved the repo to github. Link is in the first posting.

@rIKmAN: I still work on that. Might be a bit more though because testing isn't that easy as it is with Google's API.


Armoured(Posted 2013) [#14]
Hi Xaron,
With "sell your app" I speak about this:
http://developer.android.com/google/play/licensing/adding-licensing.html
in other words the LVL...


Xaron(Posted 2013) [#15]
Ah ok, no that's not possible with this module at the moment.