Class: Killbill::Plugin::ActiveMerchant::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/killbill/helpers/active_merchant/gateway.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, am_gateway, logger) ⇒ Gateway

Returns a new instance of Gateway.



13
14
15
16
17
18
19
20
21
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 13

def initialize(config, am_gateway, logger)
  @config = config
  @gateway = am_gateway
  @logger = logger

  # Override urls if needed (there is no easy way to do it earlier, because AM uses class_attribute)
  @gateway.class.test_url = @config[:test_url] unless @config[:test_url].nil?
  @gateway.class.live_url = @config[:live_url] unless @config[:live_url].nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 60

def method_missing(m, *args, &block)
  options = {}

  # The options hash should be the last argument, iterate through all to be safe
  args.reverse.each do |arg|
    if arg.respond_to?(:has_key?)
      options = arg
      return ::ActiveMerchant::Billing::Response.new(true, 'Skipped Gateway call') if Utils.normalized(arg, :skip_gw)
    end
  end

  @gateway.send(m, *args, &block)
rescue ::ActiveMerchant::ConnectionError => e
  # Need to unwrap it
  until e.triggering_exception.nil?
    e = e.triggering_exception
    break unless e.is_a?(::ActiveMerchant::ConnectionError)
  end
  handle_exception(e, options)
rescue => e
  handle_exception(e, options)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 11

def config
  @config
end

Class Method Details

.wrap(gateway_builder, config, logger) ⇒ Object



7
8
9
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 7

def self.wrap(gateway_builder, config, logger)
  Gateway.new(config, gateway_builder.call(config), logger)
end

Instance Method Details

#authorize(*args, &block) ⇒ Object



35
36
37
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 35

def authorize(*args, &block)
  method_missing(:authorize, *args, &block)
end

#capture(*args, &block) ⇒ Object

Unfortunate name…



40
41
42
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 40

def capture(*args, &block)
  method_missing(:capture, *args, &block)
end

#credit(*args, &block) ⇒ Object



52
53
54
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 52

def credit(*args, &block)
  method_missing(:credit, *args, &block)
end

#purchase(*args, &block) ⇒ Object



44
45
46
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 44

def purchase(*args, &block)
  method_missing(:purchase, *args, &block)
end

#refund(*args, &block) ⇒ Object



56
57
58
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 56

def refund(*args, &block)
  method_missing(:refund, *args, &block)
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 83

def respond_to?(method, include_private=false)
  @gateway.respond_to?(method, include_private) || super
end

#store(*args, &block) ⇒ Object

Materialize the most common operations - this is for performance reasons



27
28
29
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 27

def store(*args, &block)
  method_missing(:store, *args, &block)
end

#unstore(*args, &block) ⇒ Object



31
32
33
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 31

def unstore(*args, &block)
  method_missing(:unstore, *args, &block)
end

#void(*args, &block) ⇒ Object



48
49
50
# File 'lib/killbill/helpers/active_merchant/gateway.rb', line 48

def void(*args, &block)
  method_missing(:void, *args, &block)
end