killbill-client 0.30.0 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/killbill_client.gemspec +2 -2
- data/lib/killbill_client/api/net_http_adapter.rb +25 -23
- data/lib/killbill_client/models/combo_transaction.rb +8 -8
- data/lib/killbill_client/models/resource.rb +3 -1
- data/lib/killbill_client/models/transaction.rb +5 -0
- data/lib/killbill_client/version.rb +1 -1
- data/spec/killbill_client/base_uri_spec.rb +6 -6
- data/spec/killbill_client/encoding_spec.rb +53 -0
- data/spec/killbill_client/model_relation_spec.rb +26 -26
- data/spec/killbill_client/remote/api_spec.rb +2 -2
- data/spec/killbill_client/remote/model_spec.rb +93 -93
- data/spec/killbill_client/resource_spec.rb +61 -4
- data/spec/killbill_client/resources_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1557b30b93a8605ae8e3d36179b24a93b439c839
|
4
|
+
data.tar.gz: 267910459ce59518aab8abba5b9f62cb1ed773f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86c73b8dadf31bb8d0e96fb40e1157ad8971392dd63c3d15d697f7eeef84a29b0497c8ab897f065f181ed38fa1a041f2851156adecdea6c9c763f05981033720
|
7
|
+
data.tar.gz: c4eaaa21e76392bab84bfd341aa7b5d8761fa1cfabf86a604da08e4cc8fccc311cb8affa0faf9cd5b318f4a5b7428ea545c49b68b731a0c7a0b3a0db7ccaf733
|
data/killbill_client.gemspec
CHANGED
@@ -41,6 +41,6 @@ Gem::Specification.new do |s|
|
|
41
41
|
|
42
42
|
s.add_dependency 'json', '>= 1.2.0'
|
43
43
|
|
44
|
-
s.add_development_dependency 'rake', '>= 10.0.0'
|
45
|
-
s.add_development_dependency 'rspec', '~>
|
44
|
+
s.add_development_dependency 'rake', '>= 10.0.0', '< 11.0.0'
|
45
|
+
s.add_development_dependency 'rspec', '~> 3.4'
|
46
46
|
end
|
@@ -35,6 +35,30 @@ module KillBillClient
|
|
35
35
|
:delete => ::Net::HTTP::Delete
|
36
36
|
}
|
37
37
|
|
38
|
+
def encode_params(options = {})
|
39
|
+
# Plugin properties are passed in the options but we want to send them as query parameters,
|
40
|
+
# so remove with from global hash and insert them under :params
|
41
|
+
plugin_properties = options.delete :pluginProperty
|
42
|
+
if plugin_properties && plugin_properties.size > 0
|
43
|
+
options[:params][:pluginProperty] = plugin_properties.map { |p| "#{CGI.escape p.key}=#{CGI.escape p.value}" }
|
44
|
+
end
|
45
|
+
return nil unless (options[:params] && !options[:params].empty?)
|
46
|
+
|
47
|
+
pairs = options[:params].map { |key, value|
|
48
|
+
# If the value is an array, we 'demultiplex' into several
|
49
|
+
if value.is_a? Array
|
50
|
+
internal_pairs = value.map do |simple_value|
|
51
|
+
"#{CGI.escape key.to_s}=#{CGI.escape simple_value.to_s}"
|
52
|
+
end
|
53
|
+
internal_pairs
|
54
|
+
else
|
55
|
+
"#{CGI.escape key.to_s}=#{CGI.escape value.to_s}"
|
56
|
+
end
|
57
|
+
}
|
58
|
+
pairs.flatten!
|
59
|
+
"?#{pairs.join '&'}"
|
60
|
+
end
|
61
|
+
|
38
62
|
def request(method, relative_uri, options = {})
|
39
63
|
head = headers.dup
|
40
64
|
head.update options[:head] if options[:head]
|
@@ -45,29 +69,7 @@ module KillBillClient
|
|
45
69
|
# See https://github.com/killbill/killbill/issues/221#issuecomment-151980263
|
46
70
|
base_path = uri.request_uri == '/' ? '' : uri.request_uri
|
47
71
|
uri += (base_path + URI.escape(relative_uri))
|
48
|
-
|
49
|
-
# Plugin properties are passed in the options but we want to send them as query parameters,
|
50
|
-
# so remove with from global hash and insert them under :params
|
51
|
-
plugin_properties = options.delete :pluginProperty
|
52
|
-
if plugin_properties && plugin_properties.size > 0
|
53
|
-
options[:params][:pluginProperty] = plugin_properties.map { |p| "#{p.key}=#{p.value}" }
|
54
|
-
end
|
55
|
-
|
56
|
-
if options[:params] && !options[:params].empty?
|
57
|
-
pairs = options[:params].map { |key, value|
|
58
|
-
# If the value is an array, we 'demultiplex' into several
|
59
|
-
if value.is_a? Array
|
60
|
-
internal_pairs = value.map do |simple_value|
|
61
|
-
"#{CGI.escape key.to_s}=#{CGI.escape simple_value.to_s}"
|
62
|
-
end
|
63
|
-
internal_pairs
|
64
|
-
else
|
65
|
-
"#{CGI.escape key.to_s}=#{CGI.escape value.to_s}"
|
66
|
-
end
|
67
|
-
}
|
68
|
-
pairs.flatten!
|
69
|
-
uri += "?#{pairs.join '&'}"
|
70
|
-
end
|
72
|
+
uri += encode_params(options).to_s
|
71
73
|
request = METHODS[method].new uri.request_uri, head
|
72
74
|
|
73
75
|
# Configure multi-tenancy headers, if enabled
|
@@ -2,27 +2,27 @@ module KillBillClient
|
|
2
2
|
module Model
|
3
3
|
class ComboTransaction < ComboPaymentTransactionAttributes
|
4
4
|
|
5
|
-
def auth(user = nil, reason = nil, comment = nil, options = {})
|
5
|
+
def auth(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
|
6
6
|
@transaction.transaction_type = 'AUTHORIZE'
|
7
7
|
|
8
|
-
combo_payment(user, reason, comment, options)
|
8
|
+
combo_payment(user, reason, comment, options, refresh_options)
|
9
9
|
end
|
10
10
|
|
11
|
-
def purchase(user = nil, reason = nil, comment = nil, options = {})
|
11
|
+
def purchase(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
|
12
12
|
@transaction.transaction_type = 'PURCHASE'
|
13
13
|
|
14
|
-
combo_payment(user, reason, comment, options)
|
14
|
+
combo_payment(user, reason, comment, options, refresh_options)
|
15
15
|
end
|
16
16
|
|
17
|
-
def credit(user = nil, reason = nil, comment = nil, options = {})
|
17
|
+
def credit(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
|
18
18
|
@transaction.transaction_type = 'CREDIT'
|
19
19
|
|
20
|
-
combo_payment(user, reason, comment, options)
|
20
|
+
combo_payment(user, reason, comment, options, refresh_options)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def combo_payment(user, reason, comment, options)
|
25
|
+
def combo_payment(user, reason, comment, options, refresh_options = nil)
|
26
26
|
query_map = {
|
27
27
|
}
|
28
28
|
if options.include? :controlPluginNames
|
@@ -37,7 +37,7 @@ module KillBillClient
|
|
37
37
|
:reason => reason,
|
38
38
|
:comment => comment,
|
39
39
|
}.merge(options)
|
40
|
-
created_transaction.refresh(options, Payment)
|
40
|
+
created_transaction.refresh(refresh_options || options, Payment)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -26,7 +26,9 @@ module KillBillClient
|
|
26
26
|
class << self
|
27
27
|
|
28
28
|
def require_multi_tenant_options!(options, msg)
|
29
|
-
|
29
|
+
api_key = options[:api_key] || KillBillClient.api_key
|
30
|
+
api_secret = options[:api_secret] || KillBillClient.api_secret
|
31
|
+
if api_key.nil? || api_secret.nil?
|
30
32
|
raise ArgumentError, msg
|
31
33
|
end
|
32
34
|
end
|
@@ -2,6 +2,7 @@ module KillBillClient
|
|
2
2
|
module Model
|
3
3
|
class Transaction < PaymentTransactionAttributes
|
4
4
|
|
5
|
+
has_many :properties, KillBillClient::Model::PluginPropertyAttributes
|
5
6
|
has_many :audit_logs, KillBillClient::Model::AuditLog
|
6
7
|
|
7
8
|
def auth(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
|
@@ -40,6 +41,10 @@ module KillBillClient
|
|
40
41
|
create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/payments", query_map, payment_method_id, user, reason, comment, options)
|
41
42
|
end
|
42
43
|
|
44
|
+
def complete(user = nil, reason = nil, comment = nil, options = {})
|
45
|
+
complete_initial_transaction(user, reason, comment, options)
|
46
|
+
end
|
47
|
+
|
43
48
|
def complete_auth(user = nil, reason = nil, comment = nil, options = {})
|
44
49
|
@transaction_type = 'AUTHORIZE'
|
45
50
|
complete_initial_transaction(user, reason, comment, options)
|
@@ -4,15 +4,15 @@ describe KillBillClient do
|
|
4
4
|
|
5
5
|
it 'should be able to parse a url with http' do
|
6
6
|
KillBillClient.url = "http://example.com:8080"
|
7
|
-
KillBillClient::API.base_uri.scheme.
|
8
|
-
KillBillClient::API.base_uri.host.
|
9
|
-
KillBillClient::API.base_uri.port.
|
7
|
+
expect(KillBillClient::API.base_uri.scheme).to eq("http")
|
8
|
+
expect(KillBillClient::API.base_uri.host).to eq("example.com")
|
9
|
+
expect(KillBillClient::API.base_uri.port).to eq(8080)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should be able to parse a url without http' do
|
13
13
|
KillBillClient.url = "example.com:8080"
|
14
|
-
KillBillClient::API.base_uri.scheme.
|
15
|
-
KillBillClient::API.base_uri.host.
|
16
|
-
KillBillClient::API.base_uri.port.
|
14
|
+
expect(KillBillClient::API.base_uri.scheme).to eq("http")
|
15
|
+
expect(KillBillClient::API.base_uri.host).to eq("example.com")
|
16
|
+
expect(KillBillClient::API.base_uri.port).to eq(8080)
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KillBillClient::API do
|
4
|
+
let(:expected_query_params) {
|
5
|
+
[
|
6
|
+
'controlPluginName=killbill-example-plugin',
|
7
|
+
'pluginProperty=contractId%3Dtest'
|
8
|
+
]
|
9
|
+
}
|
10
|
+
|
11
|
+
it 'should send double-encoded uri' do
|
12
|
+
contract_property = KillBillClient::Model::PluginPropertyAttributes.new
|
13
|
+
contract_property.key = 'contractId'
|
14
|
+
contract_property.value = 'test'
|
15
|
+
info_property = KillBillClient::Model::PluginPropertyAttributes.new
|
16
|
+
info_property.key = 'details'
|
17
|
+
info_property_hash = {
|
18
|
+
'eventType' => 'voidEvent',
|
19
|
+
'transactionType' => 'void'
|
20
|
+
}
|
21
|
+
info_property.value = info_property_hash.to_json
|
22
|
+
plugin_properties = [contract_property, info_property]
|
23
|
+
options = {
|
24
|
+
:params => {:controlPluginName => 'killbill-example-plugin'},
|
25
|
+
:pluginProperty => plugin_properties
|
26
|
+
}
|
27
|
+
http_adapter = DummyForHTTPAdapter.new
|
28
|
+
query_string = http_adapter.send(:encode_params, options)
|
29
|
+
expect(query_string.chars.first).to eq('?')
|
30
|
+
query_params = query_string[1..-1].split('&').sort
|
31
|
+
expect(query_params.size).to eq(3)
|
32
|
+
|
33
|
+
# check the first two query strings
|
34
|
+
expect(query_params[0..1]).to eq(expected_query_params)
|
35
|
+
|
36
|
+
# decode info_property to check if it is double encoded
|
37
|
+
info_property_query = CGI.parse(query_params[2])
|
38
|
+
expect(info_property_query.size).to eq(1)
|
39
|
+
expect(info_property_query.keys.first).to eq('pluginProperty')
|
40
|
+
expect(info_property_query['pluginProperty'].size).to eq(1)
|
41
|
+
output_info_property = info_property_query['pluginProperty'].first.split('=')
|
42
|
+
expect(output_info_property.size).to eq(2)
|
43
|
+
expect(output_info_property[0]).to eq(info_property.key)
|
44
|
+
# should match if we decode it
|
45
|
+
expect(JSON.parse CGI.unescape(output_info_property[1])).to eq(info_property_hash)
|
46
|
+
# also ensure the undecoded value is different so that it was indeed encocded twice
|
47
|
+
expect(output_info_property[1]).not_to eq(CGI.unescape output_info_property[1])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class DummyForHTTPAdapter
|
52
|
+
include KillBillClient::API::Net::HTTPAdapter
|
53
|
+
end
|
@@ -2,32 +2,32 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe KillBillClient::Model::Resource do
|
4
4
|
class_var_name = '@@attribute_names'
|
5
|
-
|
5
|
+
|
6
6
|
it 'should test has_one property' do
|
7
7
|
#test account_timeline has one account
|
8
8
|
#has_one :account, KillBillClient::Model::Account
|
9
9
|
#expected "KillBillClient::Model::AccountTimeline"=>{:account=>{:type=>KillBillClient::Model::Account, :cardinality=>:one}, :payments=>{:type=>KillBillClient::Model::Payment, :cardinality=>:many}, :bundles=>{:type=>KillBillClient::Model::Bundle, :cardinality=>:many}, :invoices=>{:type=>KillBillClient::Model::Invoice, :cardinality=>:many}}
|
10
10
|
test_var = KillBillClient::Model::AccountTimeline.class_variable_defined? class_var_name
|
11
|
-
test_var.
|
11
|
+
expect(test_var).not_to be(false)
|
12
12
|
|
13
13
|
var = KillBillClient::Model::AccountTimeline.send(:class_variable_get, class_var_name)
|
14
|
-
var.size.
|
15
|
-
var.
|
16
|
-
var["KillBillClient::Model::AccountTimeline"].
|
14
|
+
expect(var.size).to be > 0
|
15
|
+
expect(var).to have_key "KillBillClient::Model::AccountTimeline"
|
16
|
+
expect(var["KillBillClient::Model::AccountTimeline"]).to have_key :account
|
17
17
|
|
18
18
|
attr = var["KillBillClient::Model::AccountTimeline"][:account]
|
19
19
|
|
20
|
-
attr.
|
21
|
-
attr.
|
20
|
+
expect(attr).to have_key :type
|
21
|
+
expect(attr).to have_key :cardinality
|
22
22
|
|
23
|
-
attr[:type].
|
24
|
-
attr[:cardinality].
|
23
|
+
expect(attr[:type]).to eq(KillBillClient::Model::Account)
|
24
|
+
expect(attr[:cardinality]).to eq(:one) #has one
|
25
25
|
|
26
26
|
#should also be accessible by attr_accessors
|
27
27
|
|
28
28
|
methods = KillBillClient::Model::AccountTimeline.instance_methods
|
29
|
-
methods.map(&:to_sym).
|
30
|
-
methods.map(&:to_sym).
|
29
|
+
expect(methods.map(&:to_sym)).to include :account # attr_reader
|
30
|
+
expect(methods.map(&:to_sym)).to include :account= #attr_writer
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should test has_many property' do
|
@@ -36,39 +36,39 @@ describe KillBillClient::Model::Resource do
|
|
36
36
|
#expected {"KillBillClient::Model::SubscriptionEvent"=>{:audit_logs=>{:type=>KillBillClient::Model::AuditLog, :cardinality=>:many}}}
|
37
37
|
|
38
38
|
test_var = KillBillClient::Model::EventSubscription.class_variable_defined? class_var_name
|
39
|
-
test_var.
|
39
|
+
expect(test_var).to be(true)
|
40
40
|
|
41
41
|
var = KillBillClient::Model::EventSubscription.send(:class_variable_get, class_var_name)
|
42
|
-
var.size.
|
43
|
-
var.
|
44
|
-
var["KillBillClient::Model::Subscription"].
|
42
|
+
expect(var.size).to be > 0
|
43
|
+
expect(var).to have_key "KillBillClient::Model::Subscription"
|
44
|
+
expect(var["KillBillClient::Model::Subscription"]).to have_key :events
|
45
45
|
|
46
46
|
attr = var["KillBillClient::Model::Subscription"][:events]
|
47
47
|
|
48
|
-
attr.
|
49
|
-
attr.
|
48
|
+
expect(attr).to have_key :type
|
49
|
+
expect(attr).to have_key :cardinality
|
50
50
|
|
51
|
-
attr[:type].
|
52
|
-
attr[:cardinality].
|
51
|
+
expect(attr[:type]).to eq(KillBillClient::Model::EventSubscription)
|
52
|
+
expect(attr[:cardinality]).to eq(:many) #has many
|
53
53
|
|
54
54
|
#should also be accessible by attr_accessors
|
55
55
|
|
56
56
|
methods = KillBillClient::Model::EventSubscription.instance_methods
|
57
|
-
methods.map(&:to_sym).
|
58
|
-
methods.map(&:to_sym).
|
57
|
+
expect(methods.map(&:to_sym)).to include :audit_logs # attr_reader
|
58
|
+
expect(methods.map(&:to_sym)).to include :audit_logs= #attr_writer
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should create alias attr accessors' do
|
62
62
|
KillBillClient::Model::EventSubscription.create_alias :alias_date, :requested_dt
|
63
63
|
|
64
64
|
methods = KillBillClient::Model::EventSubscription.instance_methods
|
65
|
-
methods.map(&:to_sym).
|
66
|
-
methods.map(&:to_sym).
|
65
|
+
expect(methods.map(&:to_sym)).to include :alias_date
|
66
|
+
expect(methods.map(&:to_sym)).to include :alias_date=
|
67
67
|
|
68
68
|
evt = KillBillClient::Model::EventSubscription.new
|
69
69
|
evt.alias_date = "devaroop"
|
70
|
-
evt.requested_dt.
|
71
|
-
evt.alias_date.
|
70
|
+
expect(evt.requested_dt).to eq("devaroop")
|
71
|
+
expect(evt.alias_date).to eq("devaroop")
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe KillBillClient::API do
|
4
4
|
it 'should get all tag definitions', :integration => true do
|
5
5
|
response = KillBillClient::API.get '/1.0/kb/tagDefinitions'
|
6
|
-
response.code.to_i.
|
6
|
+
expect(response.code.to_i).to eq(200)
|
7
7
|
tag_definitions = KillBillClient::Model::Resource.from_response KillBillClient::Model::TagDefinition, response
|
8
|
-
tag_definitions.size.
|
8
|
+
expect(tag_definitions.size).to be > 1
|
9
9
|
end
|
10
10
|
end
|
@@ -22,73 +22,73 @@ describe KillBillClient::Model do
|
|
22
22
|
account.country = 'LalaLand'
|
23
23
|
account.locale = 'FR_fr'
|
24
24
|
account.is_notified_for_invoices = false
|
25
|
-
account.account_id.
|
25
|
+
expect(account.account_id).to be_nil
|
26
26
|
|
27
27
|
# Create and verify the account
|
28
28
|
account = account.create('KillBill Spec test')
|
29
|
-
account.external_key.
|
30
|
-
account.account_id.
|
29
|
+
expect(account.external_key).to eq(external_key)
|
30
|
+
expect(account.account_id).not_to be_nil
|
31
31
|
account_id = account.account_id
|
32
32
|
|
33
33
|
# Try to retrieve it
|
34
34
|
account = KillBillClient::Model::Account.find_by_id account.account_id
|
35
|
-
account.external_key.
|
36
|
-
account.payment_method_id.
|
35
|
+
expect(account.external_key).to eq(external_key)
|
36
|
+
expect(account.payment_method_id).to be_nil
|
37
37
|
|
38
38
|
# Try to retrieve it
|
39
39
|
account = KillBillClient::Model::Account.find_by_external_key external_key
|
40
|
-
account.account_id.
|
41
|
-
account.payment_method_id.
|
40
|
+
expect(account.account_id).to eq(account_id)
|
41
|
+
expect(account.payment_method_id).to be_nil
|
42
42
|
|
43
43
|
# Try to retrieve it (bis repetita placent)
|
44
44
|
accounts = KillBillClient::Model::Account.find_in_batches(0, search_limit)
|
45
45
|
# Can't test equality if the remote server has extra data
|
46
|
-
accounts.pagination_total_nb_records.
|
47
|
-
accounts.pagination_max_nb_records.
|
48
|
-
accounts.size.
|
46
|
+
expect(accounts.pagination_total_nb_records).to be >= 1
|
47
|
+
expect(accounts.pagination_max_nb_records).to be >= 1
|
48
|
+
expect(accounts.size).to be >= 1
|
49
49
|
# If the remote server has lots of data, we need to page through the results (good test!)
|
50
50
|
found = nil
|
51
51
|
accounts.each_in_batches do |account|
|
52
52
|
found = account if account.external_key == external_key
|
53
53
|
break unless found.nil?
|
54
54
|
end
|
55
|
-
found.
|
55
|
+
expect(found).not_to be_nil
|
56
56
|
|
57
57
|
# Try to retrieve it via the search API
|
58
58
|
accounts = KillBillClient::Model::Account.find_in_batches_by_search_key(account.name, 0, search_limit)
|
59
59
|
# Can't test equality if the remote server has extra data
|
60
|
-
accounts.pagination_total_nb_records.
|
61
|
-
accounts.pagination_max_nb_records.
|
62
|
-
accounts.size.
|
60
|
+
expect(accounts.pagination_total_nb_records).to be >= 1
|
61
|
+
expect(accounts.pagination_max_nb_records).to be >= 1
|
62
|
+
expect(accounts.size).to be >= 1
|
63
63
|
# If the remote server has lots of data, we need to page through the results (good test!)
|
64
64
|
found = nil
|
65
65
|
accounts.each_in_batches do |account|
|
66
66
|
found = account if account.external_key == external_key
|
67
67
|
break unless found.nil?
|
68
68
|
end
|
69
|
-
found.
|
69
|
+
expect(found).not_to be_nil
|
70
70
|
|
71
71
|
# Add/Remove a tag
|
72
|
-
account.tags.size.
|
72
|
+
expect(account.tags.size).to eq(0)
|
73
73
|
account.add_tag('TEST', 'KillBill Spec test')
|
74
74
|
tags = account.tags
|
75
|
-
tags.size.
|
76
|
-
tags.first.tag_definition_name.
|
75
|
+
expect(tags.size).to eq(1)
|
76
|
+
expect(tags.first.tag_definition_name).to eq('TEST')
|
77
77
|
account.remove_tag('TEST', 'KillBill Spec test')
|
78
|
-
account.tags.size.
|
78
|
+
expect(account.tags.size).to eq(0)
|
79
79
|
|
80
80
|
# Add/Remove a custom field
|
81
|
-
account.custom_fields.size.
|
81
|
+
expect(account.custom_fields.size).to eq(0)
|
82
82
|
custom_field = KillBillClient::Model::CustomField.new
|
83
83
|
custom_field.name = Time.now.to_i.to_s
|
84
84
|
custom_field.value = Time.now.to_i.to_s
|
85
85
|
account.add_custom_field(custom_field, 'KillBill Spec test')
|
86
86
|
custom_fields = account.custom_fields
|
87
|
-
custom_fields.size.
|
88
|
-
custom_fields.first.name.
|
89
|
-
custom_fields.first.value.
|
87
|
+
expect(custom_fields.size).to eq(1)
|
88
|
+
expect(custom_fields.first.name).to eq(custom_field.name)
|
89
|
+
expect(custom_fields.first.value).to eq(custom_field.value)
|
90
90
|
account.remove_custom_field(custom_fields.first.custom_field_id, 'KillBill Spec test')
|
91
|
-
account.custom_fields.size.
|
91
|
+
expect(account.custom_fields.size).to eq(0)
|
92
92
|
|
93
93
|
# Add a payment method
|
94
94
|
pm = KillBillClient::Model::PaymentMethod.new
|
@@ -96,38 +96,38 @@ describe KillBillClient::Model do
|
|
96
96
|
pm.is_default = true
|
97
97
|
pm.plugin_name = KillBillClient::Model::PaymentMethod::EXTERNAL_PAYMENT
|
98
98
|
pm.plugin_info = {}
|
99
|
-
pm.payment_method_id.
|
99
|
+
expect(pm.payment_method_id).to be_nil
|
100
100
|
|
101
101
|
pm = pm.create(true, 'KillBill Spec test')
|
102
|
-
pm.payment_method_id.
|
102
|
+
expect(pm.payment_method_id).not_to be_nil
|
103
103
|
|
104
104
|
# Try to retrieve it
|
105
105
|
pm = KillBillClient::Model::PaymentMethod.find_by_id pm.payment_method_id, true
|
106
|
-
pm.account_id.
|
106
|
+
expect(pm.account_id).to eq(account.account_id)
|
107
107
|
|
108
108
|
# Try to retrieve it (bis repetita placent)
|
109
109
|
pms = KillBillClient::Model::PaymentMethod.find_in_batches(0, search_limit)
|
110
110
|
# Can't test equality if the remote server has extra data
|
111
|
-
pms.pagination_total_nb_records.
|
112
|
-
pms.pagination_max_nb_records.
|
113
|
-
pms.size.
|
111
|
+
expect(pms.pagination_total_nb_records).to be >= 1
|
112
|
+
expect(pms.pagination_max_nb_records).to be >= 1
|
113
|
+
expect(pms.size).to be >= 1
|
114
114
|
# If the remote server has lots of data, we need to page through the results (good test!)
|
115
115
|
found = nil
|
116
116
|
pms.each_in_batches do |payment_method|
|
117
117
|
found = payment_method if payment_method.payment_method_id == pm.payment_method_id
|
118
118
|
break unless found.nil?
|
119
119
|
end
|
120
|
-
found.
|
120
|
+
expect(found).not_to be_nil
|
121
121
|
|
122
122
|
account = KillBillClient::Model::Account.find_by_id account.account_id
|
123
|
-
account.payment_method_id.
|
123
|
+
expect(account.payment_method_id).to eq(pm.payment_method_id)
|
124
124
|
|
125
125
|
pms = KillBillClient::Model::PaymentMethod.find_all_by_account_id account.account_id
|
126
|
-
pms.size.
|
127
|
-
pms[0].payment_method_id.
|
126
|
+
expect(pms.size).to eq(1)
|
127
|
+
expect(pms[0].payment_method_id).to eq(pm.payment_method_id)
|
128
128
|
|
129
129
|
# Check there is no payment associated with that account
|
130
|
-
account.payments.size.
|
130
|
+
expect(account.payments.size).to eq(0)
|
131
131
|
|
132
132
|
# Add an external charge
|
133
133
|
invoice_item = KillBillClient::Model::InvoiceItem.new
|
@@ -138,27 +138,27 @@ describe KillBillClient::Model do
|
|
138
138
|
invoice_item = invoice_item.create 'KillBill Spec test'
|
139
139
|
invoice = KillBillClient::Model::Invoice.find_by_id_or_number invoice_item.invoice_id
|
140
140
|
|
141
|
-
invoice.balance.
|
141
|
+
expect(invoice.balance).to eq(123.98)
|
142
142
|
|
143
143
|
# Check the account balance
|
144
144
|
account = KillBillClient::Model::Account.find_by_id account.account_id, true
|
145
|
-
account.account_balance.
|
145
|
+
expect(account.account_balance).to eq(123.98)
|
146
146
|
|
147
147
|
pm.destroy(true, 'KillBill Spec test')
|
148
148
|
|
149
149
|
account = KillBillClient::Model::Account.find_by_id account.account_id
|
150
|
-
account.payment_method_id.
|
150
|
+
expect(account.payment_method_id).to be_nil
|
151
151
|
|
152
152
|
# Get its timeline
|
153
153
|
timeline = KillBillClient::Model::AccountTimeline.find_by_account_id account.account_id
|
154
154
|
|
155
|
-
timeline.account.external_key.
|
156
|
-
timeline.account.account_id.
|
155
|
+
expect(timeline.account.external_key).to eq(external_key)
|
156
|
+
expect(timeline.account.account_id).not_to be_nil
|
157
157
|
|
158
|
-
timeline.invoices.
|
159
|
-
timeline.invoices.
|
160
|
-
timeline.payments.
|
161
|
-
timeline.bundles.
|
158
|
+
expect(timeline.invoices).to be_a_kind_of Array
|
159
|
+
expect(timeline.invoices).not_to be_empty
|
160
|
+
expect(timeline.payments).to be_a_kind_of Array
|
161
|
+
expect(timeline.bundles).to be_a_kind_of Array
|
162
162
|
|
163
163
|
# Let's find the invoice by two methods
|
164
164
|
invoice = timeline.invoices.first
|
@@ -168,8 +168,8 @@ describe KillBillClient::Model do
|
|
168
168
|
invoice_with_id = KillBillClient::Model::Invoice.find_by_id_or_number invoice_id
|
169
169
|
invoice_with_number = KillBillClient::Model::Invoice.find_by_id_or_number invoice_number
|
170
170
|
|
171
|
-
invoice_with_id.invoice_id.
|
172
|
-
invoice_with_id.invoice_number.
|
171
|
+
expect(invoice_with_id.invoice_id).to eq(invoice_with_number.invoice_id)
|
172
|
+
expect(invoice_with_id.invoice_number).to eq(invoice_with_number.invoice_number)
|
173
173
|
|
174
174
|
# Create an external payment for each unpaid invoice
|
175
175
|
invoice_payment = KillBillClient::Model::InvoicePayment.new
|
@@ -179,43 +179,43 @@ describe KillBillClient::Model do
|
|
179
179
|
# Try to retrieve it
|
180
180
|
payments = KillBillClient::Model::Payment.find_in_batches(0, search_limit)
|
181
181
|
# Can't test equality if the remote server has extra data
|
182
|
-
payments.pagination_total_nb_records.
|
183
|
-
payments.pagination_max_nb_records.
|
184
|
-
payments.size.
|
182
|
+
expect(payments.pagination_total_nb_records).to be >= 1
|
183
|
+
expect(payments.pagination_max_nb_records).to be >= 1
|
184
|
+
expect(payments.size).to be >= 1
|
185
185
|
# If the remote server has lots of data, we need to page through the results (good test!)
|
186
186
|
found = nil
|
187
187
|
payments.each_in_batches do |p|
|
188
188
|
found = p if p.account_id == account.account_id
|
189
189
|
break unless found.nil?
|
190
190
|
end
|
191
|
-
found.
|
191
|
+
expect(found).not_to be_nil
|
192
192
|
|
193
193
|
# Try to retrieve it (bis repetita placent)
|
194
194
|
invoice_payment = KillBillClient::Model::InvoicePayment.find_by_id found.payment_id
|
195
|
-
invoice_payment.account_id.
|
195
|
+
expect(invoice_payment.account_id).to eq(account.account_id)
|
196
196
|
|
197
197
|
# Try to retrieve it
|
198
198
|
invoice = KillBillClient::Model::Invoice.new
|
199
199
|
invoice.invoice_id = invoice_payment.target_invoice_id
|
200
200
|
payments = invoice.payments
|
201
|
-
payments.size.
|
202
|
-
payments.first.account_id.
|
201
|
+
expect(payments.size).to eq(1)
|
202
|
+
expect(payments.first.account_id).to eq(account.account_id)
|
203
203
|
|
204
204
|
# Check the account balance
|
205
205
|
account = KillBillClient::Model::Account.find_by_id account.account_id, true
|
206
|
-
account.account_balance.
|
206
|
+
expect(account.account_balance).to eq(0)
|
207
207
|
|
208
208
|
# Verify the timeline
|
209
209
|
timeline = KillBillClient::Model::AccountTimeline.find_by_account_id account.account_id
|
210
|
-
timeline.payments.
|
210
|
+
expect(timeline.payments).not_to be_empty
|
211
211
|
invoice_payment = timeline.payments.first
|
212
|
-
timeline.payments.first.transactions.size.
|
213
|
-
timeline.payments.first.transactions.first.transaction_type.
|
214
|
-
invoice_payment.auth_amount.
|
215
|
-
invoice_payment.captured_amount.
|
216
|
-
invoice_payment.purchased_amount.
|
217
|
-
invoice_payment.refunded_amount.
|
218
|
-
invoice_payment.credited_amount.
|
212
|
+
expect(timeline.payments.first.transactions.size).to eq(1)
|
213
|
+
expect(timeline.payments.first.transactions.first.transaction_type).to eq('PURCHASE')
|
214
|
+
expect(invoice_payment.auth_amount).to eq(0)
|
215
|
+
expect(invoice_payment.captured_amount).to eq(0)
|
216
|
+
expect(invoice_payment.purchased_amount).to eq(invoice_payment.purchased_amount)
|
217
|
+
expect(invoice_payment.refunded_amount).to eq(0)
|
218
|
+
expect(invoice_payment.credited_amount).to eq(0)
|
219
219
|
|
220
220
|
# Refund the payment (with item adjustment)
|
221
221
|
invoice_item = KillBillClient::Model::Invoice.find_by_id_or_number(invoice_number, true).items.first
|
@@ -226,13 +226,13 @@ describe KillBillClient::Model do
|
|
226
226
|
|
227
227
|
# Verify the refund
|
228
228
|
timeline = KillBillClient::Model::AccountTimeline.find_by_account_id account.account_id
|
229
|
-
timeline.payments.
|
230
|
-
timeline.payments.size.
|
231
|
-
timeline.payments.first.transactions.size.
|
232
|
-
timeline.payments.first.transactions.first.transaction_type.
|
229
|
+
expect(timeline.payments).not_to be_empty
|
230
|
+
expect(timeline.payments.size).to eq(1)
|
231
|
+
expect(timeline.payments.first.transactions.size).to eq(2)
|
232
|
+
expect(timeline.payments.first.transactions.first.transaction_type).to eq('PURCHASE')
|
233
233
|
refund = timeline.payments.first.transactions.last
|
234
|
-
refund.transaction_type.
|
235
|
-
refund.amount.
|
234
|
+
expect(refund.transaction_type).to eq('REFUND')
|
235
|
+
expect(refund.amount).to eq(invoice_item.amount)
|
236
236
|
|
237
237
|
# Create a credit for invoice
|
238
238
|
new_credit = KillBillClient::Model::Credit.new
|
@@ -244,15 +244,15 @@ describe KillBillClient::Model do
|
|
244
244
|
|
245
245
|
# Verify the invoice item of the credit
|
246
246
|
invoice = KillBillClient::Model::Invoice.find_by_id_or_number invoice_id
|
247
|
-
invoice.items.
|
247
|
+
expect(invoice.items).not_to be_empty
|
248
248
|
item = invoice.items.last
|
249
|
-
item.invoice_id.
|
250
|
-
item.amount.
|
251
|
-
item.account_id.
|
249
|
+
expect(item.invoice_id).to eq(invoice_id)
|
250
|
+
expect(item.amount).to eq(10.1)
|
251
|
+
expect(item.account_id).to eq(account.account_id)
|
252
252
|
|
253
253
|
# Verify the credit
|
254
254
|
account = KillBillClient::Model::Account.find_by_id account.account_id, true
|
255
|
-
account.account_balance.
|
255
|
+
expect(account.account_balance).to eq(-10.1)
|
256
256
|
|
257
257
|
# Create a subscription
|
258
258
|
sub = KillBillClient::Model::Subscription.new
|
@@ -265,39 +265,39 @@ describe KillBillClient::Model do
|
|
265
265
|
sub = sub.create 'KillBill Spec test'
|
266
266
|
|
267
267
|
# Verify we can retrieve it
|
268
|
-
account.bundles.size.
|
269
|
-
account.bundles[0].subscriptions.size.
|
270
|
-
account.bundles[0].subscriptions[0].subscription_id.
|
268
|
+
expect(account.bundles.size).to eq(1)
|
269
|
+
expect(account.bundles[0].subscriptions.size).to eq(1)
|
270
|
+
expect(account.bundles[0].subscriptions[0].subscription_id).to eq(sub.subscription_id)
|
271
271
|
bundle = account.bundles[0]
|
272
272
|
|
273
273
|
# Verify we can retrieve it by id
|
274
|
-
KillBillClient::Model::Bundle.find_by_id(bundle.bundle_id).
|
274
|
+
expect(KillBillClient::Model::Bundle.find_by_id(bundle.bundle_id)).to eq(bundle)
|
275
275
|
|
276
276
|
# Verify we can retrieve it by external key
|
277
|
-
KillBillClient::Model::Bundle.find_by_external_key(bundle.external_key).
|
277
|
+
expect(KillBillClient::Model::Bundle.find_by_external_key(bundle.external_key)).to eq(bundle)
|
278
278
|
|
279
279
|
# Verify we can retrieve it by account id and external key
|
280
280
|
bundles = KillBillClient::Model::Bundle.find_all_by_account_id_and_external_key(account.account_id, bundle.external_key)
|
281
|
-
bundles.size.
|
282
|
-
bundles[0].
|
281
|
+
expect(bundles.size).to eq(1)
|
282
|
+
expect(bundles[0]).to eq(bundle)
|
283
283
|
end
|
284
284
|
|
285
285
|
it 'should manipulate tag definitions' do
|
286
|
-
KillBillClient::Model::TagDefinition.all.size.
|
287
|
-
KillBillClient::Model::TagDefinition.find_by_name('TEST').is_control_tag.
|
286
|
+
expect(KillBillClient::Model::TagDefinition.all.size).to be > 0
|
287
|
+
expect(KillBillClient::Model::TagDefinition.find_by_name('TEST').is_control_tag).to be_truthy
|
288
288
|
|
289
289
|
tag_definition_name = Time.now.to_i.to_s
|
290
|
-
KillBillClient::Model::TagDefinition.find_by_name(tag_definition_name).
|
290
|
+
expect(KillBillClient::Model::TagDefinition.find_by_name(tag_definition_name)).to be_nil
|
291
291
|
|
292
292
|
tag_definition = KillBillClient::Model::TagDefinition.new
|
293
293
|
tag_definition.name = tag_definition_name
|
294
294
|
tag_definition.description = 'Tag for unit test'
|
295
|
-
tag_definition.create('KillBill Spec test').id.
|
295
|
+
expect(tag_definition.create('KillBill Spec test').id).not_to be_nil
|
296
296
|
|
297
297
|
found_tag_definition = KillBillClient::Model::TagDefinition.find_by_name(tag_definition_name)
|
298
|
-
found_tag_definition.name.
|
299
|
-
found_tag_definition.description.
|
300
|
-
found_tag_definition.is_control_tag.
|
298
|
+
expect(found_tag_definition.name).to eq(tag_definition_name)
|
299
|
+
expect(found_tag_definition.description).to eq(tag_definition.description)
|
300
|
+
expect(found_tag_definition.is_control_tag).to be_falsey
|
301
301
|
end
|
302
302
|
|
303
303
|
it 'should manipulate tenants', :integration => true do
|
@@ -310,22 +310,22 @@ describe KillBillClient::Model do
|
|
310
310
|
|
311
311
|
# Create and verify the tenant
|
312
312
|
tenant = tenant.create('KillBill Spec test')
|
313
|
-
tenant.api_key.
|
314
|
-
tenant.tenant_id.
|
313
|
+
expect(tenant.api_key).to eq(api_key)
|
314
|
+
expect(tenant.tenant_id).not_to be_nil
|
315
315
|
|
316
316
|
# Try to retrieve it by id
|
317
317
|
tenant = KillBillClient::Model::Tenant.find_by_id tenant.tenant_id
|
318
|
-
tenant.api_key.
|
318
|
+
expect(tenant.api_key).to eq(api_key)
|
319
319
|
|
320
320
|
# Try to retrieve it by api key
|
321
321
|
tenant = KillBillClient::Model::Tenant.find_by_api_key tenant.api_key
|
322
|
-
tenant.api_key.
|
322
|
+
expect(tenant.api_key).to eq(api_key)
|
323
323
|
end
|
324
324
|
|
325
325
|
it 'should manipulate the catalog', :integration => true do
|
326
326
|
plans = KillBillClient::Model::Catalog::available_base_plans
|
327
|
-
plans.size.
|
328
|
-
plans[0].plan.
|
327
|
+
expect(plans.size).to be > 0
|
328
|
+
expect(plans[0].plan).not_to be_nil
|
329
329
|
end
|
330
330
|
|
331
331
|
#it 'should retrieve users permissions' do
|
@@ -10,9 +10,66 @@ describe KillBillClient::Model::Resource do
|
|
10
10
|
|
11
11
|
payment2 = KillBillClient::Model::InvoicePayment.new(payment1.to_hash)
|
12
12
|
|
13
|
-
payment2.
|
14
|
-
payment2.account_id.
|
15
|
-
payment2.target_invoice_id.
|
16
|
-
payment2.purchased_amount.
|
13
|
+
expect(payment2).to eq(payment1)
|
14
|
+
expect(payment2.account_id).to eq('1234')
|
15
|
+
expect(payment2.target_invoice_id).to eq('5678')
|
16
|
+
expect(payment2.purchased_amount).to eq(12.42)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#require_multi_tenant_options!' do
|
20
|
+
let(:message) { 'nothing' }
|
21
|
+
|
22
|
+
def require_multi_tenant_options!
|
23
|
+
described_class.require_multi_tenant_options!(options, message)
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when api_key and api_secret passed as options' do
|
27
|
+
let(:options) do
|
28
|
+
{
|
29
|
+
:api_key => 'bob',
|
30
|
+
:api_secret =>'lazar'
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
it do
|
35
|
+
expect { require_multi_tenant_options! }.not_to raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when no api_key passed as options' do
|
40
|
+
let(:options) do
|
41
|
+
{
|
42
|
+
:api_secret => 'lazar'
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
it do
|
47
|
+
expect { require_multi_tenant_options! }.to raise_error(ArgumentError, message)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when no api_secret passed as options' do
|
52
|
+
let(:options) do
|
53
|
+
{
|
54
|
+
:api_key => 'bob'
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
it do
|
59
|
+
expect { require_multi_tenant_options! }.to raise_error(ArgumentError, message)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when api_key and api_secret passed as KillBillClient configuration option' do
|
64
|
+
let(:options) { { } }
|
65
|
+
before do
|
66
|
+
allow(KillBillClient).to receive_messages(:api_key => 'bob')
|
67
|
+
allow(KillBillClient).to receive_messages(:api_secret => 'lazar')
|
68
|
+
end
|
69
|
+
|
70
|
+
it do
|
71
|
+
expect { require_multi_tenant_options! }.not_to raise_error
|
72
|
+
end
|
73
|
+
end
|
17
74
|
end
|
18
75
|
end
|
@@ -4,11 +4,11 @@ describe KillBillClient::Model::Resources do
|
|
4
4
|
it 'should respect the next page url when calling the .each_in_batches method' do
|
5
5
|
stuff = KillBillClient::Model::Resources.new
|
6
6
|
1.upto(10).each { |i| stuff << i }
|
7
|
-
stuff.size.
|
7
|
+
expect(stuff.size).to eq(10)
|
8
8
|
|
9
9
|
idx = 1
|
10
10
|
stuff.each_in_batches do |i|
|
11
|
-
i.
|
11
|
+
expect(i).to eq(idx)
|
12
12
|
idx += 1
|
13
13
|
end
|
14
14
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.31.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Killbill core team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -31,11 +31,17 @@ dependencies:
|
|
31
31
|
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 10.0.0
|
34
|
+
- - <
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 11.0.0
|
34
37
|
requirement: !ruby/object:Gem::Requirement
|
35
38
|
requirements:
|
36
39
|
- - '>='
|
37
40
|
- !ruby/object:Gem::Version
|
38
41
|
version: 10.0.0
|
42
|
+
- - <
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 11.0.0
|
39
45
|
prerelease: false
|
40
46
|
type: :development
|
41
47
|
- !ruby/object:Gem::Dependency
|
@@ -44,12 +50,12 @@ dependencies:
|
|
44
50
|
requirements:
|
45
51
|
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
53
|
+
version: '3.4'
|
48
54
|
requirement: !ruby/object:Gem::Requirement
|
49
55
|
requirements:
|
50
56
|
- - ~>
|
51
57
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
58
|
+
version: '3.4'
|
53
59
|
prerelease: false
|
54
60
|
type: :development
|
55
61
|
description: An API client library for Kill Bill.
|
@@ -175,6 +181,7 @@ files:
|
|
175
181
|
- lib/rails/generators/killbill_client/config_generator.rb
|
176
182
|
- lib/rails/killbill_client.rb
|
177
183
|
- spec/killbill_client/base_uri_spec.rb
|
184
|
+
- spec/killbill_client/encoding_spec.rb
|
178
185
|
- spec/killbill_client/model_relation_spec.rb
|
179
186
|
- spec/killbill_client/remote/api_spec.rb
|
180
187
|
- spec/killbill_client/remote/model_spec.rb
|
@@ -203,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
210
|
version: '0'
|
204
211
|
requirements: []
|
205
212
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.
|
213
|
+
rubygems_version: 2.4.6
|
207
214
|
signing_key:
|
208
215
|
specification_version: 4
|
209
216
|
summary: Kill Bill client library.
|