Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to integrate braintree-web into Angular2

I am trying to use the Braintree SDK (braintree-web) in my Angular2 app. I'd really appreciate any pointers on how to get this working. I think it is because I am not importing the braintree-web module, but I can't figure out how to to that either. I can find any exports in the whole module.

Here is where I am:

I've imported the braintree-web library and a typings file I found.

ng install --save braintree-web
npm install @types/[email protected]

I tried to hack the JS example Braintree provides into a Angular2 TS Component, but I keep getting an error:

EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./UpaccountComponent class UpaccountComponent - inline template:5:7 ORIGINAL EXCEPTION: TypeError: this.braintree.setup is not a function

Here is the .ts file.

import { Component, OnInit } from '@angular/core';


declare var braintree:any;

@Component({
  selector: 'up-btcheckoutform',
  templateUrl: './btcheckoutform.component.html',
  styleUrls: ['./btcheckoutform.component.css']
})
export class BtCheckoutFormComponent implements OnInit {
  braintree = require('BrainTreeWeb');
  // braintree = require('braintree-web');
  integration: any

  constructor() {   }

  ngOnInit() {
    var c = this;
    var clientToken = "CLIENT_TOKEN_GOES_HERE";
    braintree.setup(clientToken, "dropin", {
      container: "payment-form",
      onReady: function(int) {
        c.integration = int
        }
      });
  }

  ngOnDestroy() {
    this.integration.teardown();
  }


}
like image 375
SeekingMoneky Avatar asked Nov 01 '16 03:11

SeekingMoneky


People also ask

What is Braintree and how does it work?

For starters, Braintree is a division of PayPal. So if you’re looking for PayPal integration, then you’re all set. Beyond that, though, you can use Braintree to accept Most major credit cards, Apple Pay, Google Pay, and Venmo. What’s not to love?

Can I use Braintree direct with Spring Boot?

Beyond that, though, you can use Braintree to accept Most major credit cards, Apple Pay, Google Pay, and Venmo. What’s not to love? In this article, we’ll go over how you can implement a Braintree Direct solution within your Spring Boot application.

How do I integrate firebase with angular?

The Firebase team offers the package @angular/fire, which provides integration between the two technologies. To add Firebase support to your app open your workspace's root directory and run: This command installs the @angular/fire package and asks you a few questions. In your terminal, you should see something like:

What payment methods does Braintree accept?

So if you’re looking for PayPal integration, then you’re all set. Beyond that, though, you can use Braintree to accept Most major credit cards, Apple Pay, Google Pay, and Venmo. What’s not to love?


Video Answer


1 Answers

I'm not sure about the usage of braintree-web specifically, but if you're using webpack, remove the lines declare var braintree:any; and braintree = require('BrainTreeWeb');

You'll also need to add the braintree-web/index.js file to the bundle, unless they've got a UMD module.

From a quick glance at braintree-web, it looks like braintree.setup(..) isn't a function. Something like this might be equivalent:

braintree.client.create({ 
      authorization: "long-token-string"},
      (err, client) => {
            // Do stuff here
            client.request({..});
      });

With the package installs, you'll need to have added --save-dev to the types install.

like image 139
Fiddles Avatar answered Nov 15 '22 18:11

Fiddles