在嘗試爲測試用戶開票時,我總是收到「無法爲沒有活動卡的用戶收費」錯誤。Stripe RailsJS,無法爲沒有活動卡的客戶收取費用
該應用程序的工作原理是,用戶在輸入CC憑證後收取10美元的註冊費用。
我知道正在創建的客戶,但收費未發送
這裏是條錯誤
我credit_card_form.js文件,該文件是什麼收集信用卡信息並將其發送到分條,而不會觸及我的數據庫。
$(document).ready(function(){
\t var show_error, stripeResponseHandler, submitHandler;
\t
\t submitHandler = function (event) {
\t \t var $form = $(event.target);
\t \t $form.find("input[type=submit]").prop("disabled", true);
\t \t //If Stripe was initialized correctly this will create a token using the credit card info
\t \t if(Stripe){
\t \t \t Stripe.card.createToken($form, stripeResponseHandler);
\t \t \t show_error("CC token generated")
\t \t } else {
\t \t \t show_error("Failed to load credit card processing functionality. Please reload this page in your browser.")
\t \t }
\t \t return false;
\t \t };
\t // calling the SUBMIT
\t $(".cc_form").on('submit', submitHandler);
\t
\t // RESPONSE HANDLER
\t stripeResponseHandler = function (status, response) {
\t \t \t var token, $form;
\t \t \t $form = $('.cc_form');
\t \t \t if (response.error) {
\t \t \t \t console.log(response.error.message);
\t \t \t \t show_error(response.error.message);
\t \t \t \t $form.find("input[type=submit]").prop("disabled", false);
\t \t \t } else {
\t \t \t \t token = response.id;
\t \t \t \t $form.append($("<input type=\"hidden\" name=\"payment[token]\" />").val(token));
\t \t \t \t $("[data-stripe=number]").remove();
\t \t \t \t $("[data-stripe=cvv]").remove();
\t \t \t \t $("[data-stripe=exp-year]").remove();
\t \t \t \t $("[data-stripe=exp-month]").remove();
\t \t \t \t $("[data-stripe=label]").remove();
\t \t \t \t $form.get(0).submit();
\t \t \t }
\t \t \t return false;
\t };
\t
\t //ERROR HANDLING
\t show_error = function (message) {
\t \t if($("#flash-messages").size() < 1){
\t \t \t $('div.container.main div:first').prepend("<div id='flash-messages'></div>")
\t \t \t }
\t \t \t $("#flash-messages").html('<div class="alert alert-warning"><a class="close" data-dismiss="alert">×</a><div id="flash_alert">' + message + '</div></div>');
\t \t \t $('.alert').delay(5000).fadeOut(3000);
\t \t \t
\t \t return false;
\t };
});
\t
而且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>
我知道,正在創建的客戶,但我不知道爲什麼,當我使用測試信用卡號碼我的客戶不支付。到目前爲止,還沒有堆棧溢出的答案幫助我。
做了在條紋所創建的客戶都重視他們信用卡的鏈接? – doctororange
從最後一個代碼片段中可以看到信用卡已註冊。但是,在信用卡被保存到用戶之前,它將信用卡轉儲出來,因此它不會觸及分配數據庫 – Jack
我的意思是,如果您進入條帶儀表板並導航到其中的一位客戶,您是否看到信用卡在那裏? – doctororange