0

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!

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I was asking for a way without hardcoding the "username:" and "password:" and "merchant_account:" into the example code, and not the ":some_credential", ":some_other_credential" parts (where your solution would obviously solve). I think I was mistaken picking the term "credentials parameters", so editing now...
0

The username, password, and merchant_account are instance variables so you need to change them with instance_variable_set

gateway.instance_variable_set(:@username, :some_username) gateway.instance_variable_set(:@password, :some_password) gateway.instance_variable_set(:@merchant_account, :some_merchant_account) 

1 Comment

but that can only be true for the adien example.. what to do in case the gateway requires just two credentials like @username and @password? What if just requires one credential like @apikey?
0

I think i can answer my own question. One should pass every different initialization with its own hash..

require 'active_merchant' settings = {name: 'braintree_blue', merchant_id: 'x', public_key: 'y', private_key: 'z'} another_settings = {name: 'trust_commerce', login: 'TestMerchant', password: 'password'} Gateway = ActiveMerchant::Billing::Base::gateway(settings[:name]).new(settings) Another_Gateway = ActiveMerchant::Billing::Base::gateway(another_settings[:name]).new(another_settings) puts Gateway.options puts Another_Gateway.options 

Note that I could pass different options without the need to hardcode any keys, which is what i desired.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.