killbill-litle 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Jarfile CHANGED
@@ -1,3 +1,5 @@
1
- jar 'com.ning.billing:killbill-api', '0.1.80'
2
- jar 'com.ning.billing:killbill-util:tests', '0.1.80'
1
+ jar 'com.ning.billing:killbill-api', '0.3.0'
2
+ jar 'com.ning.billing.plugin:killbill-plugin-api-notification', '0.2.4'
3
+ jar 'com.ning.billing.plugin:killbill-plugin-api-payment', '0.2.4'
4
+ jar 'com.ning.billing:killbill-util:tests', '0.2.6-SNAPSHOT'
3
5
  jar 'javax.servlet:javax.servlet-api', '3.0.1'
data/NEWS ADDED
@@ -0,0 +1,2 @@
1
+ 1.3.0
2
+ Update to killbill 1.1.2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.0
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.rdoc_options << '--exclude' << '.'
24
24
 
25
- s.add_dependency 'killbill', '~> 1.0.19'
25
+ s.add_dependency 'killbill', '~> 1.1.2'
26
26
  s.add_dependency 'activemerchant', '~> 2.0.0'
27
27
  s.add_dependency 'activerecord', '~> 3.2.1'
28
28
  s.add_dependency 'sinatra', '~> 1.3.4'
data/lib/litle/api.rb CHANGED
@@ -13,15 +13,15 @@ module Killbill::Litle
13
13
  ActiveRecord::Base.connection.close
14
14
  end
15
15
 
16
- def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, call_context, options = {})
16
+ def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, call_context = nil, options = {})
17
17
  # If the payment was already made, just return the status
18
18
  # TODO Should we set the Litle Id field to check for dups (https://www.litle.com/mc-secure/DupeChecking_V1.2.pdf)?
19
- litle_transaction = LitleTransaction.from_kb_payment_id(kb_payment_id.to_s) rescue nil
19
+ litle_transaction = LitleTransaction.from_kb_payment_id(kb_payment_id) rescue nil
20
20
  return litle_transaction.litle_response.to_payment_response unless litle_transaction.nil?
21
21
 
22
22
  # Required argument
23
23
  # Note! The field is limited to 25 chars, so we convert the UUID (in hex) to base64
24
- options[:order_id] ||= Utils.compact_uuid kb_payment_id.to_s
24
+ options[:order_id] ||= Utils.compact_uuid kb_payment_id
25
25
 
26
26
  # Set a default report group
27
27
  options[:merchant] ||= report_group_for_currency(currency)
@@ -36,17 +36,17 @@ module Killbill::Litle
36
36
  response.to_payment_response
37
37
  end
38
38
 
39
- def get_payment_info(kb_account_id, kb_payment_id, tenant_context, options = {})
39
+ def get_payment_info(kb_account_id, kb_payment_id, tenant_context = nil, options = {})
40
40
  # We assume the payment is immutable in Litle and only look at our tables since there
41
41
  # doesn't seem to be a Litle API to fetch details for a given transaction.
42
42
  # TODO How can we support Authorization/Sale Recycling?
43
- litle_transaction = LitleTransaction.from_kb_payment_id(kb_payment_id.to_s)
43
+ litle_transaction = LitleTransaction.from_kb_payment_id(kb_payment_id)
44
44
 
45
45
  litle_transaction.litle_response.to_payment_response
46
46
  end
47
47
 
48
- def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, call_context, options = {})
49
- litle_transaction = LitleTransaction.find_candidate_transaction_for_refund(kb_payment_id.to_s, amount_in_cents)
48
+ def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, call_context = nil, options = {})
49
+ litle_transaction = LitleTransaction.find_candidate_transaction_for_refund(kb_payment_id, amount_in_cents)
50
50
 
51
51
  # Set a default report group
52
52
  options[:merchant] ||= report_group_for_currency(currency)
@@ -59,15 +59,15 @@ module Killbill::Litle
59
59
  response.to_refund_response
60
60
  end
61
61
 
62
- def get_refund_info(kb_account_id, kb_payment_id, tenant_context, options = {})
62
+ def get_refund_info(kb_account_id, kb_payment_id, tenant_context = nil, options = {})
63
63
  # We assume the refund is immutable in Litle and only look at our tables since there
64
64
  # doesn't seem to be a Litle API to fetch details for a given transaction.
65
- litle_transaction = LitleTransaction.refund_from_kb_payment_id(kb_payment_id.to_s)
65
+ litle_transaction = LitleTransaction.refund_from_kb_payment_id(kb_payment_id)
66
66
 
67
67
  litle_transaction.litle_response.to_refund_response
68
68
  end
69
69
 
70
- def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, call_context, options = {})
70
+ def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, call_context = nil, options = {})
71
71
  # Set a default report group
