Stripe:你为'card'传递了一个空字符串。 (在开发中工作)

时间:2014-01-06 20:04:08

标签: ruby-on-rails ruby web-deployment stripe-payments

所以我设置了一个rails应用程序,它在注册时通过条带保存“客户”信用卡信息,以便该卡可以用于将来的购买。代码在我的本地计算机上运行时没有任何缺陷,但不会在我的VPS上运行。我得到的错误就是这个 -

Processing by RegistrationsController#create as HTML


Parameters: {"utf8"=>"✓", "authenticity_token"=>"iwnBhyGlReHmXhlq5QDTgrw9fdXpZnXsX+IoDEp9ufk=", "user"=>{"email"=>"jim@gmail.com", "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)

正如你所看到的,它说"stripe_card_token"=>""然而,当我这样做是在本地机器上进行开发时,我获得了成功 -

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"=>"abs@gmail.com", "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" = 'abs@gmail.com' LIMIT 1
   (0.1ms)  BEGIN
  CACHE (0.0ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'abs@gmail.com' 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", "abs@gmail.com"], ["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/

代码完全一样......还有其他人有这个问题吗?问题是什么?

2 个答案:

答案 0 :(得分:1)

所以我运行了一个名为paymentProcess.js的外部JS脚本,看起来像这样 -

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);
    }
  }
};

我仍然不确定为什么Capistrano在部署期间基本上忽略了这个文件,但是当我将这个JS代码移到我的login.html.erb布局文件的头部时(在两个<script>标签之间),一切都很好。不一定是一个可靠的答案,但对于遇到同样问题的其他人来说,这是一个可靠的解决方案。

答案 1 :(得分:0)

如果它对其他人有帮助,我在嵌入式Stripe JavaScript中将“v2”更改为“v1”,这个问题就消失了。