GithubHelp home page GithubHelp logo

alethes / braintree Goto Github PK

View Code? Open in Web Editor NEW

This project forked from patrickml/braintree

0.0 3.0 0.0 12 KB

Meteor JS wrapper for Braintree Payments.

License: MIT License

JavaScript 100.00%

braintree's Introduction

BrainTreeConnect

A wrapper for Meteor style synchronous Braintree API calls.

Example Usage

try{
    var bt = BrainTreeConnect({
      //If you set an ENV variable for PRODUCTION you can dynamically change out sandbox and production
      environment: process.env.PRODUCTION && Braintree.Environment.Production || Braintree.Environment.Sandbox,
      merchantId: Meteor.settings.BRAIN_TREE.MERCHANT_ID,
      publicKey:  Meteor.settings.BRAIN_TREE.PUBLIC_KEY,
      privateKey: Meteor.settings.BRAIN_TREE.PRIVATE_KEY
    });
    return bt.customer.create(config);
} catch(error){
    throw new Meteor.Error(1001, error.message);
}

Client API

In case you are wanting to use the client API to create the nonce token you should include the following script in your head.html file

	<script src="https://js.braintreegateway.com/v2/braintree.js"></script>

Wrapped API

This package wraps the methods below. These are all the methods that are listed in the braintree-node github documentation & the braintree-website documentation.

##Webhooks (Example) ##

This example uses Iron Router but you can you any server side routing package

Router.route('receiveMerchantUpdate', function () {

      // NodeJS request object
      var request = this.request;

      // NodeJS  response object
      var response = this.response;

      var bt_challenge = request.query.bt_challenge;

      var bt = BrainTreeConnect({
        environment: process.env.PRODUCTION && Braintree.Environment.Production || Braintree.Environment.Sandbox,
        merchantId: Meteor.settings.BRAIN_TREE.MERCHANT_ID,
        publicKey: Meteor.settings.BRAIN_TREE.PUBLIC_KEY,
        privateKey: Meteor.settings.BRAIN_TREE.PRIVATE_KEY
      });

      //If we are verifying the webhook
      if(bt_challenge) {
        return response.end(bt.webhookNotification.verify(bt_challenge));
      } else {
      
//Decode the request and perform the needed logic for the type of request
 bt.webhookNotification.parse(request.body.bt_signature, request.body.bt_payload, function (err, webhookNotifiction) {
          switch(webhookNotifiction.kind) {

            //Sub Merchant was Approved
            case Braintree.WebhookNotification.Kind.SubMerchantAccountApproved:

              //Find and Update the user
              Meteor.users.update({ 'profile.merchantAccount.id' :  webhookNotifiction.merchantAccount.id }, { $set : {
                'profile.merchantAccount' : webhookNotifiction.merchantAccount
              }});

              console.log('Success');
              break;

            //Supplier was declined
            case Braintree.WebhookNotification.Kind.SubMerchantAccountDeclined:
              console.log('Failed');
              break;
          }

        });

        return response.end();
      }
    },
    {
      where: 'server',
      path: 'hooks/processor/merchants'
    });

braintree's People

Contributors

alethes avatar maxjgoldberg12 avatar patrickml avatar pem-- avatar sam-kamerer avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.