72
72
  options[:merchant] ||= report_group_for_account(kb_account_id)
73
73
 
@@ -80,8 +80,8 @@ module Killbill::Litle
80
80
  response = save_response_and_transaction litle_response, :add_payment_method
81
81
 
82
82
  if response.success
83
- LitlePaymentMethod.create :kb_account_id => kb_account_id.to_s,
84
- :kb_payment_method_id => kb_payment_method_id.to_s,
83
+ LitlePaymentMethod.create :kb_account_id => kb_account_id,
84
+ :kb_payment_method_id => kb_payment_method_id,
85
85
  :litle_token => response.litle_token,
86
86
  :cc_first_name => find_value_from_payment_method_props(payment_method_props, 'ccFirstName'),
87
87
  :cc_last_name => find_value_from_payment_method_props(payment_method_props, 'ccLastName'),
@@ -100,26 +100,26 @@ module Killbill::Litle
100
100
  end
101
101
  end
102
102
 
103
- def delete_payment_method(kb_account_id, kb_payment_method_id, call_context, options = {})
104
- LitlePaymentMethod.mark_as_deleted! kb_payment_method_id.to_s
103
+ def delete_payment_method(kb_account_id, kb_payment_method_id, call_context = nil, options = {})
104
+ LitlePaymentMethod.mark_as_deleted! kb_payment_method_id
105
105
  end
106
106
 
107
- def get_payment_method_detail(kb_account_id, kb_payment_method_id, tenant_context, options = {})
108
- LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id.to_s).to_payment_method_response
107
+ def get_payment_method_detail(kb_account_id, kb_payment_method_id, tenant_context = nil, options = {})
108
+ LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id).to_payment_method_response
109
109
  end
110
110
 
111
- def set_default_payment_method(kb_account_id, kb_payment_method_id, call_context, options = {})
111
+ def set_default_payment_method(kb_account_id, kb_payment_method_id, call_context = nil, options = {})
112
112
  # No-op
113
113
  end
114
114
 
115
- def get_payment_methods(kb_account_id, refresh_from_gateway, call_context, options = {})
116
- LitlePaymentMethod.from_kb_account_id(kb_account_id.to_s).collect { |pm| pm.to_payment_method_info_response }
115
+ def get_payment_methods(kb_account_id, refresh_from_gateway = false, call_context = nil, options = {})
116
+ LitlePaymentMethod.from_kb_account_id(kb_account_id).collect { |pm| pm.to_payment_method_info_response }
117
117
  end
118
118
 
119
119
  def reset_payment_methods(kb_account_id, payment_methods)
120
120
  return if payment_methods.nil?
121
121
 
122
- litle_pms = LitlePaymentMethod.from_kb_account_id(kb_account_id.to_s)
122
+ litle_pms = LitlePaymentMethod.from_kb_account_id(kb_account_id)
123
123
 
124
124
  payment_methods.delete_if do |payment_method_info_plugin|
125
125
  should_be_deleted = false
@@ -127,16 +127,16 @@ module Killbill::Litle
127
127
  # Do litle_pm and payment_method_info_plugin represent the same Litle payment method?
128
128
  if litle_pm.external_payment_method_id == payment_method_info_plugin.external_payment_method_id
129
129
  # Do we already have a kb_payment_method_id?
130
- if litle_pm.kb_payment_method_id == payment_method_info_plugin.payment_method_id.to_s
130
+ if litle_pm.kb_payment_method_id == payment_method_info_plugin.payment_method_id
131
131
  should_be_deleted = true
132
132
  break
133
133
  elsif litle_pm.kb_payment_method_id.nil?
134
134
  # We didn't have the kb_payment_method_id - update it
135
- litle_pm.kb_payment_method_id = payment_method_info_plugin.payment_method_id.to_s
135
+ litle_pm.kb_payment_method_id = payment_method_info_plugin.payment_method_id
136
136
  should_be_deleted = litle_pm.save
137
137
  break
138
- # Otherwise the same token points to 2 different kb_payment_method_id. This should never happen,
139
- # but we cowardly will insert a second row below
138
+ # Otherwise the same token points to 2 different kb_payment_method_id. This should never happen,
139
+ # but we cowardly will insert a second row below
140
140
  end
141
141
  end
142
142
  end
@@ -146,8 +146,8 @@ module Killbill::Litle
146
146
 
147
147
  # The remaining elements in payment_methods are not in our table (this should never happen?!)
148
148
  payment_methods.each do |payment_method_info_plugin|
149
- LitlePaymentMethod.create :kb_account_id => payment_method_info_plugin.account_id.to_s,
150
- :kb_payment_method_id => payment_method_info_plugin.payment_method_id.to_s,
149
+ LitlePaymentMethod.create :kb_account_id => payment_method_info_plugin.account_id,
150
+ :kb_payment_method_id => payment_method_info_plugin.payment_method_id,
151
151
  :litle_token => payment_method_info_plugin.external_payment_method_id
