Ruby:如何使用凭证初始化活动的商家网关实例? [英] Ruby: How to initialize an active merchant gateway instance with credentials?
问题描述
从此 http://www.rubydoc.info /github/Shopify/active_merchant/ActiveMerchant%2FBilling%2FBase.gateway
我应该使用此实例初始化active_merchant实例
I should just initialize an instance of active_merchant using this
gateway = ActiveMerchant::Billing::Base.gateway( gateway_name ).new(
:username => :some_credential
:password => :some_other_credential
)
但是我不知道:用户名
或:password
,但是它们位于固定文件 https://github.com/activemerchant/active_merchant/blob/master/test/fixtures.yml 。那么如何正确地做到这一点呢?
But I don't know :username
or :password
in advance, however they are in the fixtures file https://github.com/activemerchant/active_merchant/blob/master/test/fixtures.yml here. So how to do this properly?
例如,在fixtures.yml文件中,我们可以看到这一点。
For an example, in the fixtures.yml file we can see this..
adyen:
用户名:
密码:
商人帐户:
相应地,我们可以用它来初始化。.
Accordingly we can initialize with this..
gateway = ActiveMerchant::Billing::Base.gateway( 'adien' ).new(
username: => :some_credential
password: => :some_other_credential
merchant_account: => some_more_credential
)
我需要能够初始化网关实例,而无需对用户名进行硬编码:$上例中的c $ c>,
密码:
和 merchant_account:
参数。
I need to be able to initialize the gateway instance without hard-coding the username:
, password:
and merchant_account:
parameters in the above example.
谢谢!
推荐答案
您应该看看环境变量。它们使您可以在安全的地方定义变量,并在需要时引用它们。
You should take a look at environment variables. They let you define variables in a safe palce and refer to them when needed.
在某些地方您可以定义 PASSWORD = mysecretpassword
,然后在Rails代码中将其称为 ENV [ PASSWORD]
Somewhere you would define PASSWORD=mysecretpassword
and then in the Rails code you refer to it as ENV["PASSWORD"]
有很多方法这样。在这里看看:
There are many ways of doing this. Take a look here:
http://railsapps.github.io/rails-environment-variables.html
这篇关于Ruby:如何使用凭证初始化活动的商家网关实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!