killbill-client 2.4.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +24 -118
  3. data/.github/CONTRIBUTING.md +20 -0
  4. data/.github/FUNDING.yml +3 -0
  5. data/.github/workflows/ci.yml +145 -0
  6. data/.github/workflows/release.yml +46 -0
  7. data/README.md +2 -1
  8. data/bin/retry +21 -0
  9. data/docker/docker-compose.ci.mysql.yml +21 -0
  10. data/docker/docker-compose.ci.postgresql.yml +21 -0
  11. data/killbill_client.gemspec +2 -1
  12. data/lib/killbill_client.rb +2 -0
  13. data/lib/killbill_client/api/api.rb +1 -1
  14. data/lib/killbill_client/api/net_http_adapter.rb +30 -16
  15. data/lib/killbill_client/models/account.rb +12 -24
  16. data/lib/killbill_client/models/admin.rb +131 -0
  17. data/lib/killbill_client/models/bundle.rb +2 -0
  18. data/lib/killbill_client/models/credit.rb +5 -5
  19. data/lib/killbill_client/models/custom_field.rb +17 -0
  20. data/lib/killbill_client/models/gen/account_attributes.rb +0 -1
  21. data/lib/killbill_client/models/gen/{block_price_override_attributes.rb → block_price_attributes.rb} +1 -1
  22. data/lib/killbill_client/models/gen/invoice_attributes.rb +1 -0
  23. data/lib/killbill_client/models/gen/invoice_item_attributes.rb +1 -0
  24. data/lib/killbill_client/models/gen/overdue_state_attributes.rb +0 -1
  25. data/lib/killbill_client/models/gen/{phase_price_override_attributes.rb → phase_price_attributes.rb} +2 -2
  26. data/lib/killbill_client/models/gen/require_gen.rb +52 -53
  27. data/lib/killbill_client/models/gen/subscription_attributes.rb +2 -0
  28. data/lib/killbill_client/models/gen/{tier_price_override_attributes.rb → tier_price_attributes.rb} +2 -2
  29. data/lib/killbill_client/models/gen/{usage_price_override_attributes.rb → usage_price_attributes.rb} +2 -2
  30. data/lib/killbill_client/models/helpers/custom_field_helper.rb +1 -1
  31. data/lib/killbill_client/models/invoice.rb +7 -7
  32. data/lib/killbill_client/models/invoice_item.rb +4 -1
  33. data/lib/killbill_client/models/invoice_payment.rb +3 -0
  34. data/lib/killbill_client/models/models.rb +1 -0
  35. data/lib/killbill_client/models/resource.rb +1 -1
  36. data/lib/killbill_client/models/subscription.rb +23 -1
  37. data/lib/killbill_client/version.rb +1 -16
  38. data/spec/killbill_client/http_adapter_spec.rb +38 -0
  39. data/spec/killbill_client/remote/model_spec.rb +15 -12
  40. metadata +30 -9
  41. data/lib/killbill_client/models/gen/credit_attributes.rb +0 -43
  42. data/lib/killbill_client/models/gen/invoice_email_attributes.rb +0 -35
data/README.md CHANGED
@@ -10,7 +10,8 @@ Kill Bill compatibility
10
10
  | -------------: | ----------------: |
11
11
  | 0.x.y | 0.16.z |
12
12
  | 1.x.y | 0.18.z |
13
- | 2.x.y | 0.19.z |
13
+ | 2.x.y | 0.20.z |
14
+ | 3.x.y | 0.22.z |
14
15
 
15
16
  Installation
16
17
  ------------
