Plaid with Stripe Rails app

ruby-on-rails stripe-payments plaid

509 просмотра

1 ответ

348 Репутация автора

I have an application successfully using Stripe to charge users for access to an application. Building on to this, I would like to implement Plaid in my checkout process. Since this was my first time implementing Stripe, and now my first time with Plaid, I am a bit lost regarding the directions and how to push this feature forward.

I installed the plaid-ruby gem, and added my Plaid secret_key and client_id via figaro but now I am lost.


   Plaid.configuration.stripe = {
    p.client_id = ENV['PLAID_CLIENT_ID'],
    p.secret = ENV['PLAID_SECRET_KEY'],
    p.env = :tartan  # or :production

The Plaid Link:

       <button id='linkButton'>Open Plaid Link</button>
        <script src=""></script>
        var linkHandler = Plaid.create({
          env: 'tartan',
          clientName: 'ACCR',
          key: '<<< MY_PUBLIC_KEY >>>',
          product: 'auth',
          selectAccount: true,
          env: 'tartan',
          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() {

Here's what I have in my controller for Stripe:

    def new 
    @stripe_btn_data = {
     key: "#{ Rails.configuration.stripe[:publishable_key] }",

  #1 Create a charge
      customer = if current_user.stripe_id?
                    Stripe::Customer.create(email: :stripeEmail)


       stripe_charge = Stripe::Charge.create(
         amount:      (current_order.subtotal * 100).to_i,
         currency:    'usd',
... more information to create an order then send email after charge. 

What do I need to include in my controller, or elsewhere, to create a charge via Plaid and Stripe?

Автор: jgrant Источник Размещён: 18.07.2016 11:34

Ответы (1)

3 плюса

4835 Репутация автора


Plaid has a writeup on how to wire this up - though the provided example is in Node.js - and Stripe has a guide too.

That said, you'll need to add code in the onSuccess handler to send the public_token and metadata.account_id to your server's 'token exchange' endpoint and once you've got that, you can exchange those for the Stripe token, and finally, you'll need to attach that token to the Customer.

So, something like this:

plaid_user = Plaid::User.exchange_token(
  product: :auth

puts plaid_user.stripe_bank_account_token

customer = Stripe::Customer.retrieve("<customer-id>")

  :source => plaid_user.stripe_bank_account_token

And then you can do your Stripe::Charge.create().

Автор: floatingLomas Размещён: 19.07.2016 12:38
Вопросы из категории :