Class: MerchantSidekick::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/merchant_sidekick/gateway.rb

Direct Known Subclasses

ActiveMerchant::Gateways::Base

Constant Summary collapse

@@config_file_name =
"merchant_sidekick.yml"

Class Method Summary collapse

Class Method Details

.configObject

Returns configuration hash. By default the configuration is read from a YAML file from the Rails config/merchant_sidekick.yml path.

E.g.

# config/merchant_sidekick.yml
development:
  login_id: foo
  transaction_key: bar
  mode: test
production:
  ...

or

# config/merchant_sidekick.yml
development:
  authorize_net_gateway:
    login_id: foo
    transaction_key: bar
    mode: test
  paypal_gateway:
    api_username: seller_XYZ_biz_api1.example.com
    api_password: ABCDEFG123456789
    signature: AsPC9BjkCyDFQXbStoZcgqH3hpacAX3IenGazd35.nEnXJKR9nfCmJDu
    pem_file_name: config/paypal.pem
    mode: test
production:
  ...


67
68
69
70
71
72
73
# File 'lib/merchant_sidekick/gateway.rb', line 67

def config
  unless @@config
    @@config = YAML.load_file(config_path)[Rails.env].symbolize_keys
    @@config = @@config[type].symbolize_keys if @@config[type]
  end
  @@config
end

.config_path(file_name = nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/merchant_sidekick/gateway.rb', line 30

def config_path(file_name = nil)
  unless @@config_path
    @@config_path = "#{Rails.root}/config/#{file_name || config_file_name}"
  end
  @@config_path
end

.default_gatewayObject



75
76
77
# File 'lib/merchant_sidekick/gateway.rb', line 75

def default_gateway
  @@default_gateway || raise("No gateway instance assigned, try e.g. MerchantSidekick::Gateway.default_gateway = ActiveMerchant::Billing::BogusGateway.new")
end

.typeObject

Returns the gateway type name derived from the class name independent of the module name, e.g. :authorize_net_gateway



26
27
28
# File 'lib/merchant_sidekick/gateway.rb', line 26

def type
  name.split("::").last ? name.split("::").last.underscore.to_sym : name.underscore.to_sym
end