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

Parameter type problem in NativeScript #46

Closed
jibon57 opened this issue Aug 29, 2017 · 5 comments
Closed

Parameter type problem in NativeScript #46

jibon57 opened this issue Aug 29, 2017 · 5 comments

Comments

@jibon57
Copy link

jibon57 commented Aug 29, 2017

Hello,

I am trying to implement this library for NativeScript but it can't extracted metadata for Boolean parameter type. http://static.javadoc.io/com.braintreepayments.api/drop-in/3.1.0/com/braintreepayments/api/dropin/DropInRequest.html#collectDeviceData-boolean-

We tried to implement it using Java reflection like here: NativeScript/android#831 (comment)

but not working for this method collectDeviceData(boolean collectDeviceData) :

let collectDeviceDataMethod = dropInRequest.getClass().getMethod("collectDeviceData", [java.lang.Boolean.class]);
collectDeviceDataMethod.invoke(dropInRequest, [true]);

Error:

Error: java.lang.NoSuchMethodException: collectDeviceData [class java.lang.Boolean]
    java.lang.Class.getMethod(Class.java:1981)
    java.lang.Class.getMethod(Class.java:1637)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
    com.tns.Runtime.callJSMethod(Runtime.java:912)
    com.tns.Runtime.callJSMethod(Runtime.java:896)
    com.tns.Runtime.callJSMethod(Runtime.java:888)
    com.tns.gen.java.lang.Object_frnal_ts_helpers_l58_c38__ClickListenerImpl.onClick(Object_frnal_ts_helpers_l58_c38__ClickListenerImpl.java:12)
    android.view.View.performClick(View.java:5610)
    android.view.View$PerformClick.run(View.java:22265)
    android.os.Handler.handleCallback(Handler.java:751)
    android.os.Handler.dispatchMessage(Handler.java:95)
    android.os.Looper.loop(Looper.java:154)
    android.app.ActivityThread.main(ActivityThread.java:6077)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
File: "file:///data/data/org.nativescript.demo/files/app/tns_modules/nativescript-braintree/braintree.js, line: 25, column: 63

It can't understand boolean type. It would be better if it is "java.lang.Boolean.class"

Anyone have suggestion? Thanks in advance.

@crookedneighbor
Copy link

@jibon57 Would you like to open a PR to address this?

@jibon57
Copy link
Author

jibon57 commented Sep 22, 2017

@crookedneighbor Thanks but I ain't that type of expert :( . I need your help :)

https://github.com/braintree/braintree-android-drop-in/blob/master/Drop-In/src/main/java/com/braintreepayments/api/dropin/DropInRequest.java#L83

public DropInRequest collectDeviceData(boolean collectDeviceData) {

may be like this

public DropInRequest collectDeviceData(Boolean collectDeviceData) {

I ain't sure :( :(

@sdcoffey
Copy link

Hey @jibon57,

I'm looking at the final answer to the question you posted suggesting you do something like the following:

let isAndroidPayEnabled = dropInRequest.getClass().getMethod("isAndroidPayEnabled", []);
let booleanType = isAndroidPayEnabled.getReturnType();
let collectDeviceDataMethod = dropInRequest.getClass().getMethod("collectDeviceData", [booleanType]);
collectDeviceDataMethod.invoke(dropInRequest, [true]);

While I can't exactly endorse this code snippet, did it work for you in this case? Nativescript bindings are not something we're actively supporting, so any issues encountered using this library in a Nativescript environment should likely be directed at the android-runtime project, as you've done. In this case, it sounds like a fix is on the way for this runtime.

To be specific, we can't justify changing the type of collectDeviceData(boolean) to collectionDeviceData(Boolean), since this could have unintended consequences on existing integrations and could be source of future bugs in our code.

@jibon57
Copy link
Author

jibon57 commented Sep 22, 2017

@sdcoffey Thanks for reply. Yes, the trick is working fine but the guy who solved the problem already mentioned that the trick is dirty. But works for me :). I have started a new project here:

https://github.com/jibon57/nativescript-braintree

Still now everything looks good :)

@sdcoffey
Copy link

@jibon57

It is indeed a dirty trick, but if it's working for you, that's the best we can do from this end unforch. Good luck!

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

No branches or pull requests

3 participants