Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAP: gdx-pay extension for InApp payments #2333

Merged
merged 38 commits into from Sep 21, 2014
Merged

IAP: gdx-pay extension for InApp payments #2333

merged 38 commits into from Sep 21, 2014

Conversation

@noblemaster
Copy link
Member

noblemaster commented Sep 14, 2014

I managed to get a first draft for the gdx-pay extension (cross-platform InApp payments for libGDX) ready for review. This is less of a pull request but more of a request for feedback. Please comment - Thanks :-D

What's currently implemented (extension projects):

  • gdx-pay: the cross-platform code (complete)
  • gdx-pay-android-openiab: gdx-pay implementation for Android supporting Google Play, Amazon, Samsung and a few other stores. I used the open source OpenIAB library. (complete)
  • gdx-pay-iosrobovm-apple: stub for the iOS store (needs implementation)
  • gdx-pay-desktop-apple: stub for the Apple Mac store (needs implementation)
  • gdx-pay-gwt-googlewallet: stub for the GWT backend/GoogleWallet (needs implementation)

This test demonstrates how the payment system is used in your platform-independent code:

To integrate into Android, you will need to add corresponding hooks to your activity (look for the 3x "// InApp:"):

Screenshot running PayTest.java on an Android device:
2014-09-14 libgdx - gdx-pay extension

@nooone
Copy link
Contributor

nooone commented Sep 14, 2014

If I understood the core devs right, new extensions won't go in the core repo anymore. See gdx-ai. That being said you should probably clone gdx-ai and set your PR up as a "standalone extension".

TBH, I haven't really looked at the code, because I'm not sure which value this extension actually adds. Currently there is only an abstraction layer and one implementation. I don't see any value in that so far. Who will implement the other backends? Since there is only one implementation, it doesn't prove that the abstraction layer is "good enough" for other backends.

I think in total this would be a pretty neat and useful extension, however only with more implementations. I'd suggest you to try implementing one more backend, because I'm pretty sure that the core abstraction layer will get more "robust" or "generic" while doing that. After that people are more likely to use it, because currently, they might as well just go directly with OpenIAB.

@noblemaster
Copy link
Member Author

noblemaster commented Sep 14, 2014

If I understood the core devs right...

Not sure if I want to go into politics on that one. I actually haven't setup the "iap" branch putting the gdx-pay extension into the extensions directory of the libGDX project. Mario has set it up that way after discussing with other people involved including myself.

Anyhow, I can either way on the extension. Also, I have no problem implementing the other backends too, but then I am doing this in my free time. In the end I have to pay bills like everyone else. If this ends up being a full-time endeavor maintaining the extension including all the backends I would rather charge money for it. I was hoping to get the ball rolling rather than doing it all on my own. There have been various forum topics about InApp payments for libGDX, so I believe I am not the only one interested in it. However, you are probably not aware of that.

TBH, I haven't really looked at the code...

I have looked at different IAP solutions provided by Google, Amazon, Apple iOS, Apple Mac Store and Steam. I also considered payment gateways including PayPal and Stripe. Then I looked at cross-platform implementations including Unibill, SmartIAP and OpenIAB to name a few. I believe the general design is pretty solid, but I would be glad to hear your feedback once you had a chance to look at it in some more detail.

@badlogic
Copy link
Member

badlogic commented Sep 14, 2014

Daniel, let's keep the tone a little more friendly. @noblemaster is a long
time core committer who sometimes is away for a few months to work on momey
making games :)

I'll try to review it tonight, only skimmed it so far. It looks pretty good!
On Sep 14, 2014 11:50 AM, "Christoph Aschwanden" notifications@github.com
wrote:

If I understood the core devs right...

Not sure if I want to go into politics on that one. I actually haven't
setup the "iap" branch putting the gdx-pay extension into the extensions
directory of the libGDX project. Mario has set it up that way after
discussing with other people involved including myself.

Anyhow, I can either way on the extension. Also, I have no problem
implementing the other backends too, but then I am doing this in my free
time. In the end I have to pay bills like everyone else. If this ends up
being a full-time endeavor maintaining the extension including all the
backends I would rather charge money for it. I was hoping to get the ball
rolling rather than doing it all on my own. There have been various forum
topics about InApp payments for libGDX, so I believe I am not the only one
interested in it. However, you are probably not aware of that.

TBH, I haven't really looked at the code...

I have looked at different IAP solutions provided by Google, Amazon, Apple
iOS, Apple Mac Store and Steam. I also considered payment gateways
including PayPal and Stripe. Then I looked at cross-platform
implementations including Unibill, SmartIAP and OpenIAB to name a few. I
believe the general design is pretty solid, but I would be glad to hear
your feedback once you had a chance to look at it in some more detail.


Reply to this email directly or view it on GitHub
#2333 (comment).

