【问题标题】:Stripe Connect: Charging an existing customer against a "connected" (Standalone) accountStripe Connect:根据“已连接”(独立)帐户向现有客户收费
【发布时间】:2017-05-20 01:58:40
【问题描述】:

如果尝试通过connected account 向客户记录(具有关联的信用卡) 收取费用,我会收到错误消息,声称“没有这样的客户:cus_xxxx”——即使当使用“连接”帐户(通过平台帐户收费时)时,向同一客户收费将正常工作。

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

# 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, currency: 'usd', customer: customer.id }

【问题讨论】:

    标签: ruby stripe-payments stripe-connect


    【解决方案1】:

    由于某些(令人困惑和有点奇怪)的原因,您必须在对“共享客户”(将通过一个或多个关联账户收费的客户)收费时添加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')
    

    顺便说一句,我认为 Stripe 的错误消息(“没有这样的客户”)是一个错误,而且这个额外的步骤(生成令牌)仅对“Stripe Connect”收费是一个令人困惑的怪癖。

    【讨论】:

    • 注:如果您在创建新令牌后仍然收到“没有这样的客户”错误,请仔细检查您在创建费用时是否仍然传入 customer 参数.
    猜你喜欢
    • 1970-01-01
    • 2015-03-13
    • 2023-03-18
    • 2018-12-14
    • 2014-10-31
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 2020-12-13
    相关资源
    最近更新 更多