繁体   English   中英

条纹卡不存储,但客户是

[英]Stripe card not storing, but customer is

我可以将新客户保存到我的网络应用程序中,但我无法向该客户提供信用卡。 我相信我正确地遵循了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
)

如果没有在帖子表单上看到Rails登录就很难说这里的错误,但我想这是因为你没有在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")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM