Stripe error: "The card object must have a value for 'number'" when creating a Customer

ruby-on-rails, stripe-payments

Solution

The value you should be setting `card:` to is just the id of the token and not the entire object you are passing right now. Something like this (my ruby is a bit rusty):

card: params[:stripeToken][:id]

You can see an example of valid inputs to `Customer.create` in the Stripe API Docs.

Problem

I am using Stripe's ruby gem to (try to) perform two steps: - Collect a card using Stripe's "Checkout" form - Create a Customer using the token provided by the redirect from the form submission The latter of these steps raises a `Stripe::CardError` whose message is: The card object must have a value for 'number' The API doc describes the process: https://stripe.com/docs/tutorials/subscriptions#subscribing-a-customer-to-a-plan My code (a Rails controller action) ``` def receive_redirect customer = Stripe::Customer.create( plan: "stripe_plan_name", card: params[:stripeToken] ) end ``` params[:stripeToken] looks like this: {"id"=>"tok_1044TY4GgNdNSosPXdAmIZdt", "livemode"=>"false", "created"=>"1400620581", "used"=>"false", "object"=>"token", "type"=>"card", "card"=>{"id"=>"card_1044TY4GgNdNSosPuDSuygow", "object"=>"card", "last4"=>"9424", "type"=>"Discover", "exp_month"=>"9", "exp_year"=>"2014", "fingerprint"=>"Lz5ASwlmyseG0gYo", "customer"=>"", "country"=>"US", "name"=>"manderson@pinneyinsurance.com", "address_line1"=>"", "address_line2"=>"", "address_city"=>"", "address_state"=>"", "address_zip"=>"", "address_country"=>""}, "email"=>"<my_email>@<my_host>"} ...As you can see, they don't give me a number, so what am I to do? Stack stripe 1.8.8 (ruby gem) Rails 3.2.13 Ruby 1.9.3

Original source