Stripe ACH + Plaid + Rails

Stripe ACH processes large volumes of credit and debit transactions. Its also connected with plaid for instant verification of bank account. You can directly charge on customer once it’s verified. Here I’ve explained on how to integrate it with ruby.

Plaid and Stripe have partnered to offer frictionless money transfers without the need to ever handle an account or routing number. Use Plaid Link to instantly authenticate your customer’s account and automatically generate a Stripe bank account token so that you can accept ACH payments via their ACH API.

Step 1. Setup Strip and Plaid

First you need setup stripe and plaid . If not please use following links

Stripe: https://dashboard.stripe.com/register
Plaid: https://dashboard.plaid.com/signup/stripe/

Then you need to activate ACH Access. If you see following link in ACH Guide after sign up, Click ‘Accept Terms of Service’ to enable your Stripe account for ACH

stripe-ach-not-enabled

To verify that your Plaid account is enabled for the integration, go to the account dashboard. If you see:

dashboard-stripe-account-unlinked

Click the ‘Connect With Stripe’  and follow the steps. If you did not connect to your stripe to plaid you can’t get stripe bank token.

Once your Stripe account is connected, you’ll see:

Your Plaid account is now set up for the integration!

dashboard-stripe-account-linked

Step 2: Integrate with Plaid Link

Once your Plaid account is setup and connected to your Stripe account, add Plaid Link to your site.

<button id='linkButton'> Open Plaid Link< /button>
<script src="https://cdn.plaid.com /link/stable/link-initialize. js"> < /script>
<script>
var linkHandler = Plaid.create({
  env: 'tartan',
  clientName: 'Stripe / Plaid Test',
  key: '[Plaid key]',
  product: 'auth',
  selectAccount: true,
  onSuccess: function(public_token, metadata) {
    // Send the public_token and account ID to your app server.
    console.log('public_token: ' + public_token);
    console.log('account ID: ' + metadata.account_id);
  },});
// Trigger the Link UI
document.getElementById ('linkButton').onclick = function() {
  linkHandler.open();
};
</script>

Step 3: Integrate with rails using plaid-ruby library

Include plaid-ruby in your gem file and configure plaid in config/application.rb

Plaid.config do |p|
  p.customer_id = 'Plaid provided customer ID here'
  p.secret = 'Plaid provided secret key here'
  p.environment_location = 'URL for the development or production environment'
  # i.e. 'https://tartan.plaid.com/' for development, or
  # 'https://api.plaid.com/' for production
end

Step 4: Integrate With Stripe ACH

With Stripe, you can accept ACH payments in nearly the same way as you accept credit card payments, merely providing a verified bank account as the source argument for a charge request. However, accepting bank accounts requires a slightly different initial workflow than accepting credit cards:

1. Bank accounts must first be verified.

2. Bank accounts must be authorized for your use by the customer.

Plaid provides the quickest way to collect and verify your customer’s banking information. Using the Stripe + Plaid integration, you’re able to instantly receive a verified bank account, allowing for immediate charging.

To get stripe bank token you request plaid with

exchangeTokenResponse = Plaid.exchange_token( public_token, account_id)

it will return following details

{
  "sandbox": false,
  "access_token": "[Plaid API access token]",
  "stripe_bank_account_token": “[Stripe Bank Token]”,
  "account_id": "[Plaid Account ID]"
}

You can attach this token to a Stripe Customer object, or create a charge directly on it.

Stripe.api_key = “stripe_secret_key”
customer = Stripe::Customer.create(
:email =>’email’,
:description => “description",
:source => exchangeTokenResponse. stripe_bank_account_token)

You can use this customer object to charge

Stripe.api_key = “stripe token"
Stripe::Charge.create(
  :amount   => 1500,
  :currency => "usd",
  :customer => customer_id
)

You can use this token for linking bank account to stripe account. But the stripe bank valid for one time usage. Request once again to get exchangeTokenResponse and link your bank to stripe.

stripe_account = Stripe::Account.retrieve (‘Connected Account id’)
stripe_account.external_accounts. create(
:external_account => exchangeTokenResponse. stripe_bank_account_token)

This will create bank account for connected stripe account

Hope this is helpful..

Prakash,
ROR Developer,
Mallow Technologies.

Leave a Reply

%d bloggers like this: