android: Problem in BrainTree Drop In SDK for Android
From @jibon57 on August 22, 2017 18:15
Hello,
I was trying with BrainTree Drop In SDK for android like this:
let activity = app.android.foregroundActivity;
let dropInRequest = new com.braintreepayments.api.dropin.DropInRequest();
dropInRequest.clientToken(token) // I got the token from server
app.android.foregroundActivity.startActivityForResult(dropInRequest.getIntent(activity), '4949');
But I am getting following error:
JS: ERROR TypeError: dropInRequest.clientToken is not a function
JS: ERROR CONTEXT [object Object]
But I am following:
That functions are exist in documentation:
http://static.javadoc.io/com.braintreepayments.api/drop-in/3.0.8/com/braintreepayments/api/dropin/DropInRequest.html#clientToken-java.lang.String- http://static.javadoc.io/com.braintreepayments.api/drop-in/3.0.8/com/braintreepayments/api/dropin/DropInRequest.html#getIntent-android.content.Context-
When I tried to get the methods like:
let dropInRequest = new com.braintreepayments.api.dropin.DropInRequest();
console.dir(dropInRequest);
Output:
JS: === dump(): dumping members ===
JS: {}
JS: === dump(): dumping function and properties names ===
JS: <init>()
JS: amount()
JS: androidPayAllowedCountriesForShipping()
JS: clone()
JS: equals()
JS: finalize()
JS: getClass()
JS: hashCode()
JS: notify()
JS: notifyAll()
JS: toString()
JS: wait()
JS: === dump(): finished ===
JS: ERROR TypeError: dropInRequest.clientToken is not a function
JS: ERROR CONTEXT [object Object]
I am trying with Angular:
tns --version
3.1.3
"tns-android": {
"version": "3.1.1"
}
In where I am doing wrong? Please give me suggestion. Thanks in advance.
Copied from original issue: NativeScript/NativeScript#4736
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 34 (8 by maintainers)
Commits related to this issue
- Bump android dropin and fix 3Ds (#29) — committed to jibon57/nativescript-braintree by luke-hawk 4 years ago
@jibon57 that is due to the fact that the method signature requires a primitive
booleantype instead of thejava.lang.Booleanobject. I can’t explain the reasoning behind that, it’s Braintree’s code.Now, in Java you would go about simply writing
boolean.class, but that is not valid in NativeScript since the primitive Java types have no corresponding representation in JavaScript.There is one thing that I can think of that you could try, although you could say it’s a very dirty hack. Consider implementing the code of interest in Java, or wait for the metadata generator fix, and replace the bad code with the proper JavaScript calls.
Here’s the hack explained: So we need to get a hold of what
boolean.classwould normally return in Java, since we can’t call it directly in JavaScript. In that case we can think of a method/field whose return type is the type that is of interest to us, and get it using reflection, which we will then pass to thegetMethodcall, in order to properly get the method that Java’s reflection originally failed finding.In Braintree’s API I found the
isAndroidPayEnabledmethod on the DropInRequestClass, and its return type is boolean, so it will have to do.First we get the method using reflection, then we get the method’s return type, which we will then be able to use.
I have not tested the code.
@jibon57 this is what the above would look like using reflection as a workaround to call the missing methods:
Hope that’s enough to help you make the other calls with reflection. Refer to this simple answer on Java reflection to see how it’s normally done in Java - https://stackoverflow.com/questions/160970/how-do-i-invoke-a-java-method-when-given-the-method-name-as-a-string
Closing the issue in favor of #832, where the problem is described in detail.
@chauhan-saurabh please post issue-related questions in the respective plugin’s repository.
As for the logs that you are seeing - they are mere warnings issued by Google’s Chrome (the embedded browser on your mobile), and are safe to ignore, as they are not related neither to the plugin, nor to NativeScript. The reason you are seeing them is because of the webview that is supposedly being open when working with the Braintree sdk.
@jibon57 - pay close attention to the plugin documentation. You are lucky its thorough at least 😛
https://developers.braintreepayments.com/guides/client-sdk/setup/android/v2#browser-switch-setup ->
Note: The scheme you define must use all lowercase letters.@jibon57 thanks for the log. I created an issue outlining the possible solutions we could implement to reduce the cases when problems like yours could happen.
For the time being you could call to DropInRequest’s methods using Java reflection. Let me know if you need help with the implementation.
@Pip3r4o Thanks for reply. Yes, I think so:
I have attached the full log log.txt
But I was following instruction from here: https://github.com/braintree/braintree-android-drop-in
build.gradle: