我正在尝试使 Stripe 网站上的 Stripe 结帐示例有效
https://stripe.com/docs/checkout/rails
,但是当我尝试付款时,我收到了这个 错误信息 .
You did not set a valid publishable key. Call Stripe.setPublishableKey() with your publishable key. For more info, see https://stripe.com/docs/stripe.js
在我的 JavaScript 控制台 错误信息 是
https://checkout.stripe.com/api/bootstrap?key=&locale=en-US Failed to load resource: the server responded with a status of 400 (Bad Request)
在我的 控制台 错误信息 是
Started GET "/" for 10.240.1.15 at 2016-10-19 17:29:24 +0000 Cannot render console from 10.240.1.15! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by ChargesController#new as HTML Rendered charges/new.html.erb within layouts/application (0.5ms) Completed 200 OK in 53ms (Views: 52.6ms | ActiveRecord: 0.0ms)
当我检查我的 html 源代码 stripe-key 元标记没有任何内容时?
strip 示例使用他们自己的 secret 和可发布 key ,但我使用我的。
请,如果需要更多信息,请询问,以便我可以发布。
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Workspace</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'https://js.stripe.com/v2/' %>
<%= csrf_meta_tags %>
<%= tag :meta, :name=> 'stripe-key', :content => ENV["STRIPE_PUBLIC_KEY"] %>
</head>
<body>
<%= yield %>
</body>
</html>
收费.html.erb
<head>
</head>
<body>
<%= yield %>
</body>
</html>
stripe.js
$(document).ready(function() {
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'));
});
stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['PUBLISHABLE_KEY'],
:secret_key => ENV['SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
最佳答案
我实际上在 new.html.erb 中添加了可发布 key ,如下所示:
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
Stripe.setPublishableKey('PUBLISHABLE_KEY');
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-description="A month's subscription"
data-amount="100"
data-locale="auto">
</script>
关于ruby-on-rails - 有效的可发布 key 集,但没有获得有效的可发布 key 集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40138298/