gpt4 book ai didi

javascript - Stripe 形式不创建 token

转载 作者:行者123 更新时间:2023-12-02 17:45:45 25 4
gpt4 key购买 nike

阅读所有文档、多个 Stripe 示例,并完成 SO 轮。

客户实际上是用 nil token 创建的。不过,当我尝试向该客户收费时,我遇到了错误,因为他们当然没有卡。

HTML header

<%= javascript_include_tag "https://js.stripe.com/v2/" %>

<script type="text/javascript">
Stripe.setPublishableKey(<%= STRIPE_PUBLIC_KEY %>);

jQuery(function($) {
$('#cleaning-form').submit(function(event) {
var $form = $(this);

// 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 = $('#cleaning-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 {
// 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 re-submit
$form.get(0).submit();
}
};

FORM(它是多个部分,这是适用的部分)

<%= form_for @booking, :authenticity_token => true, :html => { :id => "cleaning-form" } do |f| %>
<h4>Credit Card Number</h4>
<%= text_field_tag :card_number, nil, :class => "valid payment-form", name: nil, :placeholder => "Card Number", :data => {:stripe => 'number' }, :tabindex => 1, :autofocus => true %>

<h4>Card security code (CVC)</h4>
<%= text_field_tag :card_code, nil,:class => "valid payment-form" , name: nil, :placeholder => "3 or 4 digits", :data => {:stripe => 'cvc' }, :tabindex => 2 %>

<h4>Expiration date</h4>
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", :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' } } %>

参数

{"utf8"=>"✓", 
"authenticity_token"=>"/D9mJRkSX7Wf51QHl+vzWPpweYsUUIfCcJrlbCZfPLE=",
"booking"=>
{"job"=>
{"bedroom"=>"1 bedroom", "bathroom"=>"1 bathroom", "extras"=>""},
"hours"=>"2",
"user"=>
{"name"=>"RERE234234",
"address"=>"34",
"state"=>"34",
"city"=>"4",
"zipcode"=>"34",
"email"=>"343223@AERAER.COM",
"phone"=>"(434) 343-4343"},
"time"=>"Sat Mar 08 2014 11:30:00 GMT-0700 (MST)"},
"commit"=>"Book cleaning",
"action"=>"create",
"controller"=>"bookings"}

最佳答案

问题是我的公钥没有引号。

Stripe.setPublishableKey(<%= STRIPE_PUBLIC_KEY %>);

更改为:

Stripe.setPublishableKey('<%= STRIPE_PUBLIC_KEY %>');

现在一切正常了。

关于javascript - Stripe 形式不创建 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21773888/

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