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

Stripe Request failed: payment required(402)

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

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(使用条纹 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 错误,我不确定为什么。任何帮助都会很棒。谢谢!

您可以在 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"
})