Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "braintree in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'braintree' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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.');
      }
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);
    }
  });
});
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'
  });
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,
  });
}
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);
  });
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);
  });
});
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');
  });
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);
  });
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');
  });
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,
      ),
    );

Is your System Free of Underlying Vulnerabilities?
Find Out Now