How to use braintree-web - 10 common examples

To help you get started, we’ve selected a few braintree-web examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github braintree / braintree-web-drop-in / src / views / payment-sheet-views / apple-pay-view.js View on Github external
ApplePayView.prototype.initialize = function () {
  var self = this;
  var isProduction = self.client.getConfiguration().gatewayConfiguration.environment === 'production';

  self.applePayConfiguration = assign({}, self.model.merchantConfiguration.applePay);
  self.applePaySessionVersion = self.applePayConfiguration.applePaySessionVersion || DEFAULT_APPLE_PAY_SESSION_VERSION;

  delete self.applePayConfiguration.applePaySessionVersion;

  self.model.asyncDependencyStarting();

  return btApplePay.create({client: this.client}).then(function (applePayInstance) {
    var buttonDiv = self.getElementById('apple-pay-button');

    self.applePayInstance = applePayInstance;

    self.model.on('changeActivePaymentView', function (paymentViewID) {
      if (paymentViewID !== self.ID) {
        return;
      }

      global.ApplePaySession.canMakePaymentsWithActiveCard(self.applePayInstance.merchantIdentifier).then(function (canMakePayments) {
        if (!canMakePayments) {
          if (isProduction) {
            self.model.reportError('applePayActiveCardError');
          } else {
            console.error('Could not find an active card. This may be because you\'re using a production iCloud account in a sandbox Apple Pay Session. Log in to a Sandbox iCloud account to test this flow, and add a card to your wallet. For additional assistance, visit  https://help.braintreepayments.com'); // eslint-disable-line no-console
            self.model.reportError('developerError');
github braintree / braintree-web-drop-in / src / views / payment-method-views / paypal-view.js View on Github external
PayPalView.prototype._initialize = function () {
  var paypalButton;

  BasePaymentMethodView.prototype._initialize.apply(this, arguments);
  this._createPayPalButton();
  this.model.asyncDependencyStarting();

  PayPal.create({client: this.options.client}, function (err, paypalInstance) {
    if (err) {
      // TODO: handle errors in PayPal creation
      console.error(err);
      return;
    }

    this.paypalInstance = paypalInstance;

    paypalButton = this.getElementById('paypal-button');
    paypalButton.addEventListener('click', this._tokenize.bind(this));

    this.model.asyncDependencyReady();
  }.bind(this));
};
github braintree / braintree-web-drop-in / test / unit / lib / analytics.js View on Github external
it('includes braintreeLibraryVersion', function () {
    var postArgs;

    analytics.sendEvent(this.client, 'test.event.kind');

    expect(this.client._request).to.have.been.called;
    postArgs = this.client._request.firstCall.args;

    expect(postArgs[0].data.braintreeLibraryVersion).to.equal(braintreeClientVersion);
  });
});
github mozilla / payments-ui / public / js / actions / pay-methods.js View on Github external
export function addCreditCard({braintreeToken, creditCard, fetch=api.fetch,
                               BraintreeClient=braintree.api.Client,
                               processingId}) {
  return (dispatch, getState) => {
    dispatch(processingActions.beginProcessing(processingId));
    var client = new BraintreeClient({
      clientToken: braintreeToken,
    });
    client.tokenizeCard({
      number: creditCard.number,
      expirationDate: creditCard.expiration,
      cvv: creditCard.cvv,
    }, function(err, nonce) {
      if (err) {
        console.error('Braintree tokenization error:', err);
        dispatch(notificationActions.showError(
          {errorCode: errorCodes.BRAINTREE_TOKENIZATION_ERROR}));
      } else {
github mozilla / payments-ui / static / public / js / actions / pay-methods.js View on Github external
export function addCreditCard({braintreeToken, creditCard, fetch=api.fetch,
                               BraintreeClient=braintree.api.Client,
                               processingId}) {
  return (dispatch, getState) => {
    dispatch(processingActions.beginProcessing(processingId));
    var client = new BraintreeClient({
      clientToken: braintreeToken,
    });
    client.tokenizeCard({
      number: creditCard.number,
      expirationDate: creditCard.expiration,
      cvv: creditCard.cvv,
    }, function(err, nonce) {
      if (err) {
        console.error('Braintree tokenization error:', err);
        dispatch(notificationActions.showError(
          {errorCode: errorCodes.BRAINTREE_TOKENIZATION_ERROR}));
      } else {
github mozilla / payments-ui / public / js / actions / transaction.js View on Github external
export function processPayment({productId, braintreeToken, creditCard,
                                payMethodUri, processingId,
                                BraintreeClient=braintree.api.Client,
                                createSubscription=defaultCreateSubscription,
                                payOnce=_processOneTimePayment,
                                ...args}) {
  return (dispatch, getState) => {
    dispatch(processingActions.beginProcessing(processingId));
    var product = products.get(productId);
    var payForProduct;

    if (product.recurrence === 'monthly') {
      console.log('calling _createSubscription for product',
                  product.id);
      payForProduct = createSubscription;
    } else {
      console.log('calling _processOneTimePayment for product',
                  product.id);
      payForProduct = payOnce;
github mozilla / payments-ui / public / js / actions / transaction.js View on Github external
export function processPayment({productId, braintreeToken, creditCard,
                                payMethodUri,
                                BraintreeClient=braintree.api.Client,
                                createSubscription=defaultCreateSubscription,
                                payOnce=processOneTimePayment,
                                ...args}) {
  return (dispatch, getState) => {
    var product = products.get(productId);
    var payForProduct;

    if (product.recurrence === 'monthly') {
      console.log('calling createSubscription for product',
                  product.id);
      payForProduct = createSubscription;
    } else {
      console.log('calling processOneTimePayment for product',
                  product.id);
      payForProduct = payOnce;
    }
github mozilla / payments-ui / static / public / js / actions / transaction.js View on Github external
export function processPayment({productId, braintreeToken, creditCard,
                                payMethodUri, processingId,
                                BraintreeClient=braintree.api.Client,
                                createSubscription=defaultCreateSubscription,
                                payOnce=_processOneTimePayment,
                                ...args}) {
  return (dispatch, getState) => {
    dispatch(processingActions.beginProcessing(processingId));
    var product = products.get(productId);
    var payForProduct;

    if (product.recurrence === 'monthly') {
      console.log('calling _createSubscription for product',
                  product.id);
      payForProduct = createSubscription;
    } else {
      console.log('calling _processOneTimePayment for product',
                  product.id);
      payForProduct = payOnce;
github mozilla / donate-wagtail / source / js / payments-card.js View on Github external
function initHostedFields() {
    client.create({ authorization: braintreeParams.token }, function (
      clientErr,
      clientInstance
    ) {
      if (clientErr) {
        showErrorMessage(loadingErrorMsg);
        return;
      }

      dataCollector.create({ client: clientInstance, kount: true }, function (
        clientErr,
        dataCollectorInstance
      ) {
        if (clientErr) {
          showErrorMessage(loadingErrorMsg);
          return;
        }
github nathanstitt / react-braintree-fields / src / api.js View on Github external
setAuthorization(authorization, onAuthorizationSuccess) {
        if (!authorization && this.authorization) {
            this.teardown();
        } else if (authorization && authorization !== this.authorization) {
            if (this.authorization) { this.teardown(); }
            this.authorization = authorization;
            Braintree.create({ authorization }, (err, clientInstance) => {
                if (err) {
                    this.onError(err);
                } else {
                    this.create(clientInstance, onAuthorizationSuccess);

                    if (this.wrapperHandlers.onDataCollectorInstanceReady) {
                        BraintreeDataCollector.create({
                            client: clientInstance,
                            kount: true,
                        }, this.wrapperHandlers.onDataCollectorInstanceReady);
                    }
                }
            });
        }
    }