@nooone
Copy link
Contributor

nooone commented Sep 14, 2014

Daniel, let's keep the tone a little more friendly.

I didn't intend to sound unfriendly. Sorry If I did.

Mario has set it up that way after discussing with other people involved including myself.

That was probably a while ago. The opinions on "core-extensions" have changed recently. That's all I wanted to say.

If this ends up being a full-time endeavor maintaining the extension including all the backends I would rather charge money for it.

That's what @badlogic told me how it would be, just a few days ago. That's why I was afraid that if you won't add more backends, nobody will in the end.

@NathanSweet
Copy link
Member

NathanSweet commented Sep 14, 2014

"Since there is only one implementation, it doesn't prove that the abstraction layer is "good enough" for other backends." He did say he is looking for feedback. Also, cross platform support for IAP would be great and has been discussed before.

"If I understood the core devs right, new extensions won't go in the core repo anymore." No one has said this. However, libgdx is already huge and isn't intended as a dumping ground for libgdx related projects. The core is generally cross platform, low level, and widely applicable functionality. If something isn't cross platform and could be a separate project, it probably should be. Sister projects can still be promoted, included in the setup UI, etc.

@just4phil
Copy link

just4phil commented Sep 14, 2014

hi.... i am a bit excited :)
i will try this.... and maybe could add OUYA ..... at least i would try to ....

purchaseObserver and purchaseListener sound like they do the same or i dont really understand the conceptual differences? (i understand what they do in your code.... i only mean the naming)

@just4phil
Copy link

just4phil commented Sep 14, 2014

sorry.... seems like i am a bit blind.... where can i grab the latest sources to integrate this in my project for testing purposes?

@nooone
Copy link
Contributor

nooone commented Sep 14, 2014

@just4phil
Copy link

just4phil commented Sep 21, 2014

@noblemaster
I am not sure if we need both the purchase observer and the purchase listener.
The observer gets installed once and listens all the time .... so why must the purchase listener be seperate?

@just4phil
Copy link

just4phil commented Sep 21, 2014

  1. For the application key it would be easier if we could just take a path to the key file in the assets directory. But we must somehow transform the path to a inputstream ...that's where I had no idea
@noblemaster
Copy link
Member Author

noblemaster commented Sep 21, 2014

@just4phil (re-listener/observer): They could be the same too, although they have different methods inside. How would you go about it, i.e. change it? Code sample?

@noblemaster
Copy link
Member Author

noblemaster commented Sep 21, 2014

@just4phil (re-OUYA applicationKey): yes, you could pass in the path to your file? Then insider the OUYA implementation you take the path and create the input stream as follows:

  String path = ...  (via configuration)
  InputStream inputStream = new FileInputStream(new File(path));
@just4phil
Copy link

just4phil commented Sep 21, 2014

Cool.... I could try that

@BlueRiverInteractive
Copy link
Contributor

BlueRiverInteractive commented Sep 21, 2014

@noblemaster Just a minor change: can you swap the arguments of the purchase method?

PurchaseSystem.purchase("product_identifier", new PurchaseListener() {
       ...
});

Feels more natural than the reverse. This way, if you have a very long listener, it's easier to see what you are purchasing.

@noblemaster
Copy link
Member Author

noblemaster commented Sep 21, 2014

@BlueRiverInteractive: agreed, you got it! Just refactored the method signatures.

@JesseTG
Copy link
Contributor

JesseTG commented Sep 21, 2014

This comment is an inside joke.

@just4phil
Copy link

just4phil commented Sep 21, 2014

hm.... after forking/cloning libgdx and ant -f fetch.xml i have this error:

The container 'Android Dependencies' references non existing library 'L:\Bitbucket__libGDX_fork\extensions\gdx-pay\gdx-pay-android-openiab\bin\gdx-pay-android-openiab.jar'

there is no such jar.... what can i do?

@MobiDevelop
Copy link
Member

MobiDevelop commented Sep 21, 2014

I'd like to make a request that we don't upload these sdk (openiab and ouya) binaries to the repo.

@badlogic badlogic merged commit 32b9841 into master Sep 21, 2014
@badlogic
Copy link
Member

badlogic commented Sep 21, 2014

I'm an idiot, i accidentially pulled this in. I don't want to rewrite history, and reverting the commit will get us into trouble down the road when we want to merge this commit.

Everybody please fetch master into a new branch on your end and continue sending PRs. Sorry. I will stop to computer now...

@noblemaster
Copy link
Member Author

noblemaster commented Sep 22, 2014

@MobiDevelop: agreed not to add the binaries. Having quite figured out "fetch" though. Adding the maven dependencies should do the trick!?

@noblemaster
Copy link
Member Author

noblemaster commented Sep 22, 2014

@badlogic: no worries :)