data/bin/retry ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+
5
+ x() {
6
+ echo "+ $*" >&2
7
+ "$@"
8
+ }
9
+
10
+ retry_delay_seconds=10
11
+
12
+ i="0"
13
+ while [ $i -lt 4 ]
14
+ do
15
+ x "$@" && exit 0
16
+ sleep "${retry_delay_seconds}"
17
+ i=$[$i+1]
18
+ done
19
+
20
+ echo "$0: retrying [$*] timed out" >&2
21
+ exit 1
@@ -0,0 +1,21 @@
1
+ version: '3.8'
2
+
3
+ services:
4
+ killbill:
5
+ network_mode: host
6
+ image: killbill/killbill:0.22.20
7
+ environment:
8
+ - KILLBILL_CATALOG_URI=SpyCarAdvanced.xml
9
+ - KILLBILL_DAO_URL=jdbc:mysql://127.0.0.1:3306/killbill
10
+ - KILLBILL_DAO_USER=root
11
+ - KILLBILL_DAO_PASSWORD=root
12
+ - KILLBILL_SERVER_TEST_MODE=true
13
+ - KILLBILL_INVOICE_SANITY_SAFETY_BOUND_ENABLED=false
14
+ - KILLBILL_INVOICE_MAX_DAILY_NUMBER_OF_ITEMS_SAFETY_BOUND=-1
15
+ depends_on:
16
+ - db
17
+ db:
18
+ network_mode: host
19
+ image: killbill/mariadb:0.22
20
+ environment:
21
+ - MYSQL_ROOT_PASSWORD=root
@@ -0,0 +1,21 @@
1
+ version: '3.8'
2
+
3
+ services:
4
+ killbill:
5
+ network_mode: host
6
+ image: killbill/killbill:0.22.20
7
+ environment:
8
+ - KILLBILL_CATALOG_URI=SpyCarAdvanced.xml
9
+ - KILLBILL_DAO_URL=jdbc:postgresql://127.0.0.1:5432/killbill
10
+ - KILLBILL_DAO_USER=postgres
11
+ - KILLBILL_DAO_PASSWORD=postgres
12
+ - KILLBILL_SERVER_TEST_MODE=true
13
+ - KILLBILL_INVOICE_SANITY_SAFETY_BOUND_ENABLED=false
14
+ - KILLBILL_INVOICE_MAX_DAILY_NUMBER_OF_ITEMS_SAFETY_BOUND=-1
15
+ depends_on:
16
+ - db
17
+ db:
18
+ network_mode: host
19
+ image: killbill/postgresql:0.22
20
+ environment:
21
+ - POSTGRES_PASSWORD=postgres
@@ -19,7 +19,7 @@ require 'killbill_client/version'
19
19
 
20
20
  Gem::Specification.new do |s|
21
21
  s.name = 'killbill-client'
22
- s.version = KillBillClient::Version.to_s
22
+ s.version = KillBillClient::VERSION
23
23
  s.summary = 'Kill Bill client library.'
24
24
  s.description = 'An API client library for Kill Bill.'
25
25
 
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
43
43
  s.add_dependency 'json', '>= 1.2.0', '< 2.0.0'
44
44
  end
45
45
 
46
+ s.add_development_dependency 'gem-release', '~> 2.2'
46
47
  s.add_development_dependency 'rake', '>= 10.0.0', '< 11.0.0'
47
48
  s.add_development_dependency 'rspec', '~> 3.4'
48
49
  end
@@ -41,6 +41,8 @@ module KillBillClient
41
41
 
42
42
  attr_writer :url
43
43
 
44
+ attr_accessor :read_timeout
45
+ attr_accessor :connection_timeout
44
46
  attr_accessor :disable_ssl_verification
45
47
  attr_accessor :return_full_stacktraces
46
48
 
@@ -70,7 +70,7 @@ module KillBillClient
70
70
 
71
71
  # @return [String]
72
72
  def user_agent
73
- "killbill/#{Version}; #{RUBY_DESCRIPTION}"
73
+ "killbill/#{VERSION}; #{RUBY_DESCRIPTION}"
74
74
  end
75
75
 
76
76
  private
@@ -35,6 +35,25 @@ module KillBillClient
35
35
  :delete => ::Net::HTTP::Delete
36
36
  }
37
37
 
38
+ def build_uri(relative_uri, options)
39
+ # Need to encode in case of spaces (e.g. /1.0/kb/security/users/Mad Max/roles)
40
+ encoded_relative_uri = URI::DEFAULT_PARSER.escape(relative_uri)
41
+ if URI(encoded_relative_uri).scheme.nil?
42
+ uri = (options[:base_uri] || KillBillClient::API.base_uri)
43
+ uri = URI.parse(uri) unless uri.is_a?(URI)
44
+ # Note: make sure to keep the full path (if any) from URI::HTTP, for non-ROOT deployments
45
+ # See https://github.com/killbill/killbill/issues/221#issuecomment-151980263
46
+ base_path = uri.request_uri == '/' ? '' : uri.request_uri
47
+ uri += (base_path + URI::DEFAULT_PARSER.escape(relative_uri))
48
+ else
49
+ uri = encoded_relative_uri
50
+ uri = URI.parse(uri) unless uri.is_a?(URI)
51
+ end
52
+ uri += encode_params(options).to_s
53
+
54
+ uri
55
+ end
56
+
38
57
  def encode_params(options = {})
