Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

braintree-web

Package Overview
Dependencies
Maintainers
1
Versions
279
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

braintree-web

A suite of tools for integrating Braintree in the browser

  • 3.112.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
279K
increased by5.52%
Maintainers
1
Weekly downloads
 
Created

What is braintree-web?

The braintree-web npm package is a JavaScript SDK that allows you to integrate Braintree's payment processing services into your web application. It provides a variety of tools to handle different types of payments, including credit cards, PayPal, and more.

What are braintree-web's main functionalities?

Credit Card Payments

This feature allows you to integrate credit card payment forms into your web application using Braintree's hosted fields. The code sample demonstrates how to create a client instance and hosted fields for credit card number, CVV, and expiration date.

const braintree = require('braintree-web');
braintree.client.create({
  authorization: 'CLIENT_AUTHORIZATION'
}, function (err, clientInstance) {
  if (err) {
    console.error(err);
    return;
  }
  braintree.hostedFields.create({
    client: clientInstance,
    styles: {
      'input': {
        'font-size': '14px'
      },
      'input.invalid': {
        'color': 'red'
      },
      'input.valid': {
        'color': 'green'
      }
    },
    fields: {
      number: {
        selector: '#card-number',
        placeholder: '4111 1111 1111 1111'
      },
      cvv: {
        selector: '#cvv',
        placeholder: '123'
      },
      expirationDate: {
        selector: '#expiration-date',
        placeholder: '10/2022'
      }
    }
  }, function (err, hostedFieldsInstance) {
    if (err) {
      console.error(err);
      return;
    }
    hostedFieldsInstance.on('validityChange', function (event) {
      var field = event.fields[event.emittedBy];
      if (field.isValid) {
        console.log('Field is valid');
      } else {
        console.log('Field is invalid');
      }
    });
  });
});

PayPal Payments

This feature allows you to integrate PayPal payments into your web application. The code sample demonstrates how to create a client instance and a PayPal instance, and then tokenize a PayPal payment.

const braintree = require('braintree-web');
braintree.client.create({
  authorization: 'CLIENT_AUTHORIZATION'
}, function (err, clientInstance) {
  if (err) {
    console.error(err);
    return;
  }
  braintree.paypal.create({
    client: clientInstance
  }, function (err, paypalInstance) {
    if (err) {
      console.error(err);
      return;
    }
    paypalInstance.tokenize({
      flow: 'checkout',
      amount: '10.00',
      currency: 'USD'
    }, function (err, payload) {
      if (err) {
        console.error(err);
        return;
      }
      console.log('PayPal payment tokenized:', payload.nonce);
    });
  });
});

Apple Pay

This feature allows you to integrate Apple Pay into your web application. The code sample demonstrates how to create a client instance and an Apple Pay instance, and then handle the Apple Pay payment process.

const braintree = require('braintree-web');
braintree.client.create({
  authorization: 'CLIENT_AUTHORIZATION'
}, function (err, clientInstance) {
  if (err) {
    console.error(err);
    return;
  }
  braintree.applePay.create({
    client: clientInstance
  }, function (err, applePayInstance) {
    if (err) {
      console.error(err);
      return;
    }
    var paymentRequest = applePayInstance.createPaymentRequest({
      total: {
        label: 'Your Label',
        amount: '10.00'
      },
      requiredBillingContactFields: ['postalAddress']
    });
    var session = new ApplePaySession(1, paymentRequest);
    session.onvalidatemerchant = function (event) {
      applePayInstance.performValidation({
        validationURL: event.validationURL,
        displayName: 'Your Store'
      }, function (err, merchantSession) {
        if (err) {
          console.error(err);
          session.abort();
          return;
        }
        session.completeMerchantValidation(merchantSession);
      });
    };
    session.onpaymentauthorized = function (event) {
      applePayInstance.tokenize({
        token: event.payment.token
      }, function (err, payload) {
        if (err) {
          console.error(err);
          session.completePayment(ApplePaySession.STATUS_FAILURE);
          return;
        }
        console.log('Apple Pay payment tokenized:', payload.nonce);
        session.completePayment(ApplePaySession.STATUS_SUCCESS);
      });
    };
    session.begin();
  });
});

Other packages similar to braintree-web

Keywords

FAQs

Package last updated on 19 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc