gpt4 book ai didi

ruby-on-rails - Paypal 环境变量凭据

转载 作者:太空宇宙 更新时间:2023-11-03 16:39:08 26 4
gpt4 key购买 nike

如何为 PayPal 凭据设置环境变量?我搜索了很多但没有得到任何线索。这是中的代码 Paypal .rb

PayPal::SDK.load("config/paypal.yml", Rails.env)
PayPal::SDK.logger = Rails.logger
merchant_id = "sts9n"
public_key = "3jnfbc24f76"
private_key = "a0167fd52cf3857e"

最佳答案

您可以将您的凭据添加到 credentials.yml 中,如下所示

EDITOR=nano rails credentials:edit

在凭据文件中如下添加 PayPal key

paypal: 
development:
client_id: "sdsdsdvsdvsv"
client_secret: "sdfsdsdv"
production:
client_id: 'sdsdsdvsdvsv'
client_secret: 'sdsdsdvsdvsv'

然后在你的配置文件中创建一个名为 paypal.yml 的 YML 文件

development:
client_id: <%= Rails.application.credentials.paypal[:development][:client_id] %>
client_secret: <%= Rails.application.credentials.paypal[:development][:client_secret] %>

production:
client_id: <%= Rails.application.credentials.paypal[:production][:client_id] %>
client_secret: <%= Rails.application.credentials.paypal[:production][:client_secret] %>
mode: live

然后在initializers文件夹中创建一个paypal.rb文件

paypal_config_file = File.join(Rails.root,'config','paypal.yml')
raise "#{paypal_config_file} is missing!" unless File.exists? paypal_config_file
paypal_config = YAML.load(ERB.new(File.read(Rails.root.join('config','paypal.yml'))).result)[Rails.env].symbolize_keys

CLIENT_ID = paypal_config[:client_id]
CLIENT_SECRET = paypal_config[:client_secret]

这样,从开发到生产的切换,你不需要更改任何代码。

关于ruby-on-rails - Paypal 环境变量凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59389886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com