2015-08-22 63 views
0

我正在使用Stripe API進行測試,我無法獲得這個基本的「市場」場景。該場景是買方從賣方購買,並且該應用程序有收費。使用條紋充電時「沒有這樣的客戶」

我的設置:

# 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 

我在做什麼錯?

+0

你確定這是錯誤發生的地方嗎?這似乎不合理。你有額外的代碼與條紋相關嗎? –

+0

@EdCottrell我這麼認爲。我沒有任何其他條紋代碼。 stacktrace行在'stripe_account = seller.stripe_user_id'上。 – rublex

回答

4

有在你的代碼發生兩兩件事:

  1. 您創建一個客戶。
  2. 然後您向該客戶收費。

問題在於,您是在自己的帳戶中創建客戶,但是您在關聯帳戶的範圍內創建了該客戶。當您通過stripe_account時,您基本上會告訴Stripe在另一個關聯的帳戶下運行API調用。您的關聯帳戶無權訪問您的基本帳戶的客戶。

簡單的修復方法是將stripe_account也傳遞給您創建的客戶API調用。

+1

我相信這個評論是不正確的(或者可能是Stripe改變了對[Connect](https://stripe.com/docs/connect)充電的要求)。在「主」賬戶擁有*任何*關聯賬戶之前(在測試環境中使用Ruby庫),我只能使用「客戶」進行收費。然而,它要求我首先[產生一個新的「令牌」](https://stripe.com/docs/connect/shared-customers#making-tokens)作爲中間步驟(當向客戶收費時不需要反對「主」賬戶)。之前,我還得到了「沒有這樣的客戶」。 –