2016-10-19 16 views
2

我試圖從條紋網站使條紋校驗樣品工作有效發佈的按鍵,但沒有得到有效發佈的按鍵設置

https://stripe.com/docs/checkout/rails

,但是當我試圖付錢,我收到此錯誤信息

您沒有設置有效的可發佈密鑰。用您的可發佈鍵調用 Stripe.setPublishableKey()。欲瞭解更多信息, 看到https://stripe.com/docs/stripe.js

在我的JavaScript控制檯錯誤信息

https://checkout.stripe.com/api/bootstrap?key=&locale=en-US未能 加載資源:服務器迴應400(錯誤請求)的狀態

在我的控制檯錯誤信息

入門使用「/」爲10.240.1.15在2016年10月19日17點29分24秒+0000不能 從10.240.1.15渲染控制檯!允許的網絡:127.0.0.1 :: 1, 127.0.0.0/127.255.255.255由ChargesController處理#new as HTML在佈局/應用程序中渲染費用/new.html.erb(0.5ms) 在53ms內完成200 OK :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] 
+0

你託管Stripe.js? – korben

+0

@Korben我顯示我的stripe.js內容。我不知道更多 –

+0

在stripe.rb中,您將可發佈鍵設置爲'ENV ['PUBLISHABLE_KEY']',但在您的元標記中它是'ENV [「STRIPE_PUBLIC_KEY」]' - 如果您使用'<%= tag:meta,:name =>'stripe-key',:content => ENV [「PUBLISHABLE_KEY」]%>'? –

回答

0

stripe.rb,你從ENV['PUBLISHABLE_KEY']設置:publishable_key,而在application.html.erb使用ENV["STRIPE_PUBLIC_KEY"]。你或許應該更新application.html.erb使用Rails.configuration.stripe[:publishable_key]代替:

<%= tag :meta, :name=> 'stripe-key', :content => Rails.configuration.stripe[:publishable_key] %> 

這就是說,這個問題很可能是你沒有設置environment variables。您可以嘗試直接在stripe.rb中設置密鑰嗎?例如: -

Rails.configuration.stripe = { 
    :publishable_key => 'pk_...', 
    :secret_key  => 'sk_...' 
} 

提醒一下,你可以找到你的API鑰匙放在儀表盤條:https://dashboard.stripe.com/account/apikeys

0

其實我加入這樣的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> 
相關問題