no such source when creating a subscription to a paid plan

Showing 1-3 of 3 messages
no such source when creating a subscription to a paid plan Raphael B 11/28/16 12:46 PM
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?

Re: [stripe-api-discuss] no such source when creating a subscription to a paid plan Remi J. 11/28/16 12:49 PM
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...@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/.

Re: [stripe-api-discuss] no such source when creating a subscription to a paid plan Raphael B 11/29/16 12:42 PM
Yup, that did it. Thanks!