简体   繁体   English

格子条纹滑轨应用程序

[英]Plaid with Stripe Rails app

I have an application successfully using Stripe to charge users for access to an application. 我有一个成功使用Stripe的应用程序,向用户收取访问应用程序的费用。 Building on to this, I would like to implement Plaid in my checkout process. 在此基础上,我想在结帐过程中实施Plaid。 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. 由于这是我第一次实现Stripe,现在是我第一次使用Plaid,因此我对方向以及如何推动此功能感到困惑。

I installed the plaid-ruby gem , and added my Plaid secret_key and client_id via figaro but now I am lost. 我安装了格子红宝石gem ,并通过figaro添加了我的格子secret_key和client_id,但现在我迷路了。

Plaid.rb: Plaid.rb:

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

The Plaid Link: 格子链接:

       <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: '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() {
          linkHandler.open();
        };
        </script>

Here's what I have in my controller for Stripe: 这是我的Stripe控制器中的内容:

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

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

      current_user.update(
        stripe_id: customer.id,
      )

       stripe_charge = Stripe::Charge.create(
         customer:    customer.id,
         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? 要通过“格子和条纹”创建费用,我需要在控制器中或其他地方包含什么?

Plaid has a writeup on how to wire this up - though the provided example is in Node.js - and Stripe has a guide too. 尽管提供的示例在Node.js中,但Plaid 撰写了有关如何进行此连接的文章-Stripe也提供了指南

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. 就是说,您需要在onSuccess处理程序中添加代码,以将public_tokenmetadata.account_id发送到服务器的“令牌交换”端点 ,一旦获得,就可以将其交换为Stripe令牌 ,最后,您需要将该令牌附加到客户。

So, something like this: 因此,如下所示:

plaid_user = Plaid::User.exchange_token(
  public_token,
  metadata_dot_account_id,
  product: :auth
)

puts plaid_user.stripe_bank_account_token

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

customer.sources.create({
  :source => plaid_user.stripe_bank_account_token
})

And then you can do your Stripe::Charge.create() . 然后,您可以执行Stripe::Charge.create()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM