条带连接:针对“已连接”(独立)帐户为现有客户收费

如果试图通过 连接帐户向客户记录(具有相关信用卡)收费,我收到错误声称“没有这样的客户:cus_xxxx” – 即使向同一个客户收取费用也能正常工作使用“已连接”帐户时(通过平台帐户充值时)。

例如,假设我们有一个ID为acct_ABC123的“已连接”(独立)帐户,请考虑以下Ruby代码:

 # Use the (secret) API key for the "platform" or base account. Stripe.api_key = 'sk_[...]' customer = Stripe::Customer.create(email: 'customer@example.com') # Associate a credit-card with the customer. token = # Generate a token (eg, using Stripe Checkout). customer.sources.create(source: token) # Attempt to charge the card via the connected account... Stripe::Charge.create({ amount: 150, currency: 'usd', customer: customer.id, application_fee: 25 }, stripe_account: 'acct_ABC123') 

最后一行导致Stripe::InvalidRequestErrorexception,上面提到“没有这样的客户”错误。 但是,如果我们只是尝试在“平台”帐户上运行它(没有stripe_account参数且没有application_fee ),相同的费用将会很好…

 Stripe::Charge.create({ amount: 150, currency: 'usd', customer: customer.id } 

对于某些(令人困惑且有点奇怪)的原因,您必须在对“共享客户”(将通过一个或多个关联帐户收费的客户)收费时添加创建新令牌的中间步骤。 因此,假设我们已经使用相关的信用卡创建了customer (根据问题),工作代码最终看起来像这样……

 token = Stripe::Token.create({ customer: customer.id }, { stripe_account: 'acct_ABC123' }) Stripe::Charge.create({ amount: 150, currency: 'usd', source: token.id, application_fee: 25 }, stripe_account: 'acct_ABC123') 

顺便说一句,我会认为Stripe的错误消息(“没有这样的客户”)是一个错误,并且这个额外的步骤(生成令牌)只需要“条纹连接”收取令人困惑的怪癖。