Braintree paypal

android

#1

Hello, how are you all?

Recently I am developing a Braintree plugin with paypal but apparently I do not get references of my created objecters, help please.

import { Common } from './paypal-checkout.common';
import * as app from "tns-core-modules/application";

declare const com: any;

export class PaypalCheckout extends Common {

    private braintree: any; // com.braintreepayments.api.BraintreeFragment

    paypalRequest(options: PaypalOptions): Promise<any> {
        return new Promise(function (resolve, reject) {

            try {
                let activity = app.android.startActivity || app.android.foregroundActivity;
                this.braintree = com.braintreepayments.api.BraintreeFragment.newInstance(activity, options.token);
            } catch(error) {
               reject("Braintree created error: " + error);
            }

            let request = new com.braintreepayments.api.models.PayPalRequest(options.amount).currencyCode(options.currencyCode);
            com.braintreepayments.api.PayPal.requestOneTimePayment(this.braintree, request);

            this.braintree.addListener(new com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener({
                    onPaymentMethodNonceCreated: function(paymentMethodNonce) {
                        resolve(paymentMethodNonce.getNonce());
                    }
                })
            );

            this.braintree.addListener(new com.braintreepayments.api.interfaces.BraintreeErrorListener({
                    onError: function(error) {
                        reject(error);
                    }
                })
            );
        });
    }
}

export interface PaypalOptions {
    token: string;
    amount: string;
    currencyCode: string;
}

Error: TypeError: Cannot read property 'newInstance' of undefined


#2

Here error, please help


#3

Did you make sure your dependencies are installed properly? Tried a clean build?


#4

Yes, file include.gradle is:


android {

}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }
}

dependencies {
    // Describe plugin native Android dependencies like
	  compile "com.braintreepayments.api:braintree:2.+"
}

and AndroidManifest.xml:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

  <!--Describe the permissions, features or other configurations required by your plugin for Android. To read more about android permissions go to https://developer.android.com/guide/topics/permissions/index.html -->
  <!--EXAMPLE: uses-permission android:name="android.permission.INTERNET"/> -->
  <application>
    <activity android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity" android:launchMode="singleTask">
      <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="${applicationId}.braintree"/>
      </intent-filter>
    </activity>
  </application>

</manifest>

#5

Thanks, recreate a new project and it worked