0
閱讀所有文檔,多個條紋示例,並完成SO輪。不創建令牌的條紋形式
客戶實際上被創建得很好,並帶有零的標記。儘管我嘗試向客戶收費時遇到了錯誤,但當然他們沒有卡。
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' } } %>
PARAMETERS
{"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"=>"[email protected]",
"phone"=>"(434) 343-4343"},
"time"=>"Sat Mar 08 2014 11:30:00 GMT-0700 (MST)"},
"commit"=>"Book cleaning",
"action"=>"create",
"controller"=>"bookings"}