ruby – Stripe Connect:针对“已连接”(独立)帐户向现有客户收
发布时间:2020-12-17 02:49:46 所属栏目:百科 来源:网络整理
导读:如果试图通过 connected account向客户记录(具有相关信用卡)收费,我收到错误声称“没有这样的客户:cus_xxxx” – 即使对同一个客户收取费用也能正常工作不使用“已连接”帐户(通过平台帐户充值时). 例如,假设我们有一个ID为acct_ABC123的“已连接”(独立)帐
如果试图通过
connected account向客户记录(具有相关信用卡)收费,我收到错误声称“没有这样的客户: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 (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,customer: customer.id } 解决方法
对于某些(令人困惑且有点奇怪)的原因,您必须在对“共享客户”(将通过一个或多个关联帐户收费的客户)收费时添加
creating a new token的中间步骤.因此,假设我们已经使用相关的信用卡创建了客户(根据问题),工作代码最终看起来像这样……
token = Stripe::Token.create({ customer: customer.id },{ stripe_account: 'acct_ABC123' }) Stripe::Charge.create({ amount: 150,source: token.id,stripe_account: 'acct_ABC123') 顺便说一句,我会认为Stripe的错误消息(“没有这样的客户”)是一个错误,并且这个额外的步骤(生成令牌)只需要“条纹连接”收费令人困惑的怪癖. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |