2017-05-19 45 views
2

如果试图通过 a connected account收取客户记录(其具有关联的信用卡),我得到一个错误声明,“没有这样的客户:cus_xxxx“ - 即使向同一客户收取费用,当不是使用”已连接“帐户(通过平台帐户进行收费)时,也能正常工作。Stripe连接:针对“已连接”(独立)帐户对现有客户进行充电

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

# Use the (secret) API key for the "platform" or base account. 
Stripe.api_key = 'sk_[...]' 

customer = Stripe::Customer.create(email: '[email protected]') 

# Associate a credit-card with the customer. 
token = # Generate a token (e.g., 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::InvalidRequestError例外,随着“没有这样的客户“上面提到的错误。然而,相同的电荷将通过罚款,如果我们只是尝试在“平台”账户(不stripe_account参数和无application_fee)运行它...

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

回答

2

对于一些(混乱,稍有奇怪的)理由,当对“共享客户”(将通过一个或多个关联账户收取的客户)收费时,您必须添加中间步骤creating a new token。因此,假设我们已经创建了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') 

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