当我在firebug控制台上点击paywithcard按钮时,我会得到(TypeError:window.multimedia(...)为null)。
button.html.erb
<%= form_tag front_charges_path do %>
<article>
<% if flash[:error].present? %>
<div id="error_explanation">
<p><%= flash[:error] %></p>
</div>
<% end %>
<label class="amount">
<span>Amount: <%=@cart_totals%></span>
</label>
</article>
<script src="https://js.stripe.com/v3/"></script>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Stripe.api_key = "pk_test_******************" %>"
data-description="A month's subscription"
data-amount="<%=@cart_totals%>"
data-locale="auto"></script>
<% end %>
<script type="text/javascript">
var widthQuery = window.matchMedia("(min-width: 600px)");
</script>
Stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['pk_test_****************'],
:secret_key => ENV['sk_test_************']
}
Stripe.api_key = "sk_test_****************"
Charges_controller.rb
class Front::ChargesController < ApplicationController
layout 'product'
def new
end
def create
# Amount in cents
@amount = 500
customer = Stripe::Customer.create(
:email => params[:ronakabhattrz],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe customer',
:currency => 'INR'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end