jgrant jgrant - 4 months ago 15
JSON Question

Parse curl information in Rails application

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.

Stripe with Plaid ACH

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?

Answer

Just create new method for plaid, smth like below.

def create
    res = plain_curl(params)
    puts res.inspect #there you will see your respond json obj in rails console.
end

private

def plain_curl(params)
  #it should return you json object, if not just add return before result.
  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