"No such customer" 使用 Stripe 充电时
"No such customer" when charging with Stripe
我正在使用 Stripe API 进行测试,但我无法让这个基本的 'marketplace' 场景发挥作用。场景是买家向卖家购买,申请有手续费。
我的设置:
# 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
)
这会导致错误:
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
我做错了什么?
您的代码中发生了两件主要事情:
- 您创建了一个客户。
- 然后您向该客户收费。
问题是您在自己的帐户中创建客户,但在关联帐户的范围内创建费用。当您传递 stripe_account
时,您实际上是在告诉 Stripe 运行 在另一个关联帐户下调用 API。您的连接帐户无权访问基本帐户的客户。
简单的解决方法是将 stripe_account
也传递给您的创建客户 API 调用。
我正在使用 Stripe API 进行测试,但我无法让这个基本的 'marketplace' 场景发挥作用。场景是买家向卖家购买,申请有手续费。
我的设置:
# 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
)
这会导致错误:
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
我做错了什么?
您的代码中发生了两件主要事情:
- 您创建了一个客户。
- 然后您向该客户收费。
问题是您在自己的帐户中创建客户,但在关联帐户的范围内创建费用。当您传递 stripe_account
时,您实际上是在告诉 Stripe 运行 在另一个关联帐户下调用 API。您的连接帐户无权访问基本帐户的客户。
简单的解决方法是将 stripe_account
也传递给您的创建客户 API 调用。