条纹请求失败:需要付款(402)

时间:2017-01-17 13:11:52

标签: ruby sinatra stripe-payments

我在测试服务器时遇到上述错误,我不明白为什么。我之前成功创建了一个托管帐户,当时我想添加一个外部帐户:

post '/account/external_account' do
  begin
    account = Stripe::Account.retrieve(params[:stripe_account])
    account.external_accounts.create(
      :object => "bank_account",
      :country => "US",
      :currency => "usd",
      :routing_number => "110000000",
      :account_number => "000123456789"
    )
  rescue Stripe::StripeError => e
    status 402
    return "Error adding external account to customer account: #{e.message}"
  end
  status 200
  return account.to_json
end 

条带帐户ID是管理帐户的ID,例如acct_19clyeKuASmJkC0m。

我在尝试保存上传的验证ID时遇到同样的错误(使用stripes success.png图片)。使用以下代码上传时:

post '/account/id' do
  begin
    path = File.dirname(__FILE__)
    image = Image.new(file: params[:file])
    image.save
    file = Stripe::FileUpload.create(
      {
        :purpose => params[:purpose],
        :file => File.new("#{path}#{image.file.url}")
      },
      {
        :stripe_account => params[:stripe_account]
      }
    )
  rescue Stripe::StripeError => e
    status 402
    return "Error saving verification id to account: #{e.message}"
  end
  status 200
  return file.to_json
end 

我收到了一个文件ID,但是当我尝试使用以下代码使用相同的帐户ID保存它时:

post '/account/id' do
  account = Stripe::Account.retrieve(params[:stripe_account])
  account.legal_entity.verification.document = params[:file_id]
  account.save
  return account.to_json
end

我得到了相同的402错误,我不知道为什么。任何帮助都会很棒。谢谢!

1 个答案:

答案 0 :(得分:2)

您可以在API参考中找到添加外部帐户的正确语法:https://stripe.com/docs/api/ruby#account_create_bank_account

基本上,您缺少external_account参数名称。这是正确的语法:

account.external_accounts.create(:external_account => {
  :object => "bank_account",
  :country => "US",
  :currency => "usd",
  :routing_number => "110000000",
  :account_number => "000123456789"
})