frenchloaf
frenchloaf

Reputation: 1054

Stripe: You passed an empty string for 'card'. (works in development)

So I have a rails app set up that is saving a "customer's" credit card information through stripe when they sign up, so that the card can be used for future purchases. The code runs with no flaws in development on my local machine, but won't run in production on my VPS. The error I'm getting is this --

Processing by RegistrationsController#create as HTML


Parameters: {"utf8"=>"✓", "authenticity_token"=>"iwnBhyGlReHmXhlq5QDTgrw9fdXpZnXsX+IoDEp9ufk=", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "meatless"=>"0", "comments"=>"ass", "stripe_card_token"=>""}, "commit"=>"SIGN UP"}
Stripe error while creating customer: You passed an empty string for 'card'. We assume empty values are an attempt to unset a parameter; however 'card' cannot be unset. You should remove 'card' from your request or supply a non-empty value
  Rendered devise/registrations/new.html.erb within layouts/login (20.4ms)

as you can see, it says "stripe_card_token"=>""however, when I do this is development on my local machine, I get success --

Started POST "/users" for 127.0.0.1 at 2014-01-06 14:39:40 -0500
Processing by RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"a/NyynWF3loWMYB3KVR0q24mLZHj/KnKJ4/dpOJFTmY=", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "meatless"=>"0", "comments"=>"abs", "stripe_card_token"=>"tok_103GFj2iAIGqhTah4jL5Q3pV"}}
  User Exists (0.7ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
   (0.1ms)  BEGIN
  CACHE (0.0ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
  SQL (0.6ms)  INSERT INTO "users" ("comments", "created_at", "current_sign_in_at", "current_sign_in_ip", "customer_id", "email", "encrypted_password", "last_4_digits", "last_sign_in_at", "last_sign_in_ip", "meatless", "remember_created_at", "reset_password_sent_at", "reset_password_token", "roles_mask", "sign_in_count", "stripe_customer_token", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) RETURNING "id"  [["comments", "abs"], ["created_at", Mon, 06 Jan 2014 19:39:42 UTC +00:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["customer_id", nil], ["email", "[email protected]"], ["encrypted_password", "$2a$10$.NeUFnXgX95FmWJeW4f6ceagVvPgQA.pOINfbqqx1llgxrgTNETim"], ["last_4_digits", "4242"], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["meatless", false], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["roles_mask", nil], ["sign_in_count", 0], ["stripe_customer_token", "cus_3GFj0ZnzTa5Y89"], ["updated_at", Mon, 06 Jan 2014 19:39:42 UTC +00:00]]
   (1.8ms)  COMMIT
   (0.1ms)  BEGIN
   (0.3ms)  UPDATE "users" SET "last_sign_in_at" = '2014-01-06 19:39:42.683904', "current_sign_in_at" = '2014-01-06 19:39:42.683904', "last_sign_in_ip" = '127.0.0.1', "current_sign_in_ip" = '127.0.0.1', "sign_in_count" = 1, "updated_at" = '2014-01-06 19:39:42.684537' WHERE "users"."id" = 9
   (0.4ms)  COMMIT
Redirected to http://localhost:3000/

The code is identical... has anyone else had this issue?? What could the problem be?

Upvotes: 1

Views: 2105

Answers (2)

Marina Martin
Marina Martin

Reputation: 192

If it helps someone else, I changed "v2" to "v1" in the embedded Stripe JavaScript and this problem went away.

Upvotes: 0

frenchloaf
frenchloaf

Reputation: 1054

So I was running an external JS script called paymentProcess.js, which looked like this --

var user;

jQuery(function() {
  Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'));
  return user.setupForm();
});

user = {
  setupForm: function() {
    return $('.card_form').submit(function() {
      $('input[type=submit]').attr('disabled', true);
      if ($('#card_number').length) {
        user.processCard();
        return false;
      } else {
        return true;
      }
    });
  },
  processCard: function() {
    var card;
    card = {
      number: $('#card_number').val(),
      cvc: $('#card_code').val(),
      expMonth: $('#card_month').val(),
      expYear: $('#card_year').val()
    };
    return Stripe.createToken(card, user.handleStripeResponse);
  },
  handleStripeResponse: function(status, response) {
    if (status === 200) {
      $('#user_stripe_card_token').val(response.id);
      return $('.card_form')[0].submit();
    } else {
      $('#stripe_error').text(response.error.message);
      return $('input[type=submit]').attr('disabled', false);
    }
  }
};

I am still unsure as to why Capistrano was basically ignoring this file during deployment, but when I moved this JS code into the head of my login.html.erb layout file (in between two <script> tags), everything worked great. Not necessarily a solid answer, but a solid work around for anyone else experiencing the same problem.

Upvotes: 1

Related Questions