152
152
  end
153
153
  end
@@ -162,35 +162,35 @@ module Killbill::Litle
162
162
  def report_group_for_account(kb_account_id)
163
163
  currency = account_currency(kb_account_id)
164
164
  report_group_for_currency(currency)
165
- rescue Killbill::Plugin::JKillbillApi::APINotAvailableError
166
- "Default Report Group"
165
+ rescue => e
166
+ 'Default Report Group'
167
167
  end
168
168
 
169
169
  def account_currency(kb_account_id)
170
- account = @kb_apis.get_account_by_id(kb_account_id)
170
+ account = @kb_apis.account_user_api.get_account_by_id(kb_account_id, @kb_apis.create_context)
171
171
  account.currency
172
172
  end
173
173
 
174
174
  def report_group_for_currency(currency)
175
- "Report Group for #{currency.respond_to?(:enum) ? currency.enum : currency.to_s}"
175
+ "Report Group for #{currency.to_s}"
176
176
  end
177
177
 
178
178
  def get_token(kb_payment_method_id)
179
- LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id.to_s).litle_token
179
+ LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id).litle_token
180
180
  end
181
181
 
182
182
  def save_response_and_transaction(litle_response, api_call, kb_payment_id=nil, amount_in_cents=0)
183
183
  @logger.warn "Unsuccessful #{api_call}: #{litle_response.message}" unless litle_response.success?
184
184
 
185
185
  # Save the response to our logs
186
- response = LitleResponse.from_response(api_call, kb_payment_id.to_s, litle_response)
186
+ response = LitleResponse.from_response(api_call, kb_payment_id, litle_response)
187
187
  response.save!
188
188
 
189
189
  if response.success and !kb_payment_id.blank? and !response.litle_txn_id.blank?
190
190
  # Record the transaction
191
191
  transaction = response.create_litle_transaction!(:amount_in_cents => amount_in_cents,
192
192
  :api_call => api_call,
193
- :kb_payment_id => kb_payment_id.to_s,
193
+ :kb_payment_id => kb_payment_id,
194
194
  :litle_txn_id => response.litle_txn_id)
195
195
  @logger.debug "Recorded transaction: #{transaction.inspect}"
196
196
  end
@@ -31,7 +31,7 @@ module Killbill::Litle
31
31
  end
32
32
 
33
33
  def self.gateway_for_currency(currency)
34
- currency_sym = currency.respond_to?(:enum) ? currency.enum.upcase.to_sym : currency.to_s.upcase.to_sym
34
+ currency_sym = currency.to_s.upcase.to_sym
35
35
  gateway = @@gateways[currency_sym]
36
36
  raise "Gateway for #{currency} not configured!" if gateway.nil?
37
37
  gateway
@@ -37,28 +37,35 @@ module Killbill::Litle
37
37
 
38
38
  def to_payment_method_response
39
39
  properties = []
40
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'token', litle_token)
40
+ properties << create_pm_kv_info('token', litle_token)
41
41
 
42
- Killbill::Plugin::Model::PaymentMethodPlugin.new(external_payment_method_id,
43
- is_default,
44
- properties,
45
- nil,
46
- 'CreditCard',
47
- cc_name,
48
- cc_type,
49
- cc_exp_month,
50
- cc_exp_year,
51
- cc_last_4,
52
- address1,
53
- address2,
54
- city,
55
- state,
56
- zip,
57
- country)
42
+ pm_plugin = Killbill::Plugin::Model::PaymentMethodPlugin.new
43
+ pm_plugin.external_payment_method_id = external_payment_method_id
44
+ pm_plugin.is_default_payment_method = is_default
45
+ pm_plugin.properties = properties
46
+ pm_plugin.type = 'CreditCard'
47
+ pm_plugin.cc_name = cc_name
48
+ pm_plugin.cc_type = cc_type
49
+ pm_plugin.cc_expiration_month = cc_exp_month
50
+ pm_plugin.cc_expiration_year = cc_exp_year
51
+ pm_plugin.cc_last4 = cc_last_4
52
+ pm_plugin.address1 = address1
53
+ pm_plugin.address2 = address2
54
+ pm_plugin.city = city
55
+ pm_plugin.state = state
56
+ pm_plugin.zip = zip
57
+ pm_plugin.country = country
58
+
59
+ pm_plugin
58
60
  end
59
61
 
60
62
  def to_payment_method_info_response
