Stripe RailsJS,无法向没有活动卡的客户收费

Stripe RailsJS, Cannot charge a customer that has no active card

我在尝试向测试用户收费时不断收到 "Cannot charge a user that has no active card" 错误。

该应用程序运行良好,因此用户在输入他们的 CC 凭据后会在注册时被收取 10 美元的费用。

我知道正在创建客户,但尚未发送费用

这是条纹错误

我的 credit_card_form.js 文件收集信用卡信息并将其发送到 stripe 而不会访问我的数据库。

$(document).ready(function(){
 var show_error, stripeResponseHandler, submitHandler;
 
 submitHandler = function (event) {
  var $form = $(event.target);
  $form.find("input[type=submit]").prop("disabled", true);
  //If Stripe was initialized correctly this will create a token using the credit card info
  if(Stripe){
   Stripe.card.createToken($form, stripeResponseHandler);
   show_error("CC token generated") 
  } else {
   show_error("Failed to load credit card processing functionality. Please reload this page in your browser.")
  }

  return false;

  };
 // calling the SUBMIT
 $(".cc_form").on('submit', submitHandler);
 
 // RESPONSE HANDLER
 stripeResponseHandler = function (status, response) {
   var token, $form;
   $form = $('.cc_form');
   if (response.error) {
    console.log(response.error.message);
    show_error(response.error.message);
    $form.find("input[type=submit]").prop("disabled", false);
   } else {
    token = response.id;
    $form.append($("<input type=\"hidden\" name=\"payment[token]\" />").val(token));
    $("[data-stripe=number]").remove();
    $("[data-stripe=cvv]").remove();
    $("[data-stripe=exp-year]").remove();
    $("[data-stripe=exp-month]").remove();
    $("[data-stripe=label]").remove();
    $form.get(0).submit();
   }

   return false;

 };
 
 //ERROR HANDLING
 show_error = function (message) {
  if($("#flash-messages").size() < 1){
   $('div.container.main div:first').prepend("<div id='flash-messages'></div>")
   }
   $("#flash-messages").html('<div class="alert alert-warning"><a class="close" data-dismiss="alert">×</a><div id="flash_alert">' + message + '</div></div>');
   $('.alert').delay(5000).fadeOut(3000);
   
  return false;
 };

});
 

和payment.rb

class Payment < ApplicationRecord
  attr_accessor :card_number, :card_cvv, :card_expires_month, :card_expires_year
  belongs_to :user
  
  def self.month_options
    Date::MONTHNAMES.compact.each_with_index.map{|name,i| ["#{i+1} - #{name}", i+1]}
  end
  
  def self.year_options
    (Date.today.year..(Date.today.year+10)).to_a
  end
  
  def process_payment
    customer = Stripe::Customer.create email:email, card:token

    
    Stripe::Charge.create customer:customer.id, amount: 1000, description: "Premium", currency: "usd"
  end
  
end

以及设备注册的片段new.html.erb,用户将从中付费

<div class="col-md-3">
  <%=p .select :card_expires_month, options_for_select(Payment.month_options), {include_blank: "Month"}, "data-stripe"=>"exp-month", class: "form-control", required: true%>
</div>
<div class="col-md-3">
  <%=p .select :card_expires_year, options_for_select(Payment.year_options.push), {include_blank: "Year"}, class: "form-control", data: {stripe: "exp-year"}, required: true%>
</div>

我知道正在创建客户,但我不知道为什么当我使用测试信用卡号时我的客户不付款。到目前为止,还没有关于堆栈溢出的答案对我有帮助。

Jack 和我 had a chat 发现 Stripe.js 没有加载,所以请求中没有发送令牌。

问题是 <%= javascript_include_tag 'https://js/stripe.com/v2' %>application.html.erb

中输入错误的 js link

正在修复 <%= javascript_include_tag 'https://js.stripe.com/v2/' %>