39
58
  # Plugin properties and controlPluginNames are passed in the options but we want to send them as query parameters,
40
59
  # so remove with from global hash and insert them under :params
@@ -67,8 +86,16 @@ module KillBillClient
67
86
 
68
87
  def create_http_client(uri, options = {})
69
88
  http = ::Net::HTTP.new uri.host, uri.port
70
- http.read_timeout = options[:read_timeout].to_f / 1000 if options[:read_timeout].is_a? Numeric
71
- http.open_timeout = options[:connection_timeout].to_f / 1000 if options[:connection_timeout].is_a? Numeric
89
+ if options[:read_timeout].is_a? Numeric
90
+ http.read_timeout = options[:read_timeout].to_f / 1000
91
+ elsif KillBillClient.read_timeout.is_a? Numeric
92
+ http.read_timeout = KillBillClient.read_timeout.to_f / 1000
93
+ end
94
+ if options[:connection_timeout].is_a? Numeric
95
+ http.open_timeout = options[:connection_timeout].to_f / 1000
96
+ elsif KillBillClient.connection_timeout.is_a? Numeric
97
+ http.open_timeout = KillBillClient.connection_timeout.to_f / 1000
98
+ end
72
99
  http.use_ssl = uri.scheme == 'https'
73
100
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if (options[:disable_ssl_verification] || KillBillClient.disable_ssl_verification)
74
101
  http
@@ -79,20 +106,7 @@ module KillBillClient
79
106
  head.update options[:head] if options[:head]
80
107
  head.delete_if { |_, value| value.nil? }
81
108
 
82
- # Need to encode in case of spaces (e.g. /1.0/kb/security/users/Mad Max/roles)
83
- encoded_relative_uri = URI::DEFAULT_PARSER.escape(relative_uri)
84
- if URI(encoded_relative_uri).scheme.nil?
85
- uri = (options[:base_uri] || base_uri)
86
- uri = URI.parse(uri) unless uri.is_a?(URI)
87
- # Note: make sure to keep the full path (if any) from URI::HTTP, for non-ROOT deployments
88
- # See https://github.com/killbill/killbill/issues/221#issuecomment-151980263
89
- base_path = uri.request_uri == '/' ? '' : uri.request_uri
90
- uri += (base_path + URI::DEFAULT_PARSER.escape(relative_uri))
91
- else
92
- uri = encoded_relative_uri
93
- uri = URI.parse(uri) unless uri.is_a?(URI)
94
- end
95
- uri += encode_params(options).to_s
109
+ uri = build_uri(relative_uri, options)
96
110
  request = METHODS[method].new uri.request_uri, head
97
111
 
98
112
  # Configure multi-tenancy headers, if enabled
@@ -65,6 +65,14 @@ module KillBillClient
65
65
  },
66
66
  options
67
67
  end
68
+
69
+ def blocking_state_audit_logs_with_history(blocking_state_id, options = {})
70
+ get "#{KILLBILL_API_ACCOUNTS_PREFIX}/block/#{blocking_state_id}/auditLogsWithHistory",
71
+ {},
72
+ options,
73
+ AuditLog
74
+ end
75
+
68
76
  end
69
77
 
70
78
  def create(user = nil, reason = nil, comment = nil, options = {})
@@ -135,20 +143,18 @@ module KillBillClient
135
143
  Bundle
136
144
  end
137
145
 
138
- def invoices(with_items=false, options = {})
146
+ def invoices(options = {})
139
147
  self.class.get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/invoices",
140
148
  {
141
- :withItems => with_items
142
149
  },
143
150
  options,
144
151
  Invoice
145
152
  end
146
153
 
147
- def migration_invoices(with_items=false, options = {})
154
+ def migration_invoices(options = {})
148
155
  self.class.get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/invoices",
149
156
  {
150
- :withMigrationInvoices => true,
151
- :withItems => with_items
157
+ :withMigrationInvoices => true
152
158
  },
153
159
  options,
154
160
  Invoice
@@ -286,26 +292,7 @@ module KillBillClient
286
292
  AuditLog
287
293
  end
288
294
 
