0

I was testing around with Stripe API and I couldn't get this basic 'marketplace' scenario to work. 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?

rublex
  • 1,893
  • 5
  • 27
  • 45
  • Are you sure this is where the error is occurring? That seems implausible. Do you have additional code relevant to Stripe? – elixenide Aug 22 '15 at 16:59
  • @EdCottrell I think so. I don't have any other Stripe code. The stacktrace line is on `stripe_account = seller.stripe_user_id`. – rublex Aug 22 '15 at 17:04

1 Answers1

5

There are two main things happening in your code:

  1. You create a customer.
  2. You then charge that customer.

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. 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.

demongolem
  • 9,474
  • 36
  • 90
  • 105
Matthew Arkin
  • 4,460
  • 2
  • 27
  • 28
  • 1
    I believe this comment is incorrect (or perhaps Stripe changed the requirements to make a [Connect](https://stripe.com/docs/connect) charge). I was just able to make a charge using a `Customer` that was created *before* the "master" account had *any* connected accounts at all (using the Ruby library, in the test environment). However, it required that I first [generate a new "token"](https://stripe.com/docs/connect/shared-customers#making-tokens) as an intermediary step (which isn't required when charging a customer against the "master" account). Before, I was also getting “No such customer”. – Chris W. May 19 '17 at 16:28