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.
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'
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.
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:
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'>
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
...
This sample implementation of this component showcases how to process a payment after receiving the token.
- Add a Volt Task that wraps around most of the Braintree API so you dont need to write your own runners.
- Fork it ( http://github.com/cbetta/volt-braintree/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request