289
- def email_notifications(options = {})
290
- self.class.get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/emailNotifications",
291
- {},
292
- options,
293
- InvoiceEmailAttributes
294
- end
295
-
296
- def update_email_notifications(user = nil, reason = nil, comment = nil, options = {})
297
- self.class.put "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/emailNotifications",
298
- to_json,
299
- {},
300
- {
301
- :user => user,
302
- :reason => reason,
303
- :comment => comment,
304
- }.merge(options)
305
- end
306
-
307
295
  def all_tags(object_type, included_deleted, audit = 'NONE', options = {})
308
-
309
296
  params = {}
310
297
  params[:objectType] = object_type if object_type
311
298
  params[:includedDeleted] = included_deleted if included_deleted
@@ -389,6 +376,7 @@ module KillBillClient
389
376
  options,
390
377
  AuditLog
391
378
  end
379
+
392
380
  end
393
381
  end
394
382
  end
@@ -0,0 +1,131 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Admin < AdminPaymentAttributes
4
+
5
+ KILLBILL_API_ADMIN_PREFIX = "#{KILLBILL_API_PREFIX}/admin"
6
+ KILLBILL_API_QUEUES_PREFIX = "#{KILLBILL_API_ADMIN_PREFIX}/queues"
7
+
8
+ KILLBILL_API_CLOCK_PREFIX = "#{KILLBILL_API_PREFIX}/test/clock"
9
+
10
+ class << self
11
+ def get_queues_entries(account_id, options = {})
12
+ get KILLBILL_API_QUEUES_PREFIX,
13
+ {
14
+ :accountId => account_id,
15
+ :withHistory => options[:withHistory],
16
+ :minDate => options[:minDate],
17
+ :maxDate => options[:maxDate]
18
+ },
19
+ {
20
+ :accept => 'application/octet-stream'
21
+ }.merge(options)
22
+ end
23
+
24
+ def fix_transaction_state(payment_id, transaction_id, transaction_status, user = nil, reason = nil, comment = nil, options = {})
25
+ put "#{KILLBILL_API_ADMIN_PREFIX}/payments/#{payment_id}/transactions/#{transaction_id}",
26
+ {:transactionStatus => transaction_status}.to_json,
27
+ {},
28
+ {
29
+ :user => user,
30
+ :reason => reason,
31
+ :comment => comment,
32
+ }.merge(options)
33
+ end
34
+
35
+ def trigger_invoice_generation_for_parked_accounts(offset = 0, limit = 100, user =nil, options = {})
36
+ post "#{KILLBILL_API_ADMIN_PREFIX}/invoices",
37
+ {},
38
+ {
39
+ :offset => offset,
40
+ :limit => limit
41
+ },
42
+ {
43
+ :user => user
44
+ }.merge(options)
45
+ end
46
+
47
+ def put_in_rotation(options = {})
48
+ put "#{KILLBILL_API_ADMIN_PREFIX}/healthcheck",
49
+ {},
50
+ {},
51
+ {}.merge(options)
52
+ end
53
+
54
+ def put_out_of_rotation(options = {})
55
+ delete "#{KILLBILL_API_ADMIN_PREFIX}/healthcheck",
56
+ {},
57
+ {},
58
+ {}.merge(options)
59
+ end
60
+
61
+ def invalidates_cache(cache_name = nil, options = {})
62
+ delete "#{KILLBILL_API_ADMIN_PREFIX}/cache",
63
+ {},
64
+ {
65
+ :cacheName => cache_name
66
+ },
67
+ {}.merge(options)
68
+ end
69
+
70
+ def invalidates_cache_by_account(account_id = nil, options = {})
71
+ delete "#{KILLBILL_API_ADMIN_PREFIX}/cache/accounts/#{account_id}",
72
+ {},
73
+ {},
74
+ {}.merge(options)
75
+ end
76
+
77
+ def invalidates_cache_by_tenant(options = {})
78
+ delete "#{KILLBILL_API_ADMIN_PREFIX}/cache/tenants",
79
+ {},
80
+ {},
81
+ {}.merge(options)
82
+ end
83
+
84
+ def get_clock(time_zone, options)
85
+ params = {}
86
+ params[:timeZone] = time_zone unless time_zone.nil?
87
+
88
+ res = get KILLBILL_API_CLOCK_PREFIX,
89
+ params,
90
+ options
91
+ JSON.parse res.body
92
+ end
93
+
94
+ def set_clock(requested_date, time_zone, options)
95
+ params = {}
96
+ params[:requestedDate] = requested_date unless requested_date.nil?
97
+ params[:timeZone] = time_zone unless time_zone.nil?
98
+
99
+ # The default 5s is not always enough
100
+ params[:timeoutSec] ||= 10
101
+
102
+ res = post KILLBILL_API_CLOCK_PREFIX,
103
+ {},
104
+ params,
105
+ {}.merge(options)
106
+ JSON.parse res.body
107
+ end
108
+
109
+ def increment_kb_clock(days, weeks, months, years, time_zone, options)
110
+ params = {}
111
+ params[:days] = days unless days.nil?
112
+ params[:weeks] = weeks unless weeks.nil?
113
+ params[:months] = months unless months.nil?
114
+ params[:years] = years unless years.nil?
115
+ params[:timeZone] = time_zone unless time_zone.nil?
116
+
117
+ # The default 5s is not always enough
118
+ params[:timeoutSec] ||= 10
119
+
120
+ res = put KILLBILL_API_CLOCK_PREFIX,
121
+ {},
122
+ params,
123
+ {}.merge(options)
124
+
125
+ JSON.parse res.body
126
+ end
127
+
128
+ end
129
+ end
130
+ end
131
+ end
@@ -6,12 +6,14 @@ module KillBillClient
6
6
 
