【问题标题】:Plaid with Stripe Rails app格纹与 Stripe Rails 应用程序
【发布时间】:2016-11-21 16:39:42
【问题描述】:

我有一个应用程序成功地使用 Stripe 向用户收取访问应用程序的费用。在此基础上,我想在我的结账过程中实施 Plaid。由于这是我第一次实现 Stripe,而现在是我第一次使用 Plaid,我对方向以及如何推动这个特性有点迷茫。

我安装了plaid-ruby gem,并通过 figaro 添加了我的 Plaid secret_key 和 client_id,但现在我迷路了。

Plaid.rb:

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

格子链接:

       <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>

这是我的 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. 

我需要在我的控制器或其他地方添加什么才能通过 Plaid 和 Stripe 创建充电?

【问题讨论】:

    标签: ruby-on-rails stripe-payments plaid


    【解决方案1】:

    Plaid 有一个 writeup 说明如何连接它 - 尽管提供的示例是在 Node.js 中 - 而 Stripe 也有一个 guide

    也就是说,您需要在onSuccess 处理程序中添加代码,以将public_tokenmetadata.account_id 发送到您服务器的'token exchange' endpoint,一旦您获得了这些代码,您就可以将它们交换为@987654324 @,最后,您需要将该令牌附加到客户。

    所以,是这样的:

    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
    })
    

    然后你可以做你的Stripe::Charge.create()

    【讨论】:

    • 我在控制台中看到了 public_token 和 account_id。我如何将此信息发送到 plaid-ruby gem('token exchange' 端点)?我是通过 plaid_user = Plaid... 执行此操作还是在我的控制器中执行此操作?
    • 我可以通过将 curl 传递到控制器然后传递 customer = .. 来实现此功能,就像您在上面所说的那样。谢谢!
    • 太棒了。很高兴听见。 :)
    • 我返回的是 no such token 错误,任何人都可能知道这是从哪里来的吗?
    • 检查以确保公共和秘密 API 密钥都来自同一帐户和同一环境。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    • 2014-04-21
    • 2021-03-17
    • 1970-01-01
    相关资源
    最近更新 更多