2014-02-14 2 views
0

Прочтите все документы, несколько примеров Stripe и выполните 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_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"=>"[email protected]", 
"phone"=>"(434) 343-4343"}, 
"time"=>"Sat Mar 08 2014 11:30:00 GMT-0700 (MST)"}, 
"commit"=>"Book cleaning", 
"action"=>"create", 
"controller"=>"bookings"} 

ответ

2

Проблема заключалась в том, что у моего открытого ключа не было котировок.

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

переоделся в:

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

И теперь он работает отлично.

Смежные вопросы