Class: Killbill::Orbital::PaymentPlugin

Inherits:
Plugin::ActiveMerchant::PaymentPlugin
  • Object
show all
Defined in:
lib/orbital/api.rb

Constant Summary collapse

FIVE_MINUTES_AGO =
(5 * 60)
ONE_HOUR_AGO =
(1 * 3600)

Instance Method Summary collapse

Constructor Details

#initializePaymentPlugin

Returns a new instance of PaymentPlugin.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/orbital/api.rb', line 7

def initialize
  gateway_builder = Proc.new do |config|
    ::ActiveMerchant::Billing::OrbitalGateway.new :login => config[:login],
                                                  :password => config[:password],
                                                  # ActiveMerchant expects it to be a String
                                                  :merchant_id => config[:merchant_id].to_s
  end

  super(gateway_builder,
        :orbital,
        ::Killbill::Orbital::OrbitalPaymentMethod,
        ::Killbill::Orbital::OrbitalTransaction,
        ::Killbill::Orbital::OrbitalResponse)
end

Instance Method Details

#add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/orbital/api.rb', line 99

def add_payment_method(, kb_payment_method_id, payment_method_props, set_default, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_method_id, payment_method_props, set_default, properties, context)
end

#authorize_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



30
31
32
33
34
35
# File 'lib/orbital/api.rb', line 30

def authorize_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  options = {:mit_reference_trx_id => find_mit_ref_trx_id_if_needed(find_value_from_properties(properties, :mit_ref_trx_id),
                                                                    context.tenant_id)}
  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context, with_trace_num_and_order_id(properties))
end

#capture_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/orbital/api.rb', line 37

def capture_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  # Pass extra parameters for the gateway here
  options = properties_to_hash properties
  if options[:force_capture]
    last_auth_response = @response_model.send('auth_responses_from_kb_payment_id', kb_payment_id, context.tenant_id).last
    raise "Unable to retrieve last authorization for operation=capture, kb_payment_id=#{kb_payment_id}, kb_payment_transaction_id=#{kb_payment_transaction_id}, kb_payment_method_id=#{kb_payment_method_id}" if last_auth_response.nil?
    options[:payment_processor_account_id] = last_auth_response.
    options[:prior_auth_id] = last_auth_response.params_auth_code
    options[:order_id] = last_auth_response.second_reference_id if options[:order_id].nil?
    purchase_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, hash_to_properties(options), context)
  else
    super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context, with_trace_num_and_order_id(properties))
  end
end

#credit_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



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

def credit_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context, with_trace_num_and_order_id(properties))
end

#delete_payment_method(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/orbital/api.rb', line 107

def delete_payment_method(, kb_payment_method_id, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_method_id, properties, context)
end

#get_payment_info(kb_account_id, kb_payment_id, properties, context) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/orbital/api.rb', line 83

def get_payment_info(, kb_payment_id, properties, context)
  options = properties_to_hash(properties)

  plugin_trxs_info = super(, kb_payment_id, properties, context)
  return super(, kb_payment_id, properties, context) if try_fix_undefined_trxs(plugin_trxs_info, options, context)
  plugin_trxs_info
end

#get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/orbital/api.rb', line 115

def get_payment_method_detail(, kb_payment_method_id, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_method_id, properties, context)
end

#get_payment_methods(kb_account_id, refresh_from_gateway, properties, context) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/orbital/api.rb', line 127

def get_payment_methods(, refresh_from_gateway, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, refresh_from_gateway, properties, context)
end

#on_event(event) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/orbital/api.rb', line 22

def on_event(event)
  # Require to deal with per tenant configuration invalidation
  super(event)
  #
  # Custom event logic could be added below...
  #
end

#purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



52
53
54
55
56
57
# File 'lib/orbital/api.rb', line 52

def purchase_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  options = {:mit_reference_trx_id => find_mit_ref_trx_id_if_needed(find_value_from_properties(properties, :mit_ref_trx_id),
                                                                    context.tenant_id)}
  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context, with_trace_num_and_order_id(properties))
end

#refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/orbital/api.rb', line 75

def refund_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context, with_trace_num_and_order_id(properties))
end

#reset_payment_methods(kb_account_id, payment_methods, properties, context) ⇒ Object



143
144
145
# File 'lib/orbital/api.rb', line 143

def reset_payment_methods(, payment_methods, properties, context)
  super
end

#search_payment_methods(search_key, offset, limit, properties, context) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/orbital/api.rb', line 135

def search_payment_methods(search_key, offset, limit, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(search_key, offset, limit, properties, context)
end

#search_payments(search_key, offset, limit, properties, context) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/orbital/api.rb', line 91

def search_payments(search_key, offset, limit, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(search_key, offset, limit, properties, context)
end

#set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context) ⇒ Object



123
124
125
# File 'lib/orbital/api.rb', line 123

def set_default_payment_method(, kb_payment_method_id, properties, context)
  # TODO
end

#void_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/orbital/api.rb', line 59

def void_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context)
  # Pass extra parameters for the gateway here
  options = {}

  properties = merge_properties(properties, options)
  super(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context, with_trace_num_and_order_id(properties))
end