@noblemaster noblemaster deleted the iap branch Sep 22, 2014
@just4phil
Copy link

just4phil commented Sep 22, 2014

hmmm.... i try to start the tests on my ouya....i added the ouya intent to the manifest of the android test project.... this is the output:

[2014-09-22 20:55:14 - gdx-tests-android] Android Launch!
[2014-09-22 20:55:14 - gdx-tests-android] adb is running normally.
[2014-09-22 20:55:14 - gdx-tests-android] Performing com.badlogic.gdx.tests.android.AndroidTestStarter activity launch
[2014-09-22 20:55:14 - gdx-tests-android] Uploading gdx-tests-android.apk onto device '015d456d7f201200'
[2014-09-22 20:55:34 - gdx-tests-android] Installing gdx-tests-android.apk...
[2014-09-22 20:55:39 - gdx-tests-android] Success!
[2014-09-22 20:55:39 - gdx-pay-android] Could not find gdx-pay-android.apk!
[2014-09-22 20:55:39 - gdx-pay-android-openiab] Could not find gdx-pay-android-openiab.apk!
[2014-09-22 20:55:39 - gdx-pay-android-ouya] Could not find gdx-pay-android-ouya.apk!
[2014-09-22 20:55:39 - gdx-tests-android] Starting activity com.badlogic.gdx.tests.android.AndroidTestStarter on device 015d456d7f201200
[2014-09-22 20:55:39 - gdx-tests-android] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.badlogic.gdx.tests.android/.AndroidTestStarter }

on my mobile it works well

@noblemaster
Copy link
Member Author

noblemaster commented Sep 23, 2014

Yes, I am actually getting the same warnings when I run the tests as well. However, when I run PayTest on an Android device it works just fine.

I added the projects as Android-library project and also as regular project to the gdx-tests-android. I guess removing or changing the project types around should make the warning to away...

@just4phil
Copy link

just4phil commented Sep 23, 2014

i can run all the gdx-test on my ouya after adding the ouya-intent to the manifest.
but i cant run PayTestOUYA.....adding the other libraries to the project doesnt seem to work ...
but i tested in my environment and still works like a charme.....
but i didnt test consumeables .... so i guess we are not done by now.....

@noblemaster
Copy link
Member Author

noblemaster commented Sep 24, 2014

but i cant run PayTestOUYA....

I guess you mean "PayTest.java"? Not sure what error you are getting but you definitely have to pass in the OUYA store parameters such as in PayTest.java:

config.addStoreParam(PurchaseManagerConfig.STORE_NAME_ANDROID_OUYA, new Object[] {
     "<OUYA developerID String",
     "<Path to OUYA applicationKey"
});

If it still doesn't work there might be another error. What log output/error messages are you getting?

@just4phil
Copy link

just4phil commented Sep 24, 2014

well i built a PayTestOUYA.java file and added it to the gdx-tests..... but that doesnt work.
when adb installs the apk on the ouya it says:

[2014-09-22 20:55:39 - gdx-pay-android] Could not find gdx-pay-android.apk!
[2014-09-22 20:55:39 - gdx-pay-android-openiab] Could not find gdx-pay-android-openiab.apk!
[2014-09-22 20:55:39 - gdx-pay-android-ouya] Could not find gdx-pay-android-ouya.apk!

any ideas?

so i will try to just change your PayTest.java and see if that works for ouya

@noblemaster
Copy link
Member Author

noblemaster commented Sep 24, 2014

You shouldn't create your own PayTestOUYA.java file. It would defeat the purpose of being cross-platform and all. You should add all your changes to PayTest.java. Once you upload the Android tests to your OUYA-device it should all magically work as long as all the parameters for your OUYA-store are set within PayTest.java.

Anyhow, it's possible that PayTest.java doesn't open the OUYA-store for you. Please make sure:

  • run on an actual OUYA-device and make sure isRunningOnOUYAHardware returns true! If not, you might have to fixup that method.

Regarding the warnings; I got those too but it works fine for me. What actually happens (console output, display on OUYA) when you run PayTest on your OUYA device? Can you post those logs?

@just4phil
Copy link

just4phil commented Sep 24, 2014

here it is:

