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)
THIRTEEN_MONTHS_AGO =
(24 * 60 * 60 * 30 * 13)

Instance Method Summary collapse

Constructor Details

#initializePaymentPlugin

Returns a new instance of PaymentPlugin.



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

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



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

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



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

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



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

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



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

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



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

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



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

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



121
122
123
124
125
126
127
# File 'lib/orbital/api.rb', line 121

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



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

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



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

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



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

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



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/orbital/api.rb', line 76

def refund_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
  credit_opts = properties_to_hash(properties)
  if should_credit?(kb_payment_id, context, credit_opts)
    # Note: from the plugin perspective, this transaction is a CREDIT but Kill Bill doesn't care about PaymentTransactionInfoPlugin#TransactionType
    return credit_payment(, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, hash_to_properties(credit_opts), context)
  end
  # 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



149
150
151
# File 'lib/orbital/api.rb', line 149

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

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



141
142
143
144
145
146
147
# File 'lib/orbital/api.rb', line 141

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



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

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



129
130
131
# File 'lib/orbital/api.rb', line 129

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

#should_credit?(kb_payment_id, context, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
156
157
158
159
160
# File 'lib/orbital/api.rb', line 153

def should_credit?(kb_payment_id, context, options = {})
  transaction = @transaction_model.find_candidate_transaction_for_refund(kb_payment_id, context.tenant_id)
  return false if transaction.nil?

  threshold = (Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :janitor_delay_threshold) || THIRTEEN_MONTHS_AGO).to_i
  options[:payment_processor_account_id] ||= transaction.
  (now - transaction.created_at) >= threshold
end

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



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

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