61
- Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, kb_payment_method_id, is_default, external_payment_method_id)
63
+ pm_info_plugin = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
64
+ pm_info_plugin.account_id = kb_account_id
65
+ pm_info_plugin.payment_method_id = kb_payment_method_id
66
+ pm_info_plugin.is_default = is_default
67
+ pm_info_plugin.external_payment_method_id = external_payment_method_id
68
+ pm_info_plugin
62
69
  end
63
70
 
64
71
  def is_default
@@ -77,5 +84,14 @@ module Killbill::Litle
77
84
  nil
78
85
  end
79
86
  end
87
+
88
+ private
89
+
90
+ def create_pm_kv_info(key, value)
91
+ prop = Killbill::Plugin::Model::PaymentMethodKVInfo.new
92
+ prop.key = key
93
+ prop.value = value
94
+ prop
95
+ end
80
96
  end
81
97
  end
@@ -47,33 +47,33 @@ module Killbill::Litle
47
47
 
48
48
  def self.from_response(api_call, kb_payment_id, response)
49
49
  LitleResponse.new({
50
- :api_call => api_call,
51
- :kb_payment_id => kb_payment_id,
52
- :message => response.message,
53
- :authorization => response.authorization,
54
- :fraud_review => response.fraud_review?,
55
- :test => response.test?,
56
- :params_litleonelineresponse_message => extract(response, "litleOnlineResponse", "message"),
57
- :params_litleonelineresponse_response => extract(response, "litleOnlineResponse", "response"),
58
- :params_litleonelineresponse_version => extract(response, "litleOnlineResponse", "version"),
59
- :params_litleonelineresponse_xmlns => extract(response, "litleOnlineResponse", "xmlns"),
60
- :params_litleonelineresponse_saleresponse_customer_id => extract(response, "litleOnlineResponse", "saleResponse", "customerId"),
61
- :params_litleonelineresponse_saleresponse_id => extract(response, "litleOnlineResponse", "saleResponse", "id"),
62
- :params_litleonelineresponse_saleresponse_report_group => extract(response, "litleOnlineResponse", "saleResponse", "reportGroup"),
63
- :params_litleonelineresponse_saleresponse_litle_txn_id => extract(response, "litleOnlineResponse", "saleResponse", "litleTxnId"),
64
- :params_litleonelineresponse_saleresponse_order_id => extract(response, "litleOnlineResponse", "saleResponse", "orderId"),
65
- :params_litleonelineresponse_saleresponse_response => extract(response, "litleOnlineResponse", "saleResponse", "response"),
66
- :params_litleonelineresponse_saleresponse_response_time => extract(response, "litleOnlineResponse", "saleResponse", "responseTime"),
67
- :params_litleonelineresponse_saleresponse_message => extract(response, "litleOnlineResponse", "saleResponse", "message"),
68
- :params_litleonelineresponse_saleresponse_auth_code => extract(response, "litleOnlineResponse", "saleResponse", "authCode"),
69
- :avs_result_code => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.code : response.avs_result['code'],
70
- :avs_result_message => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.message : response.avs_result['message'],
71
- :avs_result_street_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.street_match : response.avs_result['street_match'],
72
- :avs_result_postal_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.postal_match : response.avs_result['postal_match'],
73
- :cvv_result_code => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.code : response.cvv_result['code'],
74
- :cvv_result_message => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.message : response.cvv_result['message'],
75
- :success => response.success?
76
- })
50
+ :api_call => api_call,
51
+ :kb_payment_id => kb_payment_id,
52
+ :message => response.message,
53
+ :authorization => response.authorization,
54
+ :fraud_review => response.fraud_review?,
55
+ :test => response.test?,
56
+ :params_litleonelineresponse_message => extract(response, "litleOnlineResponse", "message"),
57
+ :params_litleonelineresponse_response => extract(response, "litleOnlineResponse", "response"),
58
+ :params_litleonelineresponse_version => extract(response, "litleOnlineResponse", "version"),
59
+ :params_litleonelineresponse_xmlns => extract(response, "litleOnlineResponse", "xmlns"),
60
+ :params_litleonelineresponse_saleresponse_customer_id => extract(response, "litleOnlineResponse", "saleResponse", "customerId"),
61
+ :params_litleonelineresponse_saleresponse_id => extract(response, "litleOnlineResponse", "saleResponse", "id"),
62
+ :params_litleonelineresponse_saleresponse_report_group => extract(response, "litleOnlineResponse", "saleResponse", "reportGroup"),
63
+ :params_litleonelineresponse_saleresponse_litle_txn_id => extract(response, "litleOnlineResponse", "saleResponse", "litleTxnId"),
64
+ :params_litleonelineresponse_saleresponse_order_id => extract(response, "litleOnlineResponse", "saleResponse", "orderId"),
65
+ :params_litleonelineresponse_saleresponse_response => extract(response, "litleOnlineResponse", "saleResponse", "response"),
66
+ :params_litleonelineresponse_saleresponse_response_time => extract(response, "litleOnlineResponse", "saleResponse", "responseTime"),
67
+ :params_litleonelineresponse_saleresponse_message => extract(response, "litleOnlineResponse", "saleResponse", "message"),
68
+ :params_litleonelineresponse_saleresponse_auth_code => extract(response, "litleOnlineResponse", "saleResponse", "authCode"),
69
+ :avs_result_code => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.code : response.avs_result['code'],
70
+ :avs_result_message => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.message : response.avs_result['message'],
71
+ :avs_result_street_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.street_match : response.avs_result['street_match'],
72
+ :avs_result_postal_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.postal_match : response.avs_result['postal_match'],
73
+ :cvv_result_code => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.code : response.cvv_result['code'],
74
+ :cvv_result_message => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.message : response.cvv_result['message'],
75
+ :success => response.success?
76
+ })
77
77
  end
