I am trying to make stripe checkout sample from stripe website works
https://stripe.com/docs/checkout/rails
, yet when I try to pay, I receive this error message.
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
In my JavaScript console the error message is
https://checkout.stripe.com/api/bootstrap?key=&locale=en-US Failed to load resource: the server responded with a status of 400 (Bad Request)
In my console the error message is
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)
When I check my html source code stripe-key meta tag does not have any content?
The stripe sample uses their own secret and publishable keys, yet I use mine.
Please, if more info is needed, ask, so I can post.
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]
I actually added the publishable key in the new.html.erb like that:
<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>
I've got the same problem, to solve it , just put this code into your stripe.rb file
config/initializers/stripe.rb
Rails.configuration.stripe = {
publishable_key: Rails.application.secrets.stripe_publishable_key,
secret_key: Rails.application.secrets.stripe_secret_key
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
of course after you put the test_keys into config/secrets.yml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With