【发布时间】:2014-03-13 11:47:17
【问题描述】:
阅读所有文档、多个 Stripe 示例,并完成了 SO 轮次。
客户实际上是用 nil 令牌很好地创建的。但是,当我尝试向该客户收费时,我遇到了错误,因为他们当然没有卡。
HTML 标题
<%= 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"}
【问题讨论】:
标签: javascript ruby-on-rails ruby params stripe-payments