78
78
 
79
79
  def to_payment_response
@@ -104,11 +104,26 @@ module Killbill::Litle
104
104
  gateway_error_code = params_litleonelineresponse_saleresponse_response
105
105
 
106
106
  if type == :payment
107
- status = success ? Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED) : Killbill::Plugin::Model::PaymentPluginStatus.new(:ERROR)
108
- Killbill::Plugin::Model::PaymentInfoPlugin.new(amount_in_cents, created_date, effective_date, status, gateway_error, gateway_error_code, first_payment_reference_id, second_payment_reference_id)
107
+ p_info_plugin = Killbill::Plugin::Model::PaymentInfoPlugin.new
108
+ p_info_plugin.amount = amount_in_cents
109
+ p_info_plugin.created_date = created_date
110
+ p_info_plugin.effective_date = effective_date
111
+ p_info_plugin.status = (success ? :PROCESSED : :ERROR)
112
+ p_info_plugin.gateway_error = gateway_error
113
+ p_info_plugin.gateway_error_code = gateway_error_code
114
+ p_info_plugin.first_payment_reference_id = first_payment_reference_id
115
+ p_info_plugin.second_payment_reference_id = second_payment_reference_id
116
+ p_info_plugin
109
117
  else
110
- status = success ? Killbill::Plugin::Model::RefundPluginStatus.new(:PROCESSED) : Killbill::Plugin::Model::RefundPluginStatus.new(:ERROR)
111
- Killbill::Plugin::Model::RefundInfoPlugin.new(amount_in_cents, created_date, effective_date, status, gateway_error, gateway_error_code, first_payment_reference_id)
118
+ r_info_plugin = Killbill::Plugin::Model::RefundInfoPlugin.new
119
+ r_info_plugin.amount = amount_in_cents
120
+ r_info_plugin.created_date = created_date
121
+ r_info_plugin.effective_date = effective_date
122
+ r_info_plugin.status = (success ? :PROCESSED : :ERROR)
123
+ r_info_plugin.gateway_error = gateway_error
124
+ r_info_plugin.gateway_error_code = gateway_error_code
125
+ r_info_plugin.reference_id = first_payment_reference_id
126
+ r_info_plugin
112
127
  end
113
128
  end
114
129
 
@@ -14,11 +14,10 @@ module Killbill::Litle
14
14
  end
15
15
  end
16
16
 
17
- def get_currency(kb_account_id_s)
18
- kb_account_id = Killbill::Plugin::Model::UUID.new(kb_account_id_s)
17
+ def get_currency(kb_account_id)
19
18
  account = kb_apis.get_account_by_id(kb_account_id)
20
- account.currency.enum
21
- rescue Killbill::Plugin::JKillbillApi::APINotAvailableError
19
+ account.currency
20
+ rescue => e
22
21
  'USD'
23
22
  end
24
23
 
data/pom.xml CHANGED
@@ -25,7 +25,7 @@
25
25
  <groupId>com.ning.killbill.ruby</groupId>
26
26
  <artifactId>litle-plugin</artifactId>
27
27
  <packaging>pom</packaging>
28
- <version>1.2.1</version>
28
+ <version>1.3.0</version>
29
29
  <name>litle-plugin</name>
30
30
  <url>http://github.com/killbill/killbill-litle-plugin</url>
31
31
  <description>Plugin for accessing Litle as a payment gateway</description>
@@ -32,7 +32,7 @@ describe Killbill::Litle::PaymentPlugin do
32
32
  it 'should reset payment methods' do
33
33
  kb_account_id = '129384'
34
34
 
35
- @plugin.get_payment_methods(kb_account_id, false, nil).size.should == 0
35
+ @plugin.get_payment_methods(kb_account_id).size.should == 0
36
36
  verify_pms kb_account_id, 0
37
37
 
38
38
  # Create a pm with a kb_payment_method_id
