braintree / braintree_node

Braintree Node.js library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
335 stars 104 forks source link

Cannot read property 'startPayment' of undefined #140

Closed pankajjjpr closed 6 years ago

pankajjjpr commented 6 years ago

Hi,

I am trying to add Braintree into my Nativescript- Angular app.

For this I took help from this link and was able to write the code.

https://market.nativescript.org/plugins/nativescript-braintree

I created a button with tap event to call a method "MakePayment()". The definition of the method at .ts file is as follows:

import { Braintree, BrainTreeOptions } from 'nativescript-braintree'; export class PrivacyPolicyComponent { private braintree: Braintree; public MakePayment() { try{ let opts: BrainTreeOptions = { amount: "10.0", collectDeviceData: false, requestThreeDSecureVerification: false, } let token = "sandbox_66qj9r76_qx2c2bc3znjs55fv"; //Get the token from server. https://developers.braintreepayments.com/start/hello-server/php

    this.braintree.startPayment(token, opts).then(() => {
    console.dir(this.braintree.output);
    alert(this.braintree.output.msg);
    // Now you have nonce. So you can push it to server :)
    }).catch(() => {
    console.dir(this.braintree.output);
    alert(this.braintree.output.msg);
    })

        this.braintree = new Braintree();
    }
   catch(error)
   {
       console.log("error occured:");
       console.log(error);
   }

}

}

I am doing just for demo and learning purpose, so i created a Token using my account. when i ran the app and topped the button then i got below error message: Cannot read property 'startPayment' of undefined

can anyone tell me what does it mean and why is it coming?

pankajjjpr commented 6 years ago

can anyone give any update on this issue?

crookedneighbor commented 6 years ago

Hi @pankajjjpr, this is the library for processing Braintree transactions on a node server.

The plugin you mentioned is not developed by Braintree. The Github repo for it is here: https://github.com/jibon57/nativescript-braintree

Based on the usage documentation, it looks like you are missing the step to instantiate it:

this.braintree = new Braintree();

I see you are doing that within the catch, but since calling this.braintree.startPayment is not within the promise, it's throwing an error that is not being caught by your promise.

For further help, I'd encourage you to open an issue on the plugin repo.