I have a simple rails website to which I need to add a payments gateway now. I see a railscast on integrating activemerchant with paypal but I wanted to use braintree instead.
I am unable to find any tutorials that show how braintree can be integrated to a rails app end to end. I see that people have good things to say about braintree but how about a tutorial?
Has someone used this payment gateway for their rails application? Would it be similar to the railscasts with paypal...just replace paypal with braintree?
Active Merchant is a much more flexible choice since it gives your company the freedom to change gateways without significant code changes. The original question was how to integrate it with Active Merchant, not how to use BT's proprietary API. Here's the answer I found after some digging through the code. You can find your public key, private key and merchant id under "Account" -> "My User" -> "API Keys".
gateway = ActiveMerchant::Billing::BraintreeGateway.new(
:merchant_id => 'Your Merchant ID',
:public_key => 'Your Public Key',
:private_key => 'Your Private Key'
)
creditcard = ActiveMerchant::Billing::CreditCard.new(
:type => 'visa',
:number => '41111111111111111',
:month => 10,
:year => 2014,
:first_name => 'Bob',
:last_name => 'Bobsen'
)
response = gateway.purchase(1000, creditcard)
STDERR.puts response.success?
STDERR.puts response.message
STDERR.puts response.authorization
The guys at Braintree created their own gem based on their API. It's very easy to setup and do actual transactions with. You can view the code on Github and a quick example can be found here. Full projects with Rails integration are located here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With