How to use braintree - 10 common examples

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__ / braintree.module.spec.ts View on Github external
it('Does it instance with options using registry', async () => {
    const module = await Test.createTestingModule({
      imports: [
        BraintreeModule.forRoot({
          environment: braintree.Environment.Sandbox,
          merchantId: 'merchantId',
          publicKey: 'publicKey',
          privateKey: 'privateKey',
        }),
      ],
    }).compile();

    const options = module.get(BRAINTREE_OPTIONS_PROVIDER);
    const provider = module.get(BraintreeProvider);

    expect(options.environment).toBe(braintree.Environment.Sandbox);
    expect(options.merchantId).toBe('merchantId');
    expect(options.publicKey).toBe('publicKey');
    expect(options.privateKey).toBe('privateKey');
    expect(provider).toBeInstanceOf(BraintreeProvider);
  });
github nestjsx / nestjs-braintree / src / __tests__ / braintree.module.spec.ts View on Github external
it('BraintreeModule.forFeature', async () => {
    @Module({
      imports: [BraintreeModule.forFeature()],
    })
    class TestModule {}

    const module: TestingModule = await Test.createTestingModule({
      imports: [
        BraintreeModule.forRoot({
          environment: braintree.Environment.Sandbox,
          merchantId: 'merchantId',
          publicKey: 'publicKey',
          privateKey: 'privateKey',
        }),
        TestModule,
      ],
    }).compile();

    const testProvider = module.select(TestModule).get(BraintreeProvider);

    expect(testProvider).toBeInstanceOf(BraintreeProvider);
  });
});
github nestjsx / nestjs-braintree / src / __tests__ / webhooks.spec.ts View on Github external
it('Canceled', async () => {
    const braintreeProvider = module.get(BraintreeProvider);
    const braintreeWebhookProvider = module.get(BraintreeWebhookProvider);

    const webhookNotification = await braintreeProvider.parseWebhook(
      gateway.webhookTesting.sampleNotification(
        braintree.WebhookNotification.Kind.SubscriptionCanceled,
      ),
    );

    braintreeWebhookProvider.handle(webhookNotification);

    expect(TestProvider.called).toBe('canceled');
  });
github nestjsx / nestjs-braintree / src / __tests__ / e2e / braintree.controller.e2e-spec.ts View on Github external
it('/braintree/webhook (POST) Canceled', async () => {
    const webhook = gateway.webhookTesting.sampleNotification(
      braintree.WebhookNotification.Kind.SubscriptionCanceled,
    );
    
    return await request(app.getHttpServer())
      .post('/braintree/webhook')
      .set('Content-Type', 'application/json')
      .send(webhook)
      .expect(201);
  });
github nestjsx / nestjs-braintree / src / __tests__ / webhooks.spec.ts View on Github external
it('TrialEnded', async () => {
    const braintreeProvider = module.get(BraintreeProvider);
    const braintreeWebhookProvider = module.get(BraintreeWebhookProvider);

    const webhookNotification = await braintreeProvider.parseWebhook(
      gateway.webhookTesting.sampleNotification(
        braintree.WebhookNotification.Kind.SubscriptionTrialEnded,
      ),
    );

    braintreeWebhookProvider.handle(webhookNotification);

    expect(TestProvider.called).toBe('trialEnded');
  });
github nestjsx / nestjs-braintree / src / __tests__ / braintree.webhook.provider.spec.ts View on Github external
const module: TestingModule = await Test.createTestingModule({
      imports: [
        ConfigModule.load(
          path.resolve(__dirname, '__stubs__', 'config', '*.ts'),
        ),
        BraintreeModule.forRootAsync({
          useFactory: async config => config.get('braintree'),
          inject: [ConfigService],
        }),
        BraintreeWebhookModule,
      ],
      providers: [SubscriptionProvider],
    }).compile();

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

    const braintreeProvider = module.get(BraintreeProvider);
    const webhookProvider = module.get(
      BraintreeWebhookProvider,
    );

    const webhookNotification = await braintreeProvider.parseWebhook(
      gateway.webhookTesting.sampleNotification(
        braintree.WebhookNotification.Kind.SubscriptionCanceled,
      ),
    );

braintree

A library for server-side integrating with Braintree.

MIT
Latest version published 2 months ago

Package Health Score

71 / 100
Full package analysis