阅读所有文档,多个Stripe示例,并完成SO轮次。
客户实际上只需使用nil标记即可创建。当我尝试向该客户收费时,我遇到了错误,因为他们当然没有卡。
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"}
答案 0 :(得分:2)
问题是我的公钥没有引用它。
Stripe.setPublishableKey(<%= STRIPE_PUBLIC_KEY %>);
改为:
Stripe.setPublishableKey('<%= STRIPE_PUBLIC_KEY %>');
现在它运作正常。