【发布时间】:2020-02-10 21:27:33
【问题描述】:
我想使用 Stripe ACH 付款。
我使用 gem plaid。
这是我的链接代码:
var linkHandler = Plaid.create({
clientName: 'Some Name',
env: 'sandbox',
key: ENV['key'],
product: ['auth'],
onSuccess: function(public_token, metadata) {
$.post('/plaid/set_auth', {
public_token: public_token,
account: metadata.account_id
});
console.log('Public Token: ' + public_token);
console.log('Selected account ID: ' + metadata.account_id);
}
});
格子控制器:
def set_auth
public_token = params['public_token']
account_id = params['account']
client = Plaid::Client.new(env: :sandbox,
client_id: ENV['client_id'],
secret: ENV['secret'],
public_key: ENV['public_key'])
exchange_token_response = client.item.public_token.exchange(public_token)
access_token = exchange_token_response.access_token
#Create a Stripe bank_account_token
stripe_response = client.processor.stripe.bank_account_token.create(access_token, account_id)
bank_account_token = stripe_response.stripe_bank_account_token
customer = Stripe::Customer.retrieve("<customer-id>")
customer.sources.create({
:source => bank_account_token
})
#...Stripe::Charge.create()...
end
问题是metadata.account_id参数没有传递给控制器。
浏览器控制台:Selected account ID: null
如果我这样做puts client.accounts.get(access_token),我会得到几个余额不同的帐户。
【问题讨论】:
-
您是否尝试在控制台中打印 public_token 和元数据?检查值。
-
public_token工作正常。 -
public_token 中有什么?元数据可以在 public_token 中吗?
-
public_token = public-sandbox-ce9c11...和metadata = {"institution"=>{"name"=>"Chase", "institution_id"=>"ins_3"}, "account"=>{"id"=>"", "name"=>"", "type"=>"", "subtype"=>"", "mask"=>""}, "account_id"=>"", "accounts"=>{"0"=>{"id"=>"PG7xK5xVJ5tqe...", "name"=>"Plaid Checking", "mask"=>"0000", "type"=>"depository", "subtype"=>"checking"},.. -
@demir 非常感谢!我重新阅读了文档,但没有找到。包括帐户选择,现在我有了 ID。
标签: ruby-on-rails ruby stripe-payments plaid