7
7
  include KillBillClient::Model::TagHelper
8
8
  include KillBillClient::Model::CustomFieldHelper
9
+ include KillBillClient::Model::AuditLogWithHistoryHelper
9
10
 
10
11
  has_custom_fields KILLBILL_API_BUNDLES_PREFIX, :bundle_id
11
12
  has_tags KILLBILL_API_BUNDLES_PREFIX, :bundle_id
12
13
 
13
14
  has_many :subscriptions, KillBillClient::Model::Subscription
14
15
  has_many :audit_logs, KillBillClient::Model::AuditLog
16
+ has_audit_logs_with_history KILLBILL_API_BUNDLES_PREFIX, :bundle_id
15
17
 
16
18
  class << self
17
19
  def find_in_batches(offset = 0, limit = 100, options = {})
@@ -1,6 +1,6 @@
1
1
  module KillBillClient
2
2
  module Model
3
- class Credit < CreditAttributes
3
+ class Credit < InvoiceItemAttributes
4
4
  KILLBILL_API_CREDITS_PREFIX = "#{KILLBILL_API_PREFIX}/credits"
5
5
  has_many :audit_logs, KillBillClient::Model::AuditLog
6
6
 
@@ -9,13 +9,13 @@ module KillBillClient
9
9
  get "#{KILLBILL_API_CREDITS_PREFIX}/#{credit_id}",
10
10
  {},
11
11
  options,
12
- CreditAttributes
12
+ InvoiceItemAttributes
13
13
  end
14
14
  end
15
15
 
16
16
  def create(auto_commit = false, user = nil, reason = nil, comment = nil, options = {})
17
- created_credit = self.class.post KILLBILL_API_CREDITS_PREFIX,
18
- to_json,
17
+ created_credits = self.class.post KILLBILL_API_CREDITS_PREFIX,
18
+ [to_hash].to_json,
19
19
  {
20
20
  :autoCommit => auto_commit
21
21
  },
@@ -24,7 +24,7 @@ module KillBillClient
24
24
  :reason => reason,
25
25
  :comment => comment,
26
26
  }.merge(options)
27
- created_credit.refresh(options)
27
+ created_credits
28
28
  end
29
29
 
30
30
  end
@@ -28,6 +28,23 @@ module KillBillClient
28
28
  },
29
29
  options
30
30
  end
31
+
32
+ def find_in_batches_by_search_type_name(object_type, field_name, field_value, offset = 0, limit = 100, options = {})
33
+
34
+ query_fields = {
35
+ :objectType => object_type,
36
+ :fieldName => field_name,
37
+ :fieldValue => field_value,
38
+ :offset => offset,
39
+ :limit => limit
40
+ }
41
+ query_fields[:fieldValue] = field_value if field_value
42
+
43
+ get "#{KILLBILL_API_CUSTOM_FIELDS_PREFIX}/search",
44
+ query_fields,
45
+ options
46
+ end
47
+
31
48
  end
32
49
  end
33
50
  end