Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
536 views
in Technique[技术] by (71.8m points)

activemerchant - Ruby: How to initialize an active merchant gateway instance with credentials?

From this http://www.rubydoc.info/github/Shopify/active_merchant/ActiveMerchant%2FBilling%2FBase.gateway

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
)

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?

For an example, in the fixtures.yml file we can see this..

adyen: username: '' password: '' merchant_account: ''

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
)

I need to be able to initialize the gateway instance without hard-coding the username:, password: and merchant_account: parameters in the above example.

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should take a look at environment variables. They let you define variables in a safe palce and refer to them when needed.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...