[英]“No such customer” when charging with Stripe
I was testing around with Stripe API and I couldn't get this basic 'marketplace' scenario to work. 我正在使用Stripe API进行测试,但无法使用这种基本的“市场”方案。 The scenario is a buyer buys from a seller, and the application has a fee.
该方案是买方从卖方购买,并且该应用程序需要付费。
My setup: 我的设置:
# Seller has already connected their account to the application
# through "Stripe Connect Standalone". Below will attempt to charge a customer.
import stripe
# application's sk from stripe
stripe.api_key = "sk...."
# Build customer
customer = stripe.Customer.create(
email = customer.email,
card = token_from_stripe_checkout
)
# Now do a charge
charge = stripe.Charge.create(
amount = 2000,
currency = "usd",
customer = customer.id,
application_fee = 500,
stripe_account = seller.stripe_user_id # which is something like: acct_xxxxxxxxx
)
This results in an error: 这会导致错误:
File "/home/btw/app.py", line 177, in stripe_test
stripe_account=seller.stripe_user_id
File "/usr/local/lib/python2.7/dist-packages/stripe/resource.py", line 357, in create
response, api_key = requestor.request('post', url, params, headers)
File "/usr/local/lib/python2.7/dist-packages/stripe/api_requestor.py", line 141, in request
resp = self.interpret_response(rbody, rcode, rheaders)
File "/usr/local/lib/python2.7/dist-packages/stripe/api_requestor.py", line 269, in interpret_response
self.handle_api_error(rbody, rcode, resp, rheaders)
File "/usr/local/lib/python2.7/dist-packages/stripe/api_requestor.py", line 156, in handle_api_error
rbody, rcode, resp, rheaders)
InvalidRequestError: Request req_xxxxxxx: No such customer: cus_xxxxxxxxx
What am I doing wrong? 我究竟做错了什么?
There are two main things happening in your code: 您的代码中发生了两件事:
The issue is that you're creating the customer in your own account but you're creating the charge under the scope of the connected account. 问题是您要在自己的帐户中创建客户,但要在关联帐户的范围内创建费用。 When you pass
stripe_account
you're essentially telling Stripe to run the API call under the other, connected account. 当您传递
stripe_account
时,您stripe_account
是在告诉Stripe在另一个连接的帐户下运行API调用。 Your connected account doesn't have access to your base account's customers. 您的关联帐户无权访问基本帐户的客户。
The simple fix would be to also pass stripe_account
to your create customer API call. 简单的解决方法是将
stripe_account
传递给您的创建客户API调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.