Ruby on rails Rails:Heroku上的条纹卡在测试模式下

Ruby on rails Rails:Heroku上的条纹卡在测试模式下,ruby-on-rails,heroku,stripe-payments,Ruby On Rails,Heroku,Stripe Payments,我已经在我的应用程序上设置了条带,这样它就可以在测试模式下在localhost和Heroku上完美运行。此后,我已切换到Stripe上的实时模式,并使用以下步骤更新我的Stripe\u api\u密钥和Stripe\u publishable\u密钥: 我还使用了stripe\u api\u key和stripe\u publishable\u key,正如我在其他文档中看到的那样,我想介绍我的基础知识 我的应用程序中有以下内容。example.yml: stripe_api_key: stri

我已经在我的应用程序上设置了条带,这样它就可以在测试模式下在
localhost
和Heroku上完美运行。此后,我已切换到Stripe上的实时模式,并使用以下步骤更新我的
Stripe\u api\u密钥
Stripe\u publishable\u密钥

我还使用了
stripe\u api\u key
stripe\u publishable\u key
,正如我在其他文档中看到的那样,我想介绍我的基础知识

我的
应用程序中有以下内容。example.yml

stripe_api_key:
stripe_publishable_key:

production:
  stripe_api_key:
  stripe_publishable_key:

SENDGRID_USERNAME:
SENDGRID_PASSWORD:

AWS_ACCESS_KEY_ID:
AWS_REGION:
AWS_SECRET_ACCESS_KEY:
S3_BUCKET_NAME:
应用程序.yml
具有相应的信息。我的
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]
有人知道为什么Stripe仍在Heroku上的生产服务器上以测试模式运行吗?

执行此操作时:

heroku配置:设置可发布的密钥=pk\u live\u。。。秘密密钥=现场密钥…

您正在heroku环境中设置两个环境变量,可以在rails中访问它们,分别为
ENV['PUBLISHABLE\u KEY']
ENV['SECRET\u KEY']

通过访问heroku仪表板、应用程序,然后
设置
并单击
显示配置变量
,您还可以查看已设置的环境变量、访问它们、删除它们或更改它们的值

您只需要在
stripe.rb中定义它们

Rails.configuration.stripe = {
  :publishable_key => ENV['PUBLISHABLE_KEY'],
  :secret_key      => ENV['SECRET_KEY']
}
或者如果你想使用你的秘密,在你的秘密上改变这个。yml

production:
  stripe_api_key: <%= ENV['PUBLISHABLE_KEY'] %>
  stripe_publishable_key: <%= ENV['SECRET_KEY'] %>
生产:
条带api密钥:
条带\u可发布\u密钥:
和以前一样留下你的stripe.rb

我仍然会将您的ENV变量名更改为更具体的名称,如
STRIPE\u publishible\u KEY
&
STRIPE\u SECRET\u KEY
我最终彻底摆脱了Figaro/
application.yml
并重新构造了我的
secrets.yml
文件,使其具有以下用于暂存/生产的结构:

# Do not keep production secrets in the repository,
# instead read values from the environment.
staging:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  stripe_api_key: <%= ENV["STRIPE_API_KEY"] %>
  stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %>
  sendgrid_username: <%= ENV["SENDGRID_USERNAME"] %>
  sendgrid_password: <%= ENV["SENDGRID_PASSWORD"] %>

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  stripe_api_key: <%= ENV["STRIPE_API_KEY"] %>
  stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %>
  sendgrid_username: <%= ENV["SENDGRID_USERNAME"] %>
  sendgrid_password: <%= ENV["SENDGRID_PASSWORD"] %>
#不要在存储库中保留生产机密,
#而是从环境中读取值。
登台:
机密密钥库:
条带api密钥:
条带\u可发布\u密钥:
sendgrid\u用户名:
sendgrid\u密码:
制作:
机密密钥库:
条带api密钥:
条带\u可发布\u密钥:
sendgrid\u用户名:
sendgrid\u密码:

之后一切正常。

设置这些密钥后是否重新启动服务器
heroku重新启动-a你的应用程序
@AbM,是的。我重新启动了整个应用程序好几次。在我的“secrets.yml”的制作部分,我有
stripe\u api\u key:
stripe\u publishable\u key:
,并通过heroku仪表板验证了这些相同的名字与我在heroku上的实时密钥配对。仍处于测试模式。请尝试仅更改
条带.rb
。并确保在设置
Stripe.api_key
时正确加载(只需
放置内容)。还可以通过检查源来检查呈现页面上设置为可发布键的内容。不幸的是,这也没有改变任何内容:(那么设置这些键的是什么呢?如果你发现了,那么你可以进行全局搜索(假设你的文本编辑器允许),看看你在哪里设置这些值,最终找出你哪里做错了。)
# Do not keep production secrets in the repository,
# instead read values from the environment.
staging:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  stripe_api_key: <%= ENV["STRIPE_API_KEY"] %>
  stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %>
  sendgrid_username: <%= ENV["SENDGRID_USERNAME"] %>
  sendgrid_password: <%= ENV["SENDGRID_PASSWORD"] %>

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  stripe_api_key: <%= ENV["STRIPE_API_KEY"] %>
  stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %>
  sendgrid_username: <%= ENV["SENDGRID_USERNAME"] %>
  sendgrid_password: <%= ENV["SENDGRID_PASSWORD"] %>