【问题标题】:Stripe card not storing, but customer is条纹卡不存储,但客户是
【发布时间】:2014-04-25 05:05:26
【问题描述】:

我可以将新客户保存到我的网络应用程序中,但我无法为该客户提供信用卡。我相信我正确地遵循了 stripe.com 的说明,但我似乎无法弄清楚。我正在使用 ruby​​/rails 和 haml

我的代码在下面

payment.html.haml:

= form_tag("", method: "POST", id: "payment-form") do
    %span.payment-errors
    .field
        = label_tag :card_number, "Credit Card Number", class: "labelTag"
        = text_field_tag :card_number, nil, {:class => "ss-form-control", :name => nil, "data-stripe" => "number"}
    .field
        = label_tag :card_code, "Security Code on Card (CVC)", class: "labelTag"
        = text_field_tag :card_code, nil, {:class => "ss-form-control minilabel", :name => nil, "data-stripe" => "cvc"}
    .field
        = label_tag :card_month, "Card Expiration", class: "labelTag"
        = select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", class: 'minilabel', "data-stripe" => 'exp-month'}
        = select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year", "data-stripe" => 'exp-year'}
    %button.standardButton.btn.btn-sumbit{type: "submit"} Submit Payment

application.js

Stripe.setPublishableKey('mykey');
$('#payment-form').submit(function(event) {
    var $form = $(this);
    alert('first')
    // Disable the submit button to prevent repeated clicks
    $form.find('button').prop('disabled', true);

    Stripe.card.createToken($form, stripeResponseHandler);

    // Prevent the form from submitting with the default action
    return false;
});
var stripeResponseHandler = function(status, response) {
  var $form = $('#payment-form');

  if (response.error) {
    // Show the errors on the form
    $form.find('.payment-errors').text(response.error.message);
    $form.find('button').prop('disabled', false);
  } else {
    alert('second');
    // token contains id, last4, and card type
    var token = response.id;
    // Insert the token into the form so it gets submitted to the server
    $form.append($('<input type="hidden" name="stripeToken" />').val(token));
    // and submit
    $form.get(0).submit();
  }
};  

user_controller.rb

# Get the credit card details submitted by the form
token = params[:stripeToken]

# Create a Customer
customer = Stripe::Customer.create(
      :card => token,
      :description => current_user.email
)

【问题讨论】:

  • 能否请您发布正在提交的参数?这将有助于查看令牌是否甚至通过表单提交。
  • @MartinLang 这是我所有的代码。我是 ruby​​/rails 新手,那么如何传递参数?
  • 不用担心 - 在这里为您提供帮助。 - 当您提交表单时,您的终端应显示您在请求中提交的参数。参数或多或少是请求的“主体”。在您的代码中,您正在调用 token = params[:stripeToken],这意味着您正在尝试从 params 中获取 stripeToken。

标签: ruby-on-rails ruby haml payment-gateway stripe-payments


【解决方案1】:

如果没有看到 Rails 在 post 表单上登录,很难说出这里的错误,但我想这是因为你没有在 form_tag 中指定路径。即

= form_tag("", method: "POST", id: "payment-form") 

而不是

= form_tag("/some_path", method: "POST", id: "payment-form")

= form_tag(some_path, method: "POST", id: "payment-form")

【讨论】:

    猜你喜欢
    • 2015-10-03
    • 2019-05-15
    • 1970-01-01
    • 2015-11-10
    • 2017-12-10
    • 2018-11-24
    • 2021-01-25
    • 1970-01-01
    • 2021-03-24
    相关资源
    最近更新 更多