@@ -44,19 +44,19 @@ describe Killbill::Litle::PaymentPlugin do
44
44
  # Add some in KillBill and reset
45
45
  payment_methods = []
46
46
  # Random order... Shouldn't matter...
47
- payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-3', false, 'litle-3')
48
- payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-2', false, 'litle-2')
49
- payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-4', false, 'litle-4')
47
+ payment_methods << create_pm_info_plugin(kb_account_id, 'kb-3', false, 'litle-3')
48
+ payment_methods << create_pm_info_plugin(kb_account_id, 'kb-2', false, 'litle-2')
49
+ payment_methods << create_pm_info_plugin(kb_account_id, 'kb-4', false, 'litle-4')
50
50
  @plugin.reset_payment_methods kb_account_id, payment_methods
51
51
  verify_pms kb_account_id, 4
52
52
 
53
53
  # Add a payment method without a kb_payment_method_id
54
54
  Killbill::Litle::LitlePaymentMethod.create :kb_account_id => kb_account_id,
55
55
  :litle_token => 'litle-5'
56
- @plugin.get_payment_methods(kb_account_id, false, nil).size.should == 5
56
+ @plugin.get_payment_methods(kb_account_id).size.should == 5
57
57
 
58
58
  # Verify we can match it
59
- payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-5', false, 'litle-5')
59
+ payment_methods << create_pm_info_plugin(kb_account_id, 'kb-5', false, 'litle-5')
60
60
  @plugin.reset_payment_methods kb_account_id, payment_methods
61
61
  verify_pms kb_account_id, 5
62
62
 
@@ -66,7 +66,7 @@ describe Killbill::Litle::PaymentPlugin do
66
66
  private
67
67
 
68
68
  def verify_pms(kb_account_id, size)
69
- pms = @plugin.get_payment_methods(kb_account_id, false, nil)
69
+ pms = @plugin.get_payment_methods(kb_account_id)
70
70
  pms.size.should == size
71
71
  pms.each do |pm|
72
72
  pm.account_id.should == kb_account_id
@@ -74,4 +74,13 @@ describe Killbill::Litle::PaymentPlugin do
74
74
  pm.external_payment_method_id.should == 'litle-' + pm.payment_method_id.split('-')[1]
75
75
  end
76
76
  end
77
+
78
+ def create_pm_info_plugin(kb_account_id, kb_payment_method_id, is_default, external_payment_method_id)
79
+ pm_info_plugin = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
80
+ pm_info_plugin.account_id = kb_account_id
81
+ pm_info_plugin.payment_method_id = kb_payment_method_id
82
+ pm_info_plugin.is_default = is_default
83
+ pm_info_plugin.external_payment_method_id = external_payment_method_id
84
+ pm_info_plugin
85
+ end
77
86
  end
@@ -3,33 +3,30 @@ require 'logger'
3
3
 
4
4
  ActiveMerchant::Billing::Base.mode = :test
5
5
 
6
- class KillbillApiWithFakeGetAccountById < Killbill::Plugin::KillbillApi
6
+ class FakeJavaUserAccountApi
7
+ attr_accessor :accounts
7
8
 
8
- def initialize(japi_proxy)
9
- super(japi_proxy)
9
+ def initialize
10
+ @accounts = []
10
11
  end
11
12
 
12
- # Returns an account where we specify the currency for the report group
13
- def get_account_by_id(id)
14
- Killbill::Plugin::Model::Account.new(id, nil, nil, nil, nil, nil, 1, nil, 1, 'USD', nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, false, true)
13
+ def get_account_by_id(id, context)
14
+ @accounts.find { |account| account.id == id.to_s }
15
+ end
16
+
17
+ def get_account_by_key(external_key, context)
18
+ @accounts.find { |account| account.external_key == external_key.to_s }
15
19
  end
16
20
  end
17
21
 
18
22
  describe Killbill::Litle::PaymentPlugin do
19
23
  before(:each) do
20
- @call_context = Killbill::Plugin::Model::CallContext.new(SecureRandom.uuid,
21
- 'token',
22
- 'rspec tester',
23
- 'TEST',
24
- 'user',
25
- 'testing',
26
- 'this is from a test',
27
- Time.now,
28
- Time.now)
29
-
30
24
  @plugin = Killbill::Litle::PaymentPlugin.new
31
- kb_apis = KillbillApiWithFakeGetAccountById.new(nil)
32
- @plugin.kb_apis = kb_apis
25
+
26
+ @account_api = FakeJavaUserAccountApi.new
27
+ svcs = {:account_user_api => @account_api}
28
+ @plugin.kb_apis = Killbill::Plugin::KillbillApi.new('litle', svcs)
29
+
33
30
  @plugin.logger = Logger.new(STDOUT)
