gpt4 book ai didi

javascript - Stripe RailsJS,无法向没有事件卡的客户收费

转载 作者:行者123 更新时间:2023-11-30 15:43:48 26 4
gpt4 key购买 nike

尝试向测试用户收费时,我不断收到“无法向没有事件卡的用户收费”错误。

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

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

enter image description here

这是 Stripe 错误

enter image description here

我的 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 未加载,因此未在请求中发送 token 。

问题是 <%= javascript_include_tag 'https://js/stripe.com/v2' %>application.html.erb 中错误输入的 js 链接

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

关于javascript - Stripe RailsJS,无法向没有事件卡的客户收费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40414239/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com