09-24 07:24:30.180: D/GdxPay/IAP(1187): Failed to locate purchase manager for OUYA-IAP (gdx-pay-android-ouya.jar file not installed)
09-24 07:24:30.180: D/GdxPay/IAP(1187): java.lang.reflect.InvocationTargetException
09-24 07:24:30.180: D/GdxPay/IAP(1187): at java.lang.reflect.Constructor.constructNative(Native Method)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at com.badlogic.gdx.pay.android.IAP.(IAP.java:75)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at java.lang.reflect.Constructor.constructNative(Native Method)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at com.badlogic.gdx.pay.PurchaseSystem.(PurchaseSystem.java:61)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at com.badlogic.gdx.tests.PayTest.create(PayTest.java:54)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:237)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
09-24 07:24:30.180: D/GdxPay/IAP(1187): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
09-24 07:24:30.180: D/GdxPay/IAP(1187): at android.os.Handler.(Handler.java:121)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at com.badlogic.gdx.pay.android.ouya.PurchaseManagerAndroidOUYA$HandlerExtension.(PurchaseManagerAndroidOUYA.java:192)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at com.badlogic.gdx.pay.android.ouya.PurchaseManagerAndroidOUYA$HandlerExtension.(PurchaseManagerAndroidOUYA.java:192)
09-24 07:24:30.180: D/GdxPay/IAP(1187): at com.badlogic.gdx.pay.android.ouya.PurchaseManagerAndroidOUYA.(PurchaseManagerAndroidOUYA.java:185)
09-24 07:24:30.180: D/GdxPay/IAP(1187): ... 10 more
09-24 07:24:30.180: I/IAP(1187): IAP: gdx-pay successfully instantiated.
09-24 07:24:30.180: E/GdxPay/OpenIAB(1187): Store name could not be mapped: OUYA
09-24 07:24:30.210: D/AndroidRuntime(1187): Shutting down VM
09-24 07:24:30.210: W/dalvikvm(1187): threadid=1: thread exiting with uncaught exception (group=0x40c90300)
09-24 07:24:30.210: E/AndroidRuntime(1187): FATAL EXCEPTION: main
09-24 07:24:30.210: E/AndroidRuntime(1187): com.badlogic.gdx.utils.GdxRuntimeException: java.lang.RuntimeException: Problem setting up in-app billing: IabResult: 3, Billing isn't supported (response: 3:Billing Unavailable)
09-24 07:24:30.210: E/AndroidRuntime(1187): at com.badlogic.gdx.tests.PayTest$1.handleInstallError(PayTest.java:96)
09-24 07:24:30.210: E/AndroidRuntime(1187): at com.badlogic.gdx.pay.android.openiab.PurchaseManagerAndroidOpenIAB$1.onIabSetupFinished(PurchaseManagerAndroidOpenIAB.java:233)
09-24 07:24:30.210: E/AndroidRuntime(1187): at org.onepf.oms.OpenIabHelper$2.run(OpenIabHelper.java:529)
09-24 07:24:30.210: E/AndroidRuntime(1187): at android.os.Handler.handleCallback(Handler.java:615)
09-24 07:24:30.210: E/AndroidRuntime(1187): at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 07:24:30.210: E/AndroidRuntime(1187): at android.os.Looper.loop(Looper.java:137)
09-24 07:24:30.210: E/AndroidRuntime(1187): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-24 07:24:30.210: E/AndroidRuntime(1187): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 07:24:30.210: E/AndroidRuntime(1187): at java.lang.reflect.Method.invoke(Method.java:511)
09-24 07:24:30.210: E/AndroidRuntime(1187): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-24 07:24:30.210: E/AndroidRuntime(1187): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-24 07:24:30.210: E/AndroidRuntime(1187): at dalvik.system.NativeStart.main(Native Method)
09-24 07:24:30.210: E/AndroidRuntime(1187): Caused by: java.lang.RuntimeException: Problem setting up in-app billing: IabResult: 3, Billing isn't supported (response: 3:Billing Unavailable)
09-24 07:24:30.210: E/AndroidRuntime(1187): ... 11 more

@noblemaster
Copy link
Member Author

noblemaster commented Sep 24, 2014

OK, I checked: looks like you are running quite an older version! You might want to checkout the latest release from the master branch!

Anyhow, from the error it looks like it's able to instantiate OpenIAB via reflection but fails for your OUYA project. Looks like the reflection code is fine (if not, fixup IAP.java for OUYA!) so I would look at how OpenIAB is added to the tests, given it works fine!?

@just4phil
Copy link

just4phil commented Sep 24, 2014

should be the latest version... i pulled yesterday and implemented my pull requests then....

  • on my mobile PayTest for Android OpenIAB google works fine
  • on my ouya my game works fine with the OUYA IAB (but i dont use the reflection part there!)
@just4phil
Copy link

just4phil commented Sep 24, 2014

i just changed OUYA IAP Backend like this:

public static final boolean isRunningOnOUYAHardware () {
    return true;
}

but this didnt help....

@noblemaster
Copy link
Member Author

noblemaster commented Sep 24, 2014

I am looking at this:

09-24 07:24:30.180: D/GdxPay/IAP(1187): at com.badlogic.gdx.pay.android.IAP.(IAP.java:75)

That's an old version. Line 75 is now in the comments...

In any case, sorry, just noted your pull requests! Merged the OUYA update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

10 participants
You can’t perform that action at this time.