Class: MerchantSidekick::ActiveMerchant::Gateways::PaypalGateway

Inherits:
Base
  • Object
show all
Defined in:
lib/merchant_sidekick/active_merchant/gateways/paypal_gateway.rb

Class Method Summary collapse

Methods inherited from Base

default_gateway=

Methods inherited from Gateway

config, config_path, default_gateway, type

Class Method Details

.gatewayObject

Returns an active merchant paypal gateway instance

E.g.

# config/active_merchant.yml
development:
  api_username: seller_XYZ_biz_api1.example.com
  api_password: ABCDEFG123456789
  signature: AsPC9BjkCyDFQXbStoZcgqH3hpacAX3IenGazd35.nEnXJKR9nfCmJDu
  pem_file_name: config/paypal.pem
  mode: test
production:
  ...


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/merchant_sidekick/active_merchant/gateways/paypal_gateway.rb', line 23

def gateway
  unless @@gateway
    options = {
      :login    => config[:api_username],
      :password => config[:api_password]
    }
    options.merge!({:test => true}) if config[:mode] == "test"
    options.merge!({:signature => config[:signature]}) unless config[:signature].blank?
  
    ::ActiveMerchant::Billing::Base.mode = :test if config[:mode] == "test"
    ::ActiveMerchant::Billing::PaypalGateway.pem_file = File.read(File.expand_path(config[:pem_file_name])) if config[:pem_file_name]
    @@gateway = ::ActiveMerchant::Billing::PaypalGateway.new(options)
  end
  @@gateway
end