How to use the braintree.connect function in braintree

To help you get started, we’ve selected a few braintree 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 tipp-us / tipp-us / server / routes.js View on Github external
var helpers = require('./helpers.js');
var braintree = require('braintree');

var gateway;

// if running on Heroku
if (process.env.BRAINTREE_MERCHANTID) {
  gateway = braintree.connect({
    environment: braintree.Environment.Sandbox,
    merchantId: process.env.BRAINTREE_MERCHANTID,
    publicKey: process.env.BRAINTREE_PUBLICKEY,
    privateKey: process.env.BRAINTREE_PRIVATEKEY,
  });
} else { // running locally
  var config = require('./config.js');
  gateway = braintree.connect({
    environment: braintree.Environment.Sandbox,
    merchantId: config.braintree.merchantId,
    publicKey: config.braintree.publicKey,
    privateKey: config.braintree.privateKey,
  });
}

// Get info of single artist
app.get('/artists/id/:id', function(req, res) {
  var artistId = req.params.id;
  db.artist.findOne({where: {id: artistId}, include: [db.show]})
    .then(function(artist) {

      if (artist === null) {
        res.status(404).end('ArtistID ' + artistId + ' not found.');
      }
github braintreedev / sample-11-braintree-android-sdk / server / routes / index.js View on Github external
var express = require('express');
var router = express.Router();

var braintree = require('braintree');

var gateway = braintree.connect({
  environment: braintree.Environment.Sandbox,
  merchantId: "ffdqc9fyffn7yn2j",
  publicKey: "qj65nndbnn6qyjkp",
  privateKey: "a3de3bb7dddf68ed3c33f4eb6d9579ca"
});

/* GET Creates a new token and returns it in the response */
router.get('/token', function (req, res) {
  gateway.clientToken.generate({}, function (error, response) {
    if (!error) {
      res.send(response.clientToken);
    } else {
      res.send(response);
    }
  });
});
github opencollective / opencollective-api / server / paymentProviders / paypalbt / index.js View on Github external
import braintree from 'braintree';
import config from 'config';
import jwt from 'jsonwebtoken';

import * as constants from '../../constants/transactions';
import * as libpayments from '../../lib/payments';
import models from '../../models';
import errors from '../../lib/errors';

const gateway = braintree.connect({
  environment: config.paypalbt.environment,
  clientId: config.paypalbt.clientId,
  clientSecret: config.paypalbt.clientSecret,
});

/** Return the URL needed by the PayPal Braintree client */
async function oauthRedirectUrl(remoteUser, CollectiveId) {
  const hostCollective = await models.Collective.findById(CollectiveId);
  const state = jwt.sign({
    CollectiveId,
    CreatedByUserId: remoteUser.id
  }, config.keys.opencollective.secret, {
    // People may need some time to set up their Paypal Account if
    // they don't have one already
    expiresIn: '45m'
  });
github opencollective / opencollective-api / server / paymentProviders / paypalbt / index.js View on Github external
async function getMerchantGateway(collective) {
  // Merchant ID of the host account
  const hostCollectiveId = await collective.getHostCollectiveId();
  if (!hostCollectiveId) throw new errors.BadRequest('Can\'t retrieve host collective id');
  const connectedAccount = await models.ConnectedAccount.findOne({
    where: { service: 'paypalbt', CollectiveId: hostCollectiveId } });
  if (!connectedAccount) throw new errors.BadRequest('Host does not have a paypal account');
  const { token } = connectedAccount;
  return braintree.connect({
    accessToken: token,
    environment: config.paypalbt.environment,
  });
}
github nestjsx / nestjs-braintree / src / __tests__ / webhooks.spec.ts View on Github external
trialEnded() {
      TestProvider.called = 'trialEnded';
    }

    @BraintreeSubscriptionWentPastDue()
    wentPastDue() {
      TestProvider.called = 'wentPastDue';
    }

    @BraintreeSubscriptionWentActive()
    wentActive() {
      TestProvider.called = 'wentActive';
    }
  }

  const gateway = braintree.connect({
    environment: braintree.Environment.Sandbox,
    merchantId: 'merchantId',
    publicKey: 'publicKey',
    privateKey: 'privateKey',
  });

  beforeEach(async () => {
    module = await Test.createTestingModule({
      imports: [
        BraintreeModule.forRoot({
          environment: braintree.Environment.Sandbox,
          merchantId: 'merchantId',
          publicKey: 'publicKey',
          privateKey: 'privateKey',
        }),
        BraintreeWebhookModule,
github reactioncommerce / reaction / imports / plugins / included / payments-braintree / server / methods / braintreeApi.js View on Github external
function getGateway(isNewPayment) {
  const accountOptions = getAccountOptions(isNewPayment);
  if (accountOptions.environment === "production") {
    accountOptions.environment = Braintree.Environment.Production;
  } else {
    accountOptions.environment = Braintree.Environment.Sandbox;
  }
  const gateway = Braintree.connect(accountOptions);
  return gateway;
}
github deltaepsilon / quiver-cms / lib / controllers / payment.js View on Github external
var Q = require('q'),
		_ = require('underscore'),
		ConfigService = require('../services/config-service'),
		FirebaseService = require('../services/firebase-service'),
		ObjectService = require('../services/object-service'),
		PaymentService = require('../services/payment-service'),
		braintree = require('braintree'),
		gateway = braintree.connect({
			environment: braintree.Environment[ConfigService.get('private.braintree.environment') || 'Sandbox'],
			merchantId: ConfigService.get('private.braintree.merchantId'),
			publicKey: ConfigService.get('private.braintree.publicKey'),
			privateKey: ConfigService.get('private.braintree.privateKey')
		});

module.exports = {
	getClientToken: function (req, res) {
		PaymentService.clientToken(req.user.id, function (err, response) {
			if (err) {
          res.status(500).send(err);
      } else {
          res.status(200).send(response.clientToken);
      }
		});
github fluidtrends / carmel / chunks / payments / functions / pay.js View on Github external
const makeGateway = ({ config }) => {
  return braintree.connect({
    environment: braintree.Environment[config.settings.braintree.environment],
    merchantId: config.settings.braintree.merchantId,
    publicKey: config.settings.braintree.publicKey,
    privateKey:config.settings.braintree.privateKey
  })
}
github paypal / paypal-checkout-components / demo / app / server / lib / braintree.js View on Github external
var braintree = require('braintree');


var gateway = braintree.connect({
    accessToken: 'access_token$sandbox$3w2ttvwd246548hd$829117ab3d240f371c0b2069492b8453'
});


module.exports = {
  clientToken: () => {
      
      var response = new Promise((resolve, reject) => {
         gateway.clientToken.generate({}, (err, res) => {
             if (err || res.success === false) {
                 reject(err);
             }
             
             resolve(res);
         }); 
      });

braintree

A library for server-side integrating with Braintree.

MIT
Latest version published 2 months ago

Package Health Score

71 / 100
Full package analysis