加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 有效的可发布密钥集,但没有有效的可发布密钥集

发布时间:2020-12-17 02:26:09 所属栏目:百科 来源:网络整理
导读:我试图从条纹网站工作制作条纹结帐样本 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 07001
我试图从条纹网站工作制作条纹结帐样本

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 07001

在我的JavaScript控制台中,错误消息是

07002 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元标记没有任何内容?

条纹样本使用他们自己的秘密和可发布的密钥,但我使用我的.

如果需要更多信息,请询问,我可以发帖.

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>

charges.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中添加了可发布的密钥:

<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读