当客户存在时,出现“无此客户:cus_************(Stripe :: InvalidRequestError)”的错误。

13

我正在从事一个名为foodsy的电子商务市场的工作。我使用stripe connect来实现这一目的。使用stripe-connect-omniauth创建连接帐户。而且,foodsy有多个客户。在Rails控制器中通过创建Sku订单。

 Stripe.api_key = "sk_test_************"
    Stripe::Order.create(
      {:currency => 'usd',
      :items => [
        {
          :type => 'sku',
          :parent => "sku_************"
        }
      ] },
    {  :stripe_account => "acct_************" }
    )

它创建了一个带有id or_************的订单。

在foodsy平台上存在的客户购买它,

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

但这段代码返回一个错误 No such customer: cus_************ (Stripe::InvalidRequestError).

我在仪表板上看到客户存在,并且 stripe 上的 source 属性已设置。那么为什么会出错?


1
对于任何搜索错误信息的人:请确保使用正确的API密钥和密钥。 - totymedli
2个回答

29

问题在于客户存在于平台账户上,但不存在于您试图创建费用的已连接账户上。

您需要将客户从平台帐户分享到已连接的帐户中:

# 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)

好的,问题解决了。文档有点乱。看起来他们已经记录了它...但我在stripe-connect文档中找不到链接,但在stripe-api文档中可以找到。[https://stripe.com/docs/connect/shared-customers] - raj

8
这也可能发生在您使用错误的 API 密钥时。

你真是个救命稻草啊! - Hadayat Niazi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接