no such source when creating a subscription to a paid plan

2,267 views
Skip to first unread message

Raphael B

unread,
Nov 28, 2016, 3:46:03 PM11/28/16
to Stripe API Discussion
I am using stripe gem v 1.57.0, Ruby 2.3.0, Stripe API version 2016-07-06 on Ubuntu 16. I have a paid-plan called "small" and I run the following in stripe-console:

Stripe.api_key = 'sk_test_<rest of my test publishable key>'

st
= Stripe::Token.create(card: {number:"4242424242424242",exp_month:11, exp_year:2017, cvc:123})

Stripe::Customer.create(plan:"small", email:"u...@example.com", default_source:st.id)


and i get:

Stripe::InvalidRequestError: (Status 400) (Request req_9eDifdeAcouHxI) No such source: tok_19KvD....

I thought I understood how things were supposed to work: you get a token for the card and pass that token and a plan name when creating a customer with a subscription.

What am I missing?

Remi J.

unread,
Nov 28, 2016, 3:49:21 PM11/28/16
to api-d...@lists.stripe.com
Hey Raphael,

The issue here is that you're not using the proper parameter. You're trying to create a customer with a source so the token id (tok_XXX) needs to be passed in the `source` parameter and not in the `default_source` parameter. The latter is used to set a specific source as the new default instead once it's already been saved on the customer. For example if that customer has 3 cards and you want to change the default to a new one, you'd use the Update Customer API [1] and pass that card's id (card_XXXX) in `default_source`.

Your code should be:

Stripe::Customer.create(plan:"small", email:"u...@example.com", source: st.id)

Hope this helps!
Remi


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

Raphael B

unread,
Nov 29, 2016, 3:42:06 PM11/29/16
to Stripe API Discussion
Yup, that did it. Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
Reply all
Reply to author
Forward
0 new messages