killbill-litle 1.9.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Jarfile +5 -4
- data/NEWS +3 -0
- data/VERSION +1 -1
- data/db/ddl.sql +1 -0
- data/db/schema.rb +1 -0
- data/killbill-litle.gemspec +1 -1
- data/lib/litle/api.rb +37 -8
- data/lib/litle/config/configuration.rb +9 -0
- data/lib/litle/models/litle_transaction.rb +1 -1
- data/pom.xml +1 -1
- data/spec/litle/currency_conversion_spec.rb +21 -0
- metadata +38 -35
data/Jarfile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
jar 'com.ning.billing:killbill-api', '0.7.
|
2
|
-
jar 'com.ning.billing.plugin:killbill-plugin-api-notification', '0.
|
3
|
-
jar 'com.ning.billing.plugin:killbill-plugin-api-payment', '0.
|
4
|
-
jar 'com.ning.billing:killbill-
|
1
|
+
jar 'com.ning.billing:killbill-api', '0.7.4'
|
2
|
+
jar 'com.ning.billing.plugin:killbill-plugin-api-notification', '0.6.1'
|
3
|
+
jar 'com.ning.billing.plugin:killbill-plugin-api-payment', '0.6.1'
|
4
|
+
jar 'com.ning.billing.plugin:killbill-plugin-api-currency', '0.6.1'
|
5
|
+
jar 'com.ning.billing:killbill-util:tests', '0.7.1'
|
5
6
|
jar 'javax.servlet:javax.servlet-api', '3.0.1'
|
data/NEWS
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.
|
1
|
+
1.9.2
|
data/db/ddl.sql
CHANGED
@@ -30,6 +30,7 @@ CREATE TABLE `litle_transactions` (
|
|
30
30
|
`kb_payment_id` varchar(255) NOT NULL,
|
31
31
|
`litle_txn_id` varchar(255) NOT NULL,
|
32
32
|
`amount_in_cents` int(11) NOT NULL,
|
33
|
+
`currency` char(3) NOT NULL,
|
33
34
|
`created_at` datetime NOT NULL,
|
34
35
|
`updated_at` datetime NOT NULL,
|
35
36
|
PRIMARY KEY (`id`),
|
data/db/schema.rb
CHANGED
@@ -31,6 +31,7 @@ ActiveRecord::Schema.define(:version => 20130311153635) do
|
|
31
31
|
t.string "kb_payment_id", :null => false
|
32
32
|
t.string "litle_txn_id", :null => false
|
33
33
|
t.integer "amount_in_cents", :null => false
|
34
|
+
t.string "currency", :null => false
|
34
35
|
t.datetime "created_at", :null => false
|
35
36
|
t.datetime "updated_at", :null => false
|
36
37
|
end
|
data/killbill-litle.gemspec
CHANGED
@@ -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.
|
25
|
+
s.add_dependency 'killbill', '~> 1.8.3'
|
26
26
|
s.add_dependency 'activemerchant', '~> 1.36.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
@@ -33,14 +33,18 @@ module Killbill::Litle
|
|
33
33
|
# Retrieve the Litle payment method
|
34
34
|
litle_pm = LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id)
|
35
35
|
|
36
|
+
# Check for currency conversion
|
37
|
+
converted = convert_amount_currency_if_required(amount_in_cents, currency)
|
38
|
+
|
36
39
|
# Go to Litle
|
37
|
-
gateway = Killbill::Litle.gateway_for_currency(
|
38
|
-
litle_response = gateway.purchase
|
39
|
-
response = save_response_and_transaction litle_response, :charge, kb_payment_id,
|
40
|
+
gateway = Killbill::Litle.gateway_for_currency(converted[1])
|
41
|
+
litle_response = gateway.purchase converted[0], litle_pm.to_litle_card_token, options
|
42
|
+
response = save_response_and_transaction litle_response, :charge, kb_payment_id, converted[0], converted[1]
|
40
43
|
|
41
44
|
response.to_payment_response
|
42
45
|
end
|
43
46
|
|
47
|
+
|
44
48
|
def get_payment_info(kb_account_id, kb_payment_id, tenant_context = nil, options = {})
|
45
49
|
# We assume the payment is immutable in Litle and only look at our tables since there
|
46
50
|
# doesn't seem to be a Litle API to fetch details for a given transaction.
|
@@ -58,11 +62,13 @@ module Killbill::Litle
|
|
58
62
|
# Set a default report group
|
59
63
|
options[:merchant] ||= report_group_for_currency(currency)
|
60
64
|
|
61
|
-
#
|
62
|
-
|
63
|
-
litle_response = gateway.credit amount_in_cents, litle_transaction.litle_txn_id, options
|
64
|
-
response = save_response_and_transaction litle_response, :refund, kb_payment_id, amount_in_cents
|
65
|
+
# Check for currency conversion
|
66
|
+
converted = convert_amount_currency_if_required(amount_in_cents, currency)
|
65
67
|
|
68
|
+
# Go to Litle
|
69
|
+
gateway = Killbill::Litle.gateway_for_currency(converted[1])
|
70
|
+
litle_response = gateway.credit converted[0], litle_transaction.litle_txn_id, options
|
71
|
+
response = save_response_and_transaction litle_response, :refund, kb_payment_id, converted[0], converted[1]
|
66
72
|
response.to_refund_response
|
67
73
|
end
|
68
74
|
|
@@ -165,6 +171,28 @@ module Killbill::Litle
|
|
165
171
|
|
166
172
|
private
|
167
173
|
|
174
|
+
def convert_amount_currency_if_required(input_amount, input_currency, currency_conversion_date)
|
175
|
+
|
176
|
+
converted_currency = Killbill::Litle.converted_currency(input_currency)
|
177
|
+
return [input_amount, input_currency] if converted_currency.nil?
|
178
|
+
|
179
|
+
currency_conversion = @kb_apis.currency_conversion_api.get_currency_conversion(input_currency, currency_conversion_date)
|
180
|
+
rates = currency_conversion.rates
|
181
|
+
found = rates.select do |r|
|
182
|
+
r.currency.to_s.upcase.to_sym == converted_currency.to_s.upcase.to_sym
|
183
|
+
end
|
184
|
+
|
185
|
+
if found.nil? || found.empty?
|
186
|
+
@logger.warn "Failed to find converted currency #{converted_currency} for input currency #{input_currency}"
|
187
|
+
return [input_amount, input_currency] if converted_currency.nil?
|
188
|
+
end
|
189
|
+
|
190
|
+
# conversion rounding ?
|
191
|
+
conversion_rate = found[0].value
|
192
|
+
output_amount = input_amount * conversion_rate
|
193
|
+
return [output_amount.to_i, converted_currency]
|
194
|
+
end
|
195
|
+
|
168
196
|
def find_value_from_payment_method_props(payment_method_props, key)
|
169
197
|
prop = (payment_method_props.properties.find { |kv| kv.key == key })
|
170
198
|
prop.nil? ? nil : prop.value
|
@@ -186,7 +214,7 @@ module Killbill::Litle
|
|
186
214
|
"Report Group for #{currency.to_s}"
|
187
215
|
end
|
188
216
|
|
189
|
-
def save_response_and_transaction(litle_response, api_call, kb_payment_id=nil, amount_in_cents=0)
|
217
|
+
def save_response_and_transaction(litle_response, api_call, kb_payment_id=nil, amount_in_cents=0, currency=nil)
|
190
218
|
@logger.warn "Unsuccessful #{api_call}: #{litle_response.message}" unless litle_response.success?
|
191
219
|
|
192
220
|
# Save the response to our logs
|
@@ -196,6 +224,7 @@ module Killbill::Litle
|
|
196
224
|
if response.success and !kb_payment_id.blank? and !response.litle_txn_id.blank?
|
197
225
|
# Record the transaction
|
198
226
|
transaction = response.create_litle_transaction!(:amount_in_cents => amount_in_cents,
|
227
|
+
:currency => currency,
|
199
228
|
:api_call => api_call,
|
200
229
|
:kb_payment_id => kb_payment_id,
|
201
230
|
:litle_txn_id => response.litle_txn_id)
|
@@ -4,6 +4,7 @@ module Killbill::Litle
|
|
4
4
|
mattr_reader :logger
|
5
5
|
mattr_reader :config
|
6
6
|
mattr_reader :gateways
|
7
|
+
mattr_reader :currency_conversions
|
7
8
|
mattr_reader :kb_apis
|
8
9
|
mattr_reader :initialized
|
9
10
|
mattr_reader :test
|
@@ -21,6 +22,8 @@ module Killbill::Litle
|
|
21
22
|
|
22
23
|
@@gateways = Killbill::Litle::Gateway.from_config(@@config[:litle])
|
23
24
|
|
25
|
+
@@currency_conversions = @@config[:currency_conversions]
|
26
|
+
|
24
27
|
if defined?(JRUBY_VERSION)
|
25
28
|
# See https://github.com/jruby/activerecord-jdbc-adapter/issues/302
|
26
29
|
require 'jdbc/mysql'
|
@@ -33,6 +36,12 @@ module Killbill::Litle
|
|
33
36
|
@@initialized = true
|
34
37
|
end
|
35
38
|
|
39
|
+
def self.converted_currency(currency)
|
40
|
+
currency_sym = currency.to_s.upcase.to_sym
|
41
|
+
@@currency_conversions && @@currency_conversions[currency_sym]
|
42
|
+
end
|
43
|
+
|
44
|
+
|
36
45
|
def self.gateway_for_currency(currency)
|
37
46
|
currency_sym = currency.to_s.upcase.to_sym
|
38
47
|
gateway = @@gateways[currency_sym]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Killbill::Litle
|
2
2
|
class LitleTransaction < ActiveRecord::Base
|
3
3
|
belongs_to :litle_response
|
4
|
-
attr_accessible :amount_in_cents, :api_call, :kb_payment_id, :litle_txn_id
|
4
|
+
attr_accessible :amount_in_cents, :currency, :api_call, :kb_payment_id, :litle_txn_id
|
5
5
|
|
6
6
|
def self.from_kb_payment_id(kb_payment_id)
|
7
7
|
single_transaction_from_kb_payment_id :charge, kb_payment_id
|
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.9.
|
28
|
+
<version>1.9.2</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>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Killbill::Litle do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
Killbill::Litle.initialize!
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should not make currency conversion' do
|
10
|
+
Killbill::Litle.converted_currency(:USD).should be_false
|
11
|
+
Killbill::Litle.converted_currency('usd').should be_false
|
12
|
+
Killbill::Litle.converted_currency('USD').should be_false
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should make currency conversion' do
|
16
|
+
Killbill::Litle.converted_currency(:BRL).should == 'USD'
|
17
|
+
Killbill::Litle.converted_currency('brl').should == 'USD'
|
18
|
+
Killbill::Litle.converted_currency('BRL').should == 'USD'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-litle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.1
|
5
4
|
prerelease:
|
5
|
+
version: 1.9.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kill Bill core team
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: killbill
|
16
16
|
version_requirements: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.
|
20
|
+
version: 1.8.3
|
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.
|
26
|
+
version: 1.8.3
|
27
27
|
none: false
|
28
28
|
prerelease: false
|
29
29
|
type: :runtime
|
@@ -31,13 +31,13 @@ dependencies:
|
|
31
31
|
name: activemerchant
|
32
32
|
version_requirements: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- - ~>
|
34
|
+
- - "~>"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 1.36.0
|
37
37
|
none: false
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - ~>
|
40
|
+
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.36.0
|
43
43
|
none: false
|
@@ -47,13 +47,13 @@ dependencies:
|
|
47
47
|
name: activerecord
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
|
-
- - ~>
|
50
|
+
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 3.2.1
|
53
53
|
none: false
|
54
54
|
requirement: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
|
-
- - ~>
|
56
|
+
- - "~>"
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: 3.2.1
|
59
59
|
none: false
|
@@ -63,13 +63,13 @@ dependencies:
|
|
63
63
|
name: sinatra
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.3.4
|
69
69
|
none: false
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - ~>
|
72
|
+
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 1.3.4
|
75
75
|
none: false
|
@@ -79,13 +79,13 @@ dependencies:
|
|
79
79
|
name: LitleOnline
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- - ~>
|
82
|
+
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: 8.16.0
|
85
85
|
none: false
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - ~>
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 8.16.0
|
91
91
|
none: false
|
@@ -95,13 +95,13 @@ dependencies:
|
|
95
95
|
name: xml-mapping
|
96
96
|
version_requirements: !ruby/object:Gem::Requirement
|
97
97
|
requirements:
|
98
|
-
- - ~>
|
98
|
+
- - "~>"
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: 0.9.1
|
101
101
|
none: false
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- - ~>
|
104
|
+
- - "~>"
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: 0.9.1
|
107
107
|
none: false
|
@@ -111,13 +111,13 @@ dependencies:
|
|
111
111
|
name: xml-object
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- - ~>
|
114
|
+
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: 0.9.93
|
117
117
|
none: false
|
118
118
|
requirement: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
|
-
- - ~>
|
120
|
+
- - "~>"
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: 0.9.93
|
123
123
|
none: false
|
@@ -127,13 +127,13 @@ dependencies:
|
|
127
127
|
name: activerecord-jdbcmysql-adapter
|
128
128
|
version_requirements: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
|
-
- - ~>
|
130
|
+
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: 1.2.9
|
133
133
|
none: false
|
134
134
|
requirement: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - ~>
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 1.2.9
|
139
139
|
none: false
|
@@ -143,13 +143,13 @@ dependencies:
|
|
143
143
|
name: jbundler
|
144
144
|
version_requirements: !ruby/object:Gem::Requirement
|
145
145
|
requirements:
|
146
|
-
- - ~>
|
146
|
+
- - "~>"
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: 0.4.1
|
149
149
|
none: false
|
150
150
|
requirement: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- - ~>
|
152
|
+
- - "~>"
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: 0.4.1
|
155
155
|
none: false
|
@@ -159,13 +159,13 @@ dependencies:
|
|
159
159
|
name: rake
|
160
160
|
version_requirements: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
|
-
- -
|
162
|
+
- - ">="
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: 10.0.0
|
165
165
|
none: false
|
166
166
|
requirement: !ruby/object:Gem::Requirement
|
167
167
|
requirements:
|
168
|
-
- -
|
168
|
+
- - ">="
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: 10.0.0
|
171
171
|
none: false
|
@@ -175,13 +175,13 @@ dependencies:
|
|
175
175
|
name: rspec
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - ~>
|
178
|
+
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 2.12.0
|
181
181
|
none: false
|
182
182
|
requirement: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
|
-
- - ~>
|
184
|
+
- - "~>"
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: 2.12.0
|
187
187
|
none: false
|
@@ -191,13 +191,13 @@ dependencies:
|
|
191
191
|
name: activerecord-jdbcsqlite3-adapter
|
192
192
|
version_requirements: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
|
-
- - ~>
|
194
|
+
- - "~>"
|
195
195
|
- !ruby/object:Gem::Version
|
196
196
|
version: 1.2.6
|
197
197
|
none: false
|
198
198
|
requirement: !ruby/object:Gem::Requirement
|
199
199
|
requirements:
|
200
|
-
- - ~>
|
200
|
+
- - "~>"
|
201
201
|
- !ruby/object:Gem::Version
|
202
202
|
version: 1.2.6
|
203
203
|
none: false
|
@@ -209,8 +209,8 @@ executables: []
|
|
209
209
|
extensions: []
|
210
210
|
extra_rdoc_files: []
|
211
211
|
files:
|
212
|
-
- .gitignore
|
213
|
-
- .travis.yml
|
212
|
+
- ".gitignore"
|
213
|
+
- ".travis.yml"
|
214
214
|
- Gemfile
|
215
215
|
- Jarfile
|
216
216
|
- NEWS
|
@@ -237,6 +237,7 @@ files:
|
|
237
237
|
- pom.xml
|
238
238
|
- release.sh
|
239
239
|
- spec/litle/base_plugin_spec.rb
|
240
|
+
- spec/litle/currency_conversion_spec.rb
|
240
241
|
- spec/litle/litle_payment_method_spec.rb
|
241
242
|
- spec/litle/remote/integration_spec.rb
|
242
243
|
- spec/litle/utils_spec.rb
|
@@ -246,24 +247,25 @@ licenses:
|
|
246
247
|
- Apache License (2.0)
|
247
248
|
post_install_message:
|
248
249
|
rdoc_options:
|
249
|
-
- --exclude
|
250
|
-
- .
|
250
|
+
- "--exclude"
|
251
|
+
- "."
|
251
252
|
require_paths:
|
252
253
|
- lib
|
253
254
|
required_ruby_version: !ruby/object:Gem::Requirement
|
254
255
|
requirements:
|
255
|
-
- -
|
256
|
+
- - ">="
|
256
257
|
- !ruby/object:Gem::Version
|
257
258
|
version: 1.9.3
|
258
259
|
none: false
|
259
260
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
260
261
|
requirements:
|
261
|
-
- -
|
262
|
+
- - ">="
|
262
263
|
- !ruby/object:Gem::Version
|
263
264
|
segments:
|
264
265
|
- 0
|
265
|
-
version: '0'
|
266
266
|
hash: 2
|
267
|
+
version: !binary |-
|
268
|
+
MA==
|
267
269
|
none: false
|
268
270
|
requirements: []
|
269
271
|
rubyforge_project:
|
@@ -273,6 +275,7 @@ specification_version: 3
|
|
273
275
|
summary: Plugin to use Litle & Co. as a gateway.
|
274
276
|
test_files:
|
275
277
|
- spec/litle/base_plugin_spec.rb
|
278
|
+
- spec/litle/currency_conversion_spec.rb
|
276
279
|
- spec/litle/litle_payment_method_spec.rb
|
277
280
|
- spec/litle/remote/integration_spec.rb
|
278
281
|
- spec/litle/utils_spec.rb
|