34
31
  @plugin.conf_dir = File.expand_path(File.dirname(__FILE__) + '../../../')
35
32
  @plugin.start_plugin
@@ -39,49 +36,49 @@ describe Killbill::Litle::PaymentPlugin do
39
36
  @plugin.stop_plugin
40
37
  end
41
38
 
42
- it "should be able to create and retrieve payment methods" do
39
+ it 'should be able to create and retrieve payment methods' do
43
40
  pm = create_payment_method
44
41
 
45
- pms = @plugin.get_payment_methods(pm.kb_account_id, false, @call_context)
42
+ pms = @plugin.get_payment_methods(pm.kb_account_id)
46
43
  pms.size.should == 1
47
44
  pms[0].external_payment_method_id.should == pm.litle_token
48
45
 
49
- pm_details = @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id, @call_context)
46
+ pm_details = @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id)
50
47
  pm_details.external_payment_method_id.should == pm.litle_token
51
48
 
52
- @plugin.delete_payment_method(pm.kb_account_id, pm.kb_payment_method_id, @call_context)
49
+ @plugin.delete_payment_method(pm.kb_account_id, pm.kb_payment_method_id)
53
50
 
54
- @plugin.get_payment_methods(pm.kb_account_id, false, @call_context).size.should == 0
55
- lambda { @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id, @call_context) }.should raise_error RuntimeError
51
+ @plugin.get_payment_methods(pm.kb_account_id).size.should == 0
52
+ lambda { @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id) }.should raise_error RuntimeError
56
53
  end
57
54
 
58
- it "should be able to charge and refund" do
55
+ it 'should be able to charge and refund' do
59
56
  pm = create_payment_method
60
57
  amount_in_cents = 10000
61
58
  currency = 'USD'
62
59
  kb_payment_id = SecureRandom.uuid
63
60
 
64
- payment_response = @plugin.process_payment pm.kb_account_id, kb_payment_id, pm.kb_payment_method_id, amount_in_cents, currency, @call_context
61
+ payment_response = @plugin.process_payment pm.kb_account_id, kb_payment_id, pm.kb_payment_method_id, amount_in_cents, currency
65
62
  payment_response.amount.should == amount_in_cents
66
- payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
63
+ payment_response.status.should == :PROCESSED
67
64
 
68
65
  # Verify our table directly
69
66
  response = Killbill::Litle::LitleResponse.find_by_api_call_and_kb_payment_id :charge, kb_payment_id
70
67
  response.test.should be_true
71
68
  response.success.should be_true
72
- response.message.should == "Approved"
69
+ response.message.should == 'Approved'
73
70
  response.params_litleonelineresponse_saleresponse_order_id.should == Killbill::Litle::Utils.compact_uuid(kb_payment_id)
74
71
 
75
- payment_response = @plugin.get_payment_info pm.kb_account_id, kb_payment_id, @call_context
72
+ payment_response = @plugin.get_payment_info pm.kb_account_id, kb_payment_id
76
73
  payment_response.amount.should == amount_in_cents
77
- payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
74
+ payment_response.status.should == :PROCESSED
78
75
 
79
76
  # Check we cannot refund an amount greater than the original charge
80
- lambda { @plugin.process_refund pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency, @call_context }.should raise_error RuntimeError
77
+ lambda { @plugin.process_refund pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency }.should raise_error RuntimeError
81
78
 
82
- refund_response = @plugin.process_refund pm.kb_account_id, kb_payment_id, amount_in_cents, currency, @call_context
79
+ refund_response = @plugin.process_refund pm.kb_account_id, kb_payment_id, amount_in_cents, currency
83
80
  refund_response.amount.should == amount_in_cents
84
- refund_response.status.should == Killbill::Plugin::Model::RefundPluginStatus.new(:PROCESSED)
81
+ refund_response.status.should == :PROCESSED
85
82
 
86
83
  # Verify our table directly
87
84
  response = Killbill::Litle::LitleResponse.find_by_api_call_and_kb_payment_id :refund, kb_payment_id
@@ -89,18 +86,18 @@ describe Killbill::Litle::PaymentPlugin do
89
86
  response.success.should be_true
90
87
 
91
88
  # Check we can retrieve the refund
92
- refund_response = @plugin.get_refund_info pm.kb_account_id, kb_payment_id, @call_context
89
+ refund_response = @plugin.get_refund_info pm.kb_account_id, kb_payment_id
93
90
  # Apparently, Litle returns positive amounts for refunds
94
91
  refund_response.amount.should == amount_in_cents
95
- refund_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
92
+ refund_response.status.should == :PROCESSED
96
93
 
97
94
  # Make sure we can charge again the same payment method
98
95
  second_amount_in_cents = 29471
99
96
  second_kb_payment_id = SecureRandom.uuid
