没有这样的客户:cus_************ (Stripe::InvalidRequestError) 当客户存在时

No such customer: cus_************ (Stripe::InvalidRequestError) when customer exists

我在一个名为 foodsy 的电子商务市场工作。为此,我正在使用 stripe connect。关联帐户是使用 stripe-connect-omniauth 创建的。 Foodsy 有几个客户。 Sku 的订单由

在 rails 控制器中创建
 Stripe.api_key = "sk_test_************"
    Stripe::Order.create(
      {:currency => 'usd',
      :items => [
        {
          :type => 'sku',
          :parent => "sku_************"
        }
      ] },
    {  :stripe_account => "acct_************" }
    )

它创建一个 ID 为 or_************ 的订单。

存在于美食平台的顾客购买,

order=Stripe::Order.retrieve("or_************",stripe_account: "acct_************")
order.pay(customer: "cus_************")

但是这段代码returns出错No such customer: cus_************ (Stripe::InvalidRequestError).

客户存在,因为我可以在仪表板上看到他,源属性设置在条带上。那为什么会出错?

问题是客户存在于平台的帐户中,但不在您尝试创建费用的关联帐户中。

您需要share the customer从平台账号到关联账号:

# Create a token from the customer on the platform account
token = Stripe::Token.create(
  {:customer => "cus_7QLGXg0dkUYWmK"},
  {:stripe_account => "acct_17BTxDCioT3wKMvR"}
)

# Retrieve the order on the connected account and pay it using the token
order = Stripe::Order.retrieve("or_17BUNHCioT3wKMvREWdDBagG",
  stripe_account: "acct_17BTxDCioT3wKMvR"
)
order.pay(source: token.id)

如果您使用了错误的 APiKey,也会发生这种情况