Home

Awesome

Volt::Braintree

A wrapper around the Braintree gem that provides you with a way to load the Braintree v.zero Drop-in with 1 line of code.

Installation

Add this line to your application's Gemfile:

gem 'volt-braintree'

And then execute:

$ bundle

Or install it yourself as:

$ gem install volt-braintree

And then add the dependency to your dependecies.rb

$ component 'braintree'

Usage

Configuration

Add the following initializer (e.g. app/main/initializers/server/braintree.rb):

  Braintree::Configuration.environment = :sandbox
  Braintree::Configuration.merchant_id = 'your_merchant_id'
  Braintree::Configuration.public_key = 'your_public_key'
  Braintree::Configuration.private_key = 'your_private_key'

You can sign up for your credentials on the Braintree website.

Integration

To add the Braintree form to your site simply add the component to your page:

  <form e-submit='process_payment'>
    <:braintree>
  </form>

Which will result in this form:

V.zero Example

You can specify additional options to generate the ClientToken by passing in arguments prefixed with the server__ name. For example to pass the client_id option when generating the ClientToken you specify the following:

   <:braintree server__customer_id='123'>

You can also pass in options to the loading of the Javascript library by prefixing it with client__ as follows:

  <:braintree client__form='alternative_form_name'>

Processing payment

To process the payment you should add an e-submit listener to the surrounding form. This form will be called twice, once before the card has been tokenised and once after. If you need the payment nonce generated by Braintree simply check for it's existence.

...
  def process_payment
    if page._payment_method_nonce
      # so something with page._payment_method_nonce
    else
      return false #stop the form from submitting
    end
  end
...

Example

This sample implementation of this component showcases how to process a payment after receiving the token.

Todos

Contributing

  1. Fork it ( http://github.com/cbetta/volt-braintree/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request