100
97
 
101
- payment_response = @plugin.process_payment pm.kb_account_id, second_kb_payment_id, pm.kb_payment_method_id, second_amount_in_cents, currency, @call_context
98
+ payment_response = @plugin.process_payment pm.kb_account_id, second_kb_payment_id, pm.kb_payment_method_id, second_amount_in_cents, currency
102
99
  payment_response.amount.should == second_amount_in_cents
103
- payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
100
+ payment_response.status.should == :PROCESSED
104
101
  end
105
102
 
106
103
  private
@@ -109,6 +106,9 @@ describe Killbill::Litle::PaymentPlugin do
109
106
  kb_account_id = SecureRandom.uuid
110
107
  kb_payment_method_id = SecureRandom.uuid
111
108
 
109
+ # Create a new account
110
+ create_kb_account kb_account_id
111
+
112
112
  # Generate a token in Litle
113
113
  paypage_registration_id = '123456789012345678901324567890abcdefghi'
114
114
  cc_first_name = 'John'
@@ -125,22 +125,23 @@ describe Killbill::Litle::PaymentPlugin do
125
125
  country = 'IFP'
126
126
 
127
127
  properties = []
128
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'paypageRegistrationId', paypage_registration_id)
129
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'ccFirstName', cc_first_name)
130
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'ccLastName', cc_last_name)
131
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'ccType', cc_type)
132
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'ccExpMonth', cc_exp_month)
133
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'ccExpYear', cc_exp_year)
134
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'ccLast4', cc_last_4)
135
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'address1', address1)
136
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'address2', address2)
137
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'city', city)
138
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'state', state)
139
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'zip', zip)
140
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'country', country)
141
-
142
- info = Killbill::Plugin::Model::PaymentMethodPlugin.new nil, nil, properties, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
143
- payment_method = @plugin.add_payment_method(kb_account_id, kb_payment_method_id, info, true, @call_context)
128
+ properties << create_pm_kv_info('paypageRegistrationId', paypage_registration_id)
129
+ properties << create_pm_kv_info('ccFirstName', cc_first_name)
130
+ properties << create_pm_kv_info('ccLastName', cc_last_name)
131
+ properties << create_pm_kv_info('ccType', cc_type)
132
+ properties << create_pm_kv_info('ccExpMonth', cc_exp_month)
133
+ properties << create_pm_kv_info('ccExpYear', cc_exp_year)
134
+ properties << create_pm_kv_info('ccLast4', cc_last_4)
135
+ properties << create_pm_kv_info('address1', address1)
136
+ properties << create_pm_kv_info('address2', address2)
137
+ properties << create_pm_kv_info('city', city)
138
+ properties << create_pm_kv_info('state', state)
139
+ properties << create_pm_kv_info('zip', zip)
140
+ properties << create_pm_kv_info('country', country)
141
+
142
+ info = Killbill::Plugin::Model::PaymentMethodPlugin.new
143
+ info.properties = properties
144
+ payment_method = @plugin.add_payment_method(kb_account_id, kb_payment_method_id, info, true)
144
145
 
145
146
  pm = Killbill::Litle::LitlePaymentMethod.from_kb_payment_method_id kb_payment_method_id
146
147
  pm.should == payment_method
@@ -162,4 +163,27 @@ describe Killbill::Litle::PaymentPlugin do
162
163
 
163
164
  pm
164
165
  end
166
+
167
+ def create_kb_account(kb_account_id)
168
+ external_key = Time.now.to_i.to_s + '-test'
169
+ email = external_key + '@tester.com'
170
+
171
+ account = Killbill::Plugin::Model::Account.new
172
+ account.id = kb_account_id
173
+ account.external_key = external_key
174
+ account.email = email
175
+ account.name = 'Integration spec'
176
+ account.currency = :USD
177
+
178
+ @account_api.accounts << account
179
+
180
+ return external_key, kb_account_id
181
+ end
182
+
183
+ def create_pm_kv_info(key, value)
184
+ prop = Killbill::Plugin::Model::PaymentMethodKVInfo.new
185
+ prop.key = key
186
+ prop.value = value
187
+ prop
188
+ end
165
189
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-litle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-14 00:00:00.000000000 Z
12
+ date: 2013-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: killbill
@@ -17,13 +17,13 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.19
20
+ version: 1.1.2
21
21
  none: false
22
22
  requirement: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.19
26
+ version: 1.1.2
27
27
  none: false
28
28
  prerelease: false
29
29
  type: :runtime
@@ -213,6 +213,7 @@ files:
213
213
  - ".travis.yml"
214
214
  - Gemfile
215
215
  - Jarfile
216
+ - NEWS
216
217
  - README.md
217
218
  - Rakefile
218
219
  - VERSION