Customer exists but getting (Stripe InvalidRequest Error::No such customer)

10,390 views
Skip to first unread message

Bruce

unread,
Mar 31, 2014, 4:02:09 PM3/31/14
to api-d...@lists.stripe.com
So my application is simply trying let a connected user accept a one-time credit card payment from a client with a saved credit card...Here is my high level understanding of how to do this:

More concretely, if your, the application owner's, account is A, and 
the connected account is B: 
- Create customer X on A's account using A's publishable key and secret key. 
- Create a *token* on B's account using the access_token and customer X's token. 
- With that token, create a once-off charge or customer Y on B's 
account using the access_token. 
- If you'd like to subscribe customer Y to a subscription, you can do 
so with B's access_token. 

The error I'm getting in test mode:
Stripe::InvalidRequestError No such customer: cus_3something

Now, cus_3something exists on the application's (A's) account because I can see it in the customer dashboard.  When I start to create a token on B's account, here is the ruby code that throws the error:

token = Stripe::Token.create(
 
{
:customer => CUSTOMER_ID, :card => CARD_ID},
 
ACCESS_TOKEN # user's access token from the Stripe Connect flow
)

charge
= Stripe::Charge.create({
       
:amount => amount, # amount in cents, again
       
:currency => "usd",
       
:customer => CUSTOMER_ID
       
:card => CARD_ID,
       
:description => params[:email]},
        ACCESS_TOKEN
     
)

#where CARD_ID = the card id of the customer created on A's account, CUSTOMER_ID = the id of the customer created on A's account, ACCESS_TOKEN = access_token of the connected user B received after a POST request to the access_token_url endpoint.
 

I have Stripe.api_key = Rails.configuration.stripe[:secret_key], which means it is set to the application account's (A) secret key.   What could be the problem?

Amber Feng

unread,
Mar 31, 2014, 7:12:50 PM3/31/14
to api-d...@lists.stripe.com
Hey Bruce,

Hm, that should work. Are you sure B's account is connected to A's application?

If you want to privately email me the email address for the A/B
accounts (as well as the customer ID you're failing to access), I can
take a look.

Amber
> --
> You received this message because you are subscribed to the Google Groups
> "Stripe API Discussion" group.
> To post to this group, send email to api-d...@lists.stripe.com.
> Visit this group at
> http://groups.google.com/a/lists.stripe.com/group/api-discuss/.
>
> To unsubscribe from this group and stop receiving emails from it, send an
> email to api-discuss...@lists.stripe.com.

Bruce

unread,
Mar 31, 2014, 8:43:51 PM3/31/14
to api-d...@lists.stripe.com
Hi Amber,

Yes, I believe so.  My one connected user in the dashboard has an account # "acct_XXXetc" which matches the connected user's account # stored in my database; this connected user stored in my DB also has the ACCESS_TOKEN as defined above.  The email should arrive in a few minutes.  Thank you for your help.

Vladimir Andrijevik

unread,
Apr 1, 2014, 7:09:54 AM4/1/14
to api-d...@lists.stripe.com
Hi Bruce,

The code you are using to create a charge:

charge = Stripe::Charge.create({
:amount => amount, # amount in cents, again
:currency => "usd",
:customer => CUSTOMER_ID
:card => CARD_ID,
:description => params[:email]
}, ACCESS_TOKEN)

should not be using the CUSTOMER_ID and CARD_ID from account A. You can only
use CUSTOMER_ID and CARD_ID to create a Token in the connected account
B, but you cannot use CUSTOMER_ID and CARD_ID directly in account B (since
that customer only exists in account A).

If you want to make a copy of the Customer in account B, you should
create a Customer in account B from the token you created (which copies over
details from the shared customer):

customerInAccountB = Stripe::Customer.create({
card: token.id
}, ACCESS_KEY)

and then charge that customer:

Stripe::Charge.create({
:amount => amount, # amount in cents, again
:currency => "usd",
:customer => customerInAccountB.id,
:description => params[:email]
}, ACCESS_KEY)

Otherwise, if you just want to do a one-off Charge without
saving a copy of the shared Customer, use the token directly:

Stripe::Charge.create({
:amount => amount, # amount in cents, again
:currency => "usd",
:card => token.id,
:description => params[:email]
}, ACCESS_KEY)

Hope this helps clear things up!

Cheers,
Vlad

Bruce

unread,
Apr 1, 2014, 8:35:55 PM4/1/14
to api-d...@lists.stripe.com
Thanks Vlad and Amber, that worked!
Reply all
Reply to author
Forward
0 new messages