Class: PaymentTest::PaymentPlugin

Inherits:
Killbill::Plugin::Payment
  • Object
show all
Defined in:
lib/payment_test/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePaymentPlugin

Returns a new instance of PaymentPlugin.


35
36
37
38
39
40
41
# File 'lib/payment_test/api.rb', line 35

def initialize
  super
  @api_beatrix = PaymentPluginBeatrix.new(self)
  @api_control = PaymentPluginControl.new(self)

  @state = PaymentTest::State.instance
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/payment_test/api.rb', line 44

def method_missing(method, *args, &block)
  # properties is always the second last argument right before context
  args[args.length - 2] = [] if args[args.length - 2].nil?
  properties = args[args.length - 2]

  # Let's be cautious..
  PluginPropertyUtils.validate_properties(properties)

  if is_beatrix_call(properties)
    @api_beatrix.send method, *args
  else
    # Check if we need to throw
    @api_control.throw_exception_if_required(properties, @state.always_throw(method))

    # Check if we should return nil
    if @api_control.should_return_nil(properties, @state.always_return_nil(method))
      return nil
    end

    # Check if we need to sleep
    @api_control.sleep_if_required(properties, @state.sleep_time_sec(method))

    if @state.always_return_plugin_status_error(method)
      PluginPropertyUtils.add_property_if_not_exist(properties, 'TRANSACTION_STATUS', 'ERROR')
    end

    if @state.always_return_plugin_status_pending(method)
      PluginPropertyUtils.add_property_if_not_exist(properties, 'TRANSACTION_STATUS', 'PENDING')
    end

    if @state.always_return_plugin_status_canceled(method)
      PluginPropertyUtils.add_property_if_not_exist(properties, 'TRANSACTION_STATUS', 'CANCELED')
    end        

    # Finally make the call
    @api_control.send method, *args
  end
end

Instance Attribute Details

#api_beatrixObject (readonly)

Returns the value of attribute api_beatrix


11
12
13
# File 'lib/payment_test/api.rb', line 11

def api_beatrix
  @api_beatrix
end

#api_controlObject (readonly)

Returns the value of attribute api_control


11
12
13
# File 'lib/payment_test/api.rb', line 11

def api_control
  @api_control
end