This is my first time using curl in my Rails 4 App. I am trying to use Plaid with Stripe. I am able to successful exchange the public token for the stripe bank account token.
Here's my controller action.
def create
results = `curl https://tartan.plaid.com/exchange_token \
-d client_id="CLIENT_ID" \
-d secret="SECRET_KEY" \
-d public_token="#{params[:public_token]}" \
-d account_id="#{params[:meta][:account_id]}"`
end
In Terminal with JSON.parse(results)
{"account_id"=>"ACCOUNT_ID", "stripe_bank_account_token"=>"12345678abcd", "sandbox"=>true, "access_token"=>"test_citi"}
How does one get the stripe_bank_account_token into the controller?
UPDATE
I am using the Figaro Gem to hide the params/credentials..
results =
`curl https://tartan.plaid.com/exchange_token \
-d client_id="#{ ENV['PLAID_CLIENT_ID'] }" \
-d secret="#{ ENV['PLAID_SECRET_KEY'] }" \
-d public_token="#{params[:public_token]}" \
-d account_id="#{params[:meta][:account_id]}"`
# here's how I get the stripe_bank_account_token
break_down = JSON.parse(results)
x = break_down.select { |key, val| key == "stripe_bank_account_token" }
You shouldn't pipe to curl from Ruby code especially when it involves user input.
Rather you should use the built in Ruby HTTP Client, a gem like RestClient, or even better the Plaid Ruby Gem.
gem install plaid
then just
require 'Plaid'
Plaid.config do |p|
p.client_id = '<<< Plaid provided client ID >>>'
p.secret = '<<< Plaid provided secret key >>>'
p.env = :tartan # or :api for production
end
user = Plaid::User.exchange_token(params[:public_token], params[:meta][:account_id], product: :auth)
user.stripe_bank_account_token