Reputation: 21
I am trying to do my first test order through Stripe on my Rails app that I'm testing out but I'm getting a NoMethodError - undefined method `stripe' for #, exact line that's causing it is in a JS snippet on my form order file.
Edit: Adding screenshot of the error, changing Rails.configuration.stripe to Rails.application.secrets lets the page load but the checkout is throwing another error (screenshot also attached)
error screenshot publishable error
< script >
var handler = StripeCheckout.configure({
key: '<%= Rails.configuration.stripe[:publishable_key] %>',
token: function(token, arg) {
document.getElementById("stripeToken").value = token.id;
document.getElementById("stripeEmail").value = token.email;
document.getElementById("chargeForm").submit();
}
});
document.getElementById('btn-order').addEventListener('click', function(e) {
var quantity = $('#quantity').val();
var total_price = (quantity * "<%= @meal.price %>") + "00";
$('#total_price').val(total_price);
handler.open({
name: "Sixerr",
description: "<%= @meal.title %>",
amount: total_price
});
e.preventDefault();
}); < /script>
And here is my stripe.rb file
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
:secret_key => ENV['STRIPE_SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
There was a couple other answers but none of them seemed to fix the problem, appreciate any help here.
Upvotes: 1
Views: 1676
Reputation: 5871
Please make sure the file is present in the config/initializers folder, below is the configuration for stripe.rb file
if Rails.env.development?
Rails.configuration.stripe = {
:publishable_key => 'pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
:secret_key => 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
end
Stripe.api_key = Rails.configuration.stripe[:secret_key]
if Rails.env.production?
Rails.configuration.stripe = {
:publishable_key => 'pk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
:secret_key => 'sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
end
if Rails.env.test?
Rails.configuration.stripe = {
:publishable_key => 'pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxx',
:secret_key => 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxx'
}
end
Stripe.api_key = Rails.configuration.stripe[:secret_key]
Upvotes: 0
Reputation: 4060
You need to make sure that your stripe.rb
file is in the config/initializers
folder, and once that is done, you need to restart your webserver so that the initializer can be loaded.
Upvotes: 4