我在 javascript 方面不是最擅长的,并且对为什么我的咖啡脚本没有检索到条带令牌感到非常困惑。我检查了错误,它说卡返回零。我注意到如果我在错误页面上重新填写信用卡信息,它可以正常工作吗?
这是创建订阅的网址 /subscriptions/new?plan_id=1
这是一个信用卡错误,它指向 /subscriptions/
如果我在此页面上填写信用卡详细信息,则它可以工作并在条带上创建订阅。我在不是我的条纹表单视图的页面上收到此错误,并且可能导致问题
我收到此错误
Uncaught ReferenceError: Stripe is not defined subscriptions.js?body=1:5
(anonymous function) subscriptions.js?body=1:5
fire jquery.js?body=1:3049
self.fireWith jquery.js?body=1:3161
jQuery.extend.ready jquery.js?body=1:434
completed
这是我的看法
<%= javascript_include_tag "https://js.stripe.com/v2/" %>
<h1 class="callout callout-info">Signing up for <%= @subscription.plan.name %> Plan</h1>
<div class="poweredby">
<span><%= image_tag("/images/stripepower.png", :alt => "Safe with stripe", :class => "stripepower") %></span>
<span class="stripepower_description">Secure, Reliable, & Simple</span>
</div>
<div class="panel panel-default">
<div class="panel-body">
<%= form_for @subscription do |f| %>
<% if @subscription.errors.any? %>
<div class="error_messages">
<h2><%= pluralize(@subscription.errors.count, "error") %> prohibited this subscription from being saved:</h2>
<ul>
<% @subscription.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :plan_id %>
<%= f.hidden_field :email, :value => @useremail %>
<%= f.hidden_field :subscription_status, :value => "active" %>
<%= f.hidden_field :stripe_card_token %>
<% if @subscription.stripe_card_token.present? %>
Credit card has been provided.
<% else %>
<div class="form-group">
<%= label_tag :card_number, "Credit Card Number" %>
<%= text_field_tag :card_number, nil, name: nil, class: "form-control" %>
</div>
<div class="form-group">
<%= label_tag :card_code, "Security Code on Card (CVV)" %>
<%= text_field_tag :card_code, nil, name: nil, class: "form-control" %>
</div>
<div class="form-group">
<%= label_tag :card_month, "Card Expiration" %>
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", class: "form-control"} %>
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year", class: "form-control expirationdate"} %>
</div>
<% end %>
<div id="stripe_error">
<noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>
<div class="actions">
<%= f.submit "Subscribe", class: "btn btn-primary btn-lg" %>
</div>
<% end %>
</div>
</div>
这是我的咖啡脚本文件,感谢 rails cast
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
subscription.setupForm()
subscription =
setupForm: ->
$('#new_subscription').submit ->
$('input[type=submit]').attr('disabled', true)
if $('#card_number').length
subscription.processCard()
false
else
true
processCard: ->
card =
number: $('#card_number').val()
cvc: $('#card_code').val()
expMonth: $('#card_month').val()
expYear: $('#card_year').val()
Stripe.createToken(card, subscription.handleStripeResponse)
handleStripeResponse: (status, response) ->
if status == 200
$('#subscription_stripe_card_token').val(response.id)
$('#new_subscription')[0].submit()
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)