使用 Rails 6.1.3 , Ruby 3.0 + Stripe,但即使我认为我正确包含了所有键,我也会不断收到此错误:
配置 > 初始化程序 > stripe.rb
Rails.configuration.stripe = {
:publishable_key => Rails.application.secrets.publishable_key,
:secret_key => Rails.application.secrets.secret_key
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
应用 > 秘密.yml
development:
publishable_key: "pk_test_51ILY7..."
secret_key: "sk_test_51ILY7..."
在终端中,一旦我调用 EDITOR=nano rails credentials:edit,这就是我所看到的:
stripe:
development:
publishable_key: 'pk_test_51ILY7...'
secret_key: 'sk_test_51ILY7...'
production:
publishable_key: 'pk_live_51ILY7...'
secret_key: 'sk_live_51ILY7...'
我可以在 Rails 终端中看到的错误
Started POST "/checkout/create_order" for ::1 at 2021-02-22 18:25:10 +0100
Processing by CheckoutController#create_order as JS
Parameters: {"authenticity_token"=>"[FILTERED]", "id"=>"1"}
Order Load (0.9ms) SELECT "orders".* FROM "orders" WHERE "orders"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/checkout_controller.rb:6:in `create_order'
Completed 500 Internal Server Error in 24ms (ActiveRecord: 0.9ms | Allocations: 1751)
Stripe::AuthenticationError (No API key provided. Set your API key using "Stripe.api_key = <API-KEY>". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email support@stripe.com if you have any questions.):
任何见解问题出在哪里?
谢谢