lago-ruby-client 1.43.0 → 1.44.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.
- checksums.yaml +4 -4
- data/lib/lago/api/client.rb +5 -0
- data/lib/lago/api/resources/customer.rb +12 -1
- data/lib/lago/api/resources/customers/wallets/alert.rb +76 -0
- data/lib/lago/api/resources/customers/wallets/base.rb +17 -0
- data/lib/lago/api/resources/customers/wallets/metadata.rb +51 -0
- data/lib/lago/api/resources/customers/wallets/whitelist_params.rb +103 -0
- data/lib/lago/api/resources/customers/wallets.rb +34 -0
- data/lib/lago/api/resources/invoice.rb +8 -1
- data/lib/lago/api/resources/nested.rb +65 -0
- data/lib/lago/api/resources/subscription.rb +84 -49
- data/lib/lago/api/resources/wallet.rb +2 -65
- data/lib/lago/api/resources/wallet_transaction.rb +22 -1
- data/lib/lago/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e05c7adf2d8d5d2dd6d5e8e9263908f415013356761245b1f22878b0fd0c7a2
|
|
4
|
+
data.tar.gz: d89d43c70f055b2363ef08cb063d5910f1335257846292400b4e1f88e0ab882f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fdab377ffb956c42aec999bd2ca63fa4ceeb895f656497175b955b93d2d2adfa60e2b088ff3deedbf039fef3ca01fb4ecb2d98aa2afb27d74bcf9f9710737ace
|
|
7
|
+
data.tar.gz: 0e52ca90f164179ac5e28c90e48a37ef1d0f57ffe47f35ba105df18857ed4035a4969fa9aff93de0291143bfd0bb5e2d23efb052b5db7e17cebd3502cbf46f9a
|
data/lib/lago/api/client.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'lago/api/resources/base'
|
|
4
|
+
require 'lago/api/resources/nested'
|
|
4
5
|
require 'lago/api/resources/activity_log'
|
|
5
6
|
require 'lago/api/resources/add_on'
|
|
6
7
|
require 'lago/api/resources/api_log'
|
|
@@ -19,6 +20,10 @@ require 'lago/api/resources/customers/payment_method'
|
|
|
19
20
|
require 'lago/api/resources/customers/payment_request'
|
|
20
21
|
require 'lago/api/resources/customers/subscription'
|
|
21
22
|
require 'lago/api/resources/customers/wallet'
|
|
23
|
+
require 'lago/api/resources/customers/wallets'
|
|
24
|
+
require 'lago/api/resources/customers/wallets/base'
|
|
25
|
+
require 'lago/api/resources/customers/wallets/alert'
|
|
26
|
+
require 'lago/api/resources/customers/wallets/metadata'
|
|
22
27
|
require 'lago/api/resources/event'
|
|
23
28
|
require 'lago/api/resources/feature'
|
|
24
29
|
require 'lago/api/resources/fee'
|
|
@@ -14,9 +14,20 @@ module Lago
|
|
|
14
14
|
'customer'
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def
|
|
17
|
+
def wallets
|
|
18
|
+
Customers::Wallets.new(client)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def current_usage( # rubocop:disable Metrics/ParameterLists
|
|
22
|
+
external_customer_id, external_subscription_id, apply_taxes: nil,
|
|
23
|
+
filter_by_charge_id: nil, filter_by_charge_code: nil, filter_by_group: nil, full_usage: nil
|
|
24
|
+
)
|
|
18
25
|
query_params = { external_subscription_id: external_subscription_id }
|
|
19
26
|
query_params[:apply_taxes] = apply_taxes unless apply_taxes.nil?
|
|
27
|
+
query_params[:filter_by_charge_id] = filter_by_charge_id unless filter_by_charge_id.nil?
|
|
28
|
+
query_params[:filter_by_charge_code] = filter_by_charge_code unless filter_by_charge_code.nil?
|
|
29
|
+
filter_by_group&.each { |k, v| query_params[:"filter_by_group[#{k}]"] = v }
|
|
30
|
+
query_params[:full_usage] = full_usage unless full_usage.nil?
|
|
20
31
|
query_string = URI.encode_www_form(query_params)
|
|
21
32
|
|
|
22
33
|
uri = URI("#{client.base_api_url}#{api_resource}/#{external_customer_id}/current_usage?#{query_string}")
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lago
|
|
4
|
+
module Api
|
|
5
|
+
module Resources
|
|
6
|
+
module Customers
|
|
7
|
+
class Wallets < Lago::Api::Resources::Nested
|
|
8
|
+
class Alert < Base
|
|
9
|
+
def create_batch(customer_id, wallet_code, params)
|
|
10
|
+
response = connection.post(
|
|
11
|
+
whitelist_create_batch_params(params),
|
|
12
|
+
api_resource(customer_id, wallet_code),
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
JSON.parse(response.to_json, object_class: OpenStruct).alerts
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def destroy_all(customer_id, wallet_code)
|
|
19
|
+
connection.destroy(
|
|
20
|
+
api_resource(customer_id, wallet_code),
|
|
21
|
+
identifier: nil,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def api_resource(customer_id, wallet_code)
|
|
30
|
+
"#{base_api_resource(customer_id, wallet_code)}/alerts"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def root_name
|
|
34
|
+
'alert'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def whitelist_create_params(params)
|
|
38
|
+
{ alert: create_alert_params(params) }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def whitelist_update_params(params)
|
|
42
|
+
{
|
|
43
|
+
alert: {
|
|
44
|
+
name: params[:name],
|
|
45
|
+
code: params[:code],
|
|
46
|
+
thresholds: params[:thresholds],
|
|
47
|
+
}.compact,
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def whitelist_create_batch_params(params)
|
|
52
|
+
params = params.is_a?(Hash) ? params[:alerts] : params
|
|
53
|
+
|
|
54
|
+
{ alerts: (params || []).map { |alert| create_alert_params(alert) } }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def create_alert_params(params)
|
|
58
|
+
{
|
|
59
|
+
alert_type: params[:alert_type],
|
|
60
|
+
name: params[:name],
|
|
61
|
+
code: params[:code],
|
|
62
|
+
thresholds: params[:thresholds],
|
|
63
|
+
}.compact
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def whitelist_thresholds(params)
|
|
67
|
+
(params || []).map do |p|
|
|
68
|
+
(p || {}).slice(:code, :value, :recurring)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lago
|
|
4
|
+
module Api
|
|
5
|
+
module Resources
|
|
6
|
+
module Customers
|
|
7
|
+
class Wallets < Lago::Api::Resources::Nested
|
|
8
|
+
class Base < Lago::Api::Resources::Nested
|
|
9
|
+
def base_api_resource(customer_id, wallet_code)
|
|
10
|
+
URI.join(client.base_api_url, "customers/#{customer_id}/wallets/#{wallet_code}")
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lago
|
|
4
|
+
module Api
|
|
5
|
+
module Resources
|
|
6
|
+
module Customers
|
|
7
|
+
class Wallets < Lago::Api::Resources::Nested
|
|
8
|
+
class Metadata < Base
|
|
9
|
+
def api_resource(customer_id, wallet_code)
|
|
10
|
+
"#{base_api_resource(customer_id, wallet_code)}/metadata"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def replace(customer_id, wallet_code, metadata)
|
|
14
|
+
path = api_resource(customer_id, wallet_code)
|
|
15
|
+
payload = { metadata: whitelist_params(metadata) }
|
|
16
|
+
response = connection.post(payload, path)
|
|
17
|
+
|
|
18
|
+
response['metadata']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def merge(customer_id, wallet_code, metadata)
|
|
22
|
+
path = api_resource(customer_id, wallet_code)
|
|
23
|
+
payload = { metadata: whitelist_params(metadata) }
|
|
24
|
+
response = connection.patch(path, identifier: nil, body: payload)
|
|
25
|
+
|
|
26
|
+
response['metadata']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def delete_all(customer_id, wallet_code)
|
|
30
|
+
path = api_resource(customer_id, wallet_code)
|
|
31
|
+
response = connection.destroy(path, identifier: nil)
|
|
32
|
+
|
|
33
|
+
response['metadata']
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def delete_key(customer_id, wallet_code, key)
|
|
37
|
+
path = api_resource(customer_id, wallet_code)
|
|
38
|
+
response = connection.destroy(path, identifier: key)
|
|
39
|
+
|
|
40
|
+
response['metadata']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def whitelist_params(params)
|
|
44
|
+
WhitelistParams.new.metadata(params)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lago
|
|
4
|
+
module Api
|
|
5
|
+
module Resources
|
|
6
|
+
module Customers
|
|
7
|
+
class Wallets < Lago::Api::Resources::Nested
|
|
8
|
+
class WhitelistParams
|
|
9
|
+
def wallet(params)
|
|
10
|
+
result_hash = params.compact.slice(
|
|
11
|
+
:external_customer_id,
|
|
12
|
+
:rate_amount,
|
|
13
|
+
:name,
|
|
14
|
+
:code,
|
|
15
|
+
:priority,
|
|
16
|
+
:paid_credits,
|
|
17
|
+
:granted_credits,
|
|
18
|
+
:currency,
|
|
19
|
+
:expiration_at,
|
|
20
|
+
:transaction_metadata,
|
|
21
|
+
:invoice_requires_successful_payment,
|
|
22
|
+
:ignore_paid_top_up_limits_on_creation,
|
|
23
|
+
:transaction_name,
|
|
24
|
+
:paid_top_up_min_amount_cents,
|
|
25
|
+
:paid_top_up_max_amount_cents,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
recurring_rules = recurring_rules_params(params[:recurring_transaction_rules])
|
|
29
|
+
result_hash[:recurring_transaction_rules] = recurring_rules if recurring_rules.any?
|
|
30
|
+
|
|
31
|
+
applies_to = applies_to_params(params[:applies_to])
|
|
32
|
+
result_hash[:applies_to] = applies_to if applies_to.any?
|
|
33
|
+
|
|
34
|
+
metadata = metadata(params[:metadata])
|
|
35
|
+
result_hash[:metadata] = metadata if metadata
|
|
36
|
+
|
|
37
|
+
payment_method = payment_method_params(params[:payment_method])
|
|
38
|
+
result_hash[:payment_method] = payment_method if payment_method.any?
|
|
39
|
+
|
|
40
|
+
invoice_custom_section = invoice_custom_section_params(params[:invoice_custom_section])
|
|
41
|
+
result_hash[:invoice_custom_section] = invoice_custom_section if invoice_custom_section
|
|
42
|
+
|
|
43
|
+
{ 'wallet' => result_hash }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def metadata(params)
|
|
47
|
+
return unless params
|
|
48
|
+
|
|
49
|
+
params.to_h.transform_keys(&:to_s).transform_values(&:to_s)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def recurring_rules_params(rules)
|
|
55
|
+
processed_rules = []
|
|
56
|
+
|
|
57
|
+
(rules || []).each do |r|
|
|
58
|
+
result = (r || {}).slice(
|
|
59
|
+
:lago_id,
|
|
60
|
+
:paid_credits,
|
|
61
|
+
:granted_credits,
|
|
62
|
+
:threshold_credits,
|
|
63
|
+
:invoice_requires_successful_payment,
|
|
64
|
+
:trigger,
|
|
65
|
+
:interval,
|
|
66
|
+
:method,
|
|
67
|
+
:started_at,
|
|
68
|
+
:expiration_at,
|
|
69
|
+
:target_ongoing_balance,
|
|
70
|
+
:transaction_metadata,
|
|
71
|
+
:transaction_name,
|
|
72
|
+
:ignore_paid_top_up_limits,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
payment_method = payment_method_params(r[:payment_method])
|
|
76
|
+
result[:payment_method] = payment_method if payment_method.any?
|
|
77
|
+
|
|
78
|
+
invoice_custom_section = invoice_custom_section_params(r[:invoice_custom_section])
|
|
79
|
+
result[:invoice_custom_section] = invoice_custom_section if invoice_custom_section
|
|
80
|
+
|
|
81
|
+
processed_rules << result unless result.empty?
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
processed_rules
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def applies_to_params(applies_to)
|
|
88
|
+
(applies_to || {}).slice(:fee_types, :billable_metric_codes)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def payment_method_params(payment_method)
|
|
92
|
+
(payment_method || {}).slice(:payment_method_type, :payment_method_id)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def invoice_custom_section_params(invoice_custom_section)
|
|
96
|
+
invoice_custom_section&.slice(:skip_invoice_custom_sections, :invoice_custom_section_codes)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'lago/api/resources/nested'
|
|
4
|
+
require 'lago/api/resources/customers/wallets/whitelist_params'
|
|
5
|
+
|
|
6
|
+
module Lago
|
|
7
|
+
module Api
|
|
8
|
+
module Resources
|
|
9
|
+
module Customers
|
|
10
|
+
class Wallets < Lago::Api::Resources::Nested
|
|
11
|
+
def api_resource(customer_id)
|
|
12
|
+
"#{client.base_api_url}customers/#{customer_id}/wallets"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def root_name
|
|
16
|
+
'wallet'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def whitelist_params(params)
|
|
20
|
+
Wallets::WhitelistParams.new.wallet(params)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def alerts
|
|
24
|
+
Wallets::Alert.new(client)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def metadata
|
|
28
|
+
Wallets::Metadata.new(client)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -132,7 +132,10 @@ module Lago
|
|
|
132
132
|
result[:fees] = fees unless fees.empty?
|
|
133
133
|
|
|
134
134
|
payment_method_params = whitelist_payment_method_params(params[:payment_method])
|
|
135
|
-
result[:payment_method] = payment_method_params if payment_method_params
|
|
135
|
+
result[:payment_method] = payment_method_params if payment_method_params
|
|
136
|
+
|
|
137
|
+
invoice_custom_section = whitelist_invoice_custom_section_params(params[:invoice_custom_section])
|
|
138
|
+
result[:invoice_custom_section] = invoice_custom_section if invoice_custom_section
|
|
136
139
|
|
|
137
140
|
{ root_name => result }
|
|
138
141
|
end
|
|
@@ -173,6 +176,10 @@ module Lago
|
|
|
173
176
|
def whitelist_payment_method_params(payment_method_param)
|
|
174
177
|
payment_method_param&.slice(:payment_method_type, :payment_method_id)
|
|
175
178
|
end
|
|
179
|
+
|
|
180
|
+
def whitelist_invoice_custom_section_params(invoice_custom_section_param)
|
|
181
|
+
invoice_custom_section_param&.slice(:skip_invoice_custom_sections, :invoice_custom_section_codes)
|
|
182
|
+
end
|
|
176
183
|
end
|
|
177
184
|
end
|
|
178
185
|
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'lago/api/resources/base'
|
|
4
|
+
|
|
5
|
+
module Lago
|
|
6
|
+
module Api
|
|
7
|
+
module Resources
|
|
8
|
+
class Nested < Base
|
|
9
|
+
def initialize(client)
|
|
10
|
+
super(client)
|
|
11
|
+
@connection = Lago::Api::Connection.new(client.api_key, client.base_api_url)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create(*parent_ids, params)
|
|
15
|
+
path = api_resource(*parent_ids)
|
|
16
|
+
payload = whitelist_create_params(params)
|
|
17
|
+
response = connection.post(payload, path)[root_name]
|
|
18
|
+
|
|
19
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get(*parent_ids, resource_id)
|
|
23
|
+
path = api_resource(*parent_ids)
|
|
24
|
+
response = connection.get(path, identifier: resource_id)[root_name]
|
|
25
|
+
|
|
26
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update(*parent_ids, resource_id, params)
|
|
30
|
+
path = api_resource(*parent_ids)
|
|
31
|
+
payload = whitelist_update_params(params)
|
|
32
|
+
response = connection.put(path, identifier: resource_id, body: payload)[root_name]
|
|
33
|
+
|
|
34
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def destroy(*parent_ids, resource_id)
|
|
38
|
+
path = api_resource(*parent_ids)
|
|
39
|
+
response = connection.destroy(path, identifier: resource_id)[root_name]
|
|
40
|
+
|
|
41
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_all(*parent_ids, **options)
|
|
45
|
+
path = api_resource(*parent_ids)
|
|
46
|
+
response = connection.get_all(options, path)
|
|
47
|
+
|
|
48
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
attr_reader :connection
|
|
54
|
+
|
|
55
|
+
def whitelist_update_params(params)
|
|
56
|
+
whitelist_params(params)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def whitelist_create_params(params)
|
|
60
|
+
whitelist_params(params)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -35,75 +35,89 @@ module Lago
|
|
|
35
35
|
JSON.parse(response.to_json, object_class: OpenStruct).lifetime_usage
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
def get_entitlements(external_subscription_id)
|
|
39
|
-
response = connection.get(entitlements_uri(external_subscription_id), identifier: nil)
|
|
38
|
+
def get_entitlements(external_subscription_id, subscription_status: nil)
|
|
39
|
+
response = connection.get(entitlements_uri(external_subscription_id, subscription_status:), identifier: nil)
|
|
40
40
|
JSON.parse(response.to_json, object_class: OpenStruct).entitlements
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def update_entitlements(external_subscription_id, params)
|
|
43
|
+
def update_entitlements(external_subscription_id, params, subscription_status: nil)
|
|
44
44
|
response = connection.patch(
|
|
45
|
-
entitlements_uri(external_subscription_id),
|
|
45
|
+
entitlements_uri(external_subscription_id, subscription_status:),
|
|
46
46
|
identifier: nil,
|
|
47
47
|
body: whitelist_entitlements_update_params(params),
|
|
48
48
|
)
|
|
49
49
|
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
def delete_entitlement(external_subscription_id, feature_code)
|
|
53
|
-
response = connection.destroy(
|
|
52
|
+
def delete_entitlement(external_subscription_id, feature_code, subscription_status: nil)
|
|
53
|
+
response = connection.destroy(
|
|
54
|
+
entitlements_uri(external_subscription_id, feature_code, subscription_status:),
|
|
55
|
+
identifier: nil,
|
|
56
|
+
)
|
|
54
57
|
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
55
58
|
end
|
|
56
59
|
|
|
57
|
-
def delete_entitlement_privilege(
|
|
60
|
+
def delete_entitlement_privilege(
|
|
61
|
+
external_subscription_id, entitlement_code, privilege_code,
|
|
62
|
+
subscription_status: nil
|
|
63
|
+
)
|
|
58
64
|
response = connection.destroy(
|
|
59
|
-
entitlements_uri(
|
|
65
|
+
entitlements_uri(
|
|
66
|
+
external_subscription_id,
|
|
67
|
+
entitlement_code,
|
|
68
|
+
"privileges/#{privilege_code}",
|
|
69
|
+
subscription_status:,
|
|
70
|
+
),
|
|
60
71
|
identifier: nil,
|
|
61
72
|
)
|
|
62
73
|
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
63
74
|
end
|
|
64
75
|
|
|
65
|
-
def get_alert(external_subscription_id, code)
|
|
66
|
-
response = connection.get(alert_uri(external_subscription_id, code), identifier: nil)
|
|
76
|
+
def get_alert(external_subscription_id, code, subscription_status: nil)
|
|
77
|
+
response = connection.get(alert_uri(external_subscription_id, code, subscription_status:), identifier: nil)
|
|
67
78
|
JSON.parse(response.to_json, object_class: OpenStruct).alert
|
|
68
79
|
end
|
|
69
80
|
|
|
70
|
-
def update_alert(external_subscription_id, code, params)
|
|
81
|
+
def update_alert(external_subscription_id, code, params, subscription_status: nil)
|
|
71
82
|
response = connection.put(
|
|
72
|
-
alert_uri(external_subscription_id, code),
|
|
83
|
+
alert_uri(external_subscription_id, code, subscription_status:),
|
|
73
84
|
identifier: nil,
|
|
74
85
|
body: whitelist_alert_update_params(params),
|
|
75
86
|
)
|
|
76
87
|
JSON.parse(response.to_json, object_class: OpenStruct).alert
|
|
77
88
|
end
|
|
78
89
|
|
|
79
|
-
def delete_alert(external_subscription_id, code)
|
|
80
|
-
response = connection.destroy(
|
|
90
|
+
def delete_alert(external_subscription_id, code, subscription_status: nil)
|
|
91
|
+
response = connection.destroy(
|
|
92
|
+
alert_uri(external_subscription_id, code, subscription_status:),
|
|
93
|
+
identifier: nil,
|
|
94
|
+
)
|
|
81
95
|
JSON.parse(response.to_json, object_class: OpenStruct).alert
|
|
82
96
|
end
|
|
83
97
|
|
|
84
|
-
def get_alerts(external_subscription_id)
|
|
85
|
-
response = connection.get(alert_uri(external_subscription_id), identifier: nil)
|
|
98
|
+
def get_alerts(external_subscription_id, subscription_status: nil)
|
|
99
|
+
response = connection.get(alert_uri(external_subscription_id, subscription_status:), identifier: nil)
|
|
86
100
|
JSON.parse(response.to_json, object_class: OpenStruct).alerts
|
|
87
101
|
end
|
|
88
102
|
|
|
89
|
-
def create_alert(external_subscription_id, params)
|
|
103
|
+
def create_alert(external_subscription_id, params, subscription_status: nil)
|
|
90
104
|
response = connection.post(
|
|
91
105
|
whitelist_alert_create_params(params),
|
|
92
|
-
alert_uri(external_subscription_id),
|
|
106
|
+
alert_uri(external_subscription_id, subscription_status:),
|
|
93
107
|
)
|
|
94
108
|
JSON.parse(response.to_json, object_class: OpenStruct).alert
|
|
95
109
|
end
|
|
96
110
|
|
|
97
|
-
def create_alerts(external_subscription_id, params)
|
|
111
|
+
def create_alerts(external_subscription_id, params, subscription_status: nil)
|
|
98
112
|
response = connection.post(
|
|
99
113
|
whitelist_alert_batch_create_params(params),
|
|
100
|
-
alert_uri(external_subscription_id),
|
|
114
|
+
alert_uri(external_subscription_id, subscription_status:),
|
|
101
115
|
)
|
|
102
116
|
JSON.parse(response.to_json, object_class: OpenStruct).alerts
|
|
103
117
|
end
|
|
104
118
|
|
|
105
|
-
def delete_alerts(external_subscription_id)
|
|
106
|
-
connection.destroy(alert_uri(external_subscription_id), identifier: nil)
|
|
119
|
+
def delete_alerts(external_subscription_id, subscription_status: nil)
|
|
120
|
+
connection.destroy(alert_uri(external_subscription_id, subscription_status:), identifier: nil)
|
|
107
121
|
end
|
|
108
122
|
|
|
109
123
|
# Charges
|
|
@@ -112,14 +126,14 @@ module Lago
|
|
|
112
126
|
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
113
127
|
end
|
|
114
128
|
|
|
115
|
-
def get_charge(external_id, charge_code)
|
|
116
|
-
response = connection.get(charges_uri(external_id, charge_code), identifier: nil)
|
|
129
|
+
def get_charge(external_id, charge_code, subscription_status: nil)
|
|
130
|
+
response = connection.get(charges_uri(external_id, charge_code, subscription_status:), identifier: nil)
|
|
117
131
|
JSON.parse(response.to_json, object_class: OpenStruct).charge
|
|
118
132
|
end
|
|
119
133
|
|
|
120
|
-
def update_charge(external_id, charge_code, params)
|
|
134
|
+
def update_charge(external_id, charge_code, params, subscription_status: nil)
|
|
121
135
|
response = connection.put(
|
|
122
|
-
charges_uri(external_id, charge_code),
|
|
136
|
+
charges_uri(external_id, charge_code, subscription_status:),
|
|
123
137
|
identifier: nil,
|
|
124
138
|
body: whitelist_subscription_charge_params(params),
|
|
125
139
|
)
|
|
@@ -132,14 +146,17 @@ module Lago
|
|
|
132
146
|
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
133
147
|
end
|
|
134
148
|
|
|
135
|
-
def get_fixed_charge(external_id, fixed_charge_code)
|
|
136
|
-
response = connection.get(
|
|
149
|
+
def get_fixed_charge(external_id, fixed_charge_code, subscription_status: nil)
|
|
150
|
+
response = connection.get(
|
|
151
|
+
fixed_charges_uri(external_id, fixed_charge_code, subscription_status:),
|
|
152
|
+
identifier: nil,
|
|
153
|
+
)
|
|
137
154
|
JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
|
|
138
155
|
end
|
|
139
156
|
|
|
140
|
-
def update_fixed_charge(external_id, fixed_charge_code, params)
|
|
157
|
+
def update_fixed_charge(external_id, fixed_charge_code, params, subscription_status: nil)
|
|
141
158
|
response = connection.put(
|
|
142
|
-
fixed_charges_uri(external_id, fixed_charge_code),
|
|
159
|
+
fixed_charges_uri(external_id, fixed_charge_code, subscription_status:),
|
|
143
160
|
identifier: nil,
|
|
144
161
|
body: whitelist_subscription_fixed_charge_params(params),
|
|
145
162
|
)
|
|
@@ -152,31 +169,34 @@ module Lago
|
|
|
152
169
|
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
153
170
|
end
|
|
154
171
|
|
|
155
|
-
def get_charge_filter(external_id, charge_code, filter_id)
|
|
156
|
-
response = connection.get(
|
|
172
|
+
def get_charge_filter(external_id, charge_code, filter_id, subscription_status: nil)
|
|
173
|
+
response = connection.get(
|
|
174
|
+
charge_filters_uri(external_id, charge_code, filter_id, subscription_status:),
|
|
175
|
+
identifier: nil,
|
|
176
|
+
)
|
|
157
177
|
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
158
178
|
end
|
|
159
179
|
|
|
160
|
-
def create_charge_filter(external_id, charge_code, params)
|
|
180
|
+
def create_charge_filter(external_id, charge_code, params, subscription_status: nil)
|
|
161
181
|
response = connection.post(
|
|
162
182
|
whitelist_subscription_charge_filter_params(params),
|
|
163
|
-
charge_filters_uri(external_id, charge_code),
|
|
183
|
+
charge_filters_uri(external_id, charge_code, subscription_status:),
|
|
164
184
|
)
|
|
165
185
|
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
166
186
|
end
|
|
167
187
|
|
|
168
|
-
def update_charge_filter(external_id, charge_code, filter_id, params)
|
|
188
|
+
def update_charge_filter(external_id, charge_code, filter_id, params, subscription_status: nil)
|
|
169
189
|
response = connection.put(
|
|
170
|
-
charge_filters_uri(external_id, charge_code, filter_id),
|
|
190
|
+
charge_filters_uri(external_id, charge_code, filter_id, subscription_status:),
|
|
171
191
|
identifier: nil,
|
|
172
192
|
body: whitelist_subscription_charge_filter_params(params),
|
|
173
193
|
)
|
|
174
194
|
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
175
195
|
end
|
|
176
196
|
|
|
177
|
-
def destroy_charge_filter(external_id, charge_code, filter_id)
|
|
197
|
+
def destroy_charge_filter(external_id, charge_code, filter_id, subscription_status: nil)
|
|
178
198
|
response = connection.destroy(
|
|
179
|
-
charge_filters_uri(external_id, charge_code, filter_id),
|
|
199
|
+
charge_filters_uri(external_id, charge_code, filter_id, subscription_status:),
|
|
180
200
|
identifier: nil,
|
|
181
201
|
)
|
|
182
202
|
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
@@ -195,7 +215,10 @@ module Lago
|
|
|
195
215
|
}.compact
|
|
196
216
|
|
|
197
217
|
payment_method_params = whitelist_payment_method_params(params[:payment_method])
|
|
198
|
-
result[:payment_method] = payment_method_params if payment_method_params
|
|
218
|
+
result[:payment_method] = payment_method_params if payment_method_params
|
|
219
|
+
|
|
220
|
+
invoice_custom_section = whitelist_invoice_custom_section_params(params[:invoice_custom_section])
|
|
221
|
+
result[:invoice_custom_section] = invoice_custom_section if invoice_custom_section
|
|
199
222
|
|
|
200
223
|
{ root_name => result }
|
|
201
224
|
end
|
|
@@ -263,33 +286,45 @@ module Lago
|
|
|
263
286
|
payment_method_param&.slice(:payment_method_type, :payment_method_id)
|
|
264
287
|
end
|
|
265
288
|
|
|
266
|
-
def
|
|
289
|
+
def whitelist_invoice_custom_section_params(invoice_custom_section_param)
|
|
290
|
+
invoice_custom_section_param&.slice(:skip_invoice_custom_sections, :invoice_custom_section_codes)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def append_status_query(url, subscription_status)
|
|
294
|
+
return url if subscription_status.nil?
|
|
295
|
+
|
|
296
|
+
separator = url.include?('?') ? '&' : '?'
|
|
297
|
+
"#{url}#{separator}subscription_status=#{subscription_status}"
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def entitlements_uri(external_subscription_id, feature_code = nil, action = nil, subscription_status: nil)
|
|
267
301
|
url = "#{client.base_api_url}#{api_resource}/#{external_subscription_id}/entitlements"
|
|
268
302
|
url += "/#{feature_code}" if feature_code
|
|
269
303
|
url += "/#{action}" if action
|
|
270
|
-
URI(url)
|
|
304
|
+
URI(append_status_query(url, subscription_status))
|
|
271
305
|
end
|
|
272
306
|
|
|
273
|
-
def alert_uri(external_subscription_id, code = nil)
|
|
274
|
-
|
|
307
|
+
def alert_uri(external_subscription_id, code = nil, subscription_status: nil)
|
|
308
|
+
url = "#{client.base_api_url}#{api_resource}/#{external_subscription_id}/alerts#{code ? "/#{code}" : ''}"
|
|
309
|
+
URI(append_status_query(url, subscription_status))
|
|
275
310
|
end
|
|
276
311
|
|
|
277
|
-
def charges_uri(external_id, charge_code = nil)
|
|
312
|
+
def charges_uri(external_id, charge_code = nil, subscription_status: nil)
|
|
278
313
|
url = "#{client.base_api_url}#{api_resource}/#{external_id}/charges"
|
|
279
314
|
url += "/#{charge_code}" if charge_code
|
|
280
|
-
URI(url)
|
|
315
|
+
URI(append_status_query(url, subscription_status))
|
|
281
316
|
end
|
|
282
317
|
|
|
283
|
-
def fixed_charges_uri(external_id, fixed_charge_code = nil)
|
|
318
|
+
def fixed_charges_uri(external_id, fixed_charge_code = nil, subscription_status: nil)
|
|
284
319
|
url = "#{client.base_api_url}#{api_resource}/#{external_id}/fixed_charges"
|
|
285
320
|
url += "/#{fixed_charge_code}" if fixed_charge_code
|
|
286
|
-
URI(url)
|
|
321
|
+
URI(append_status_query(url, subscription_status))
|
|
287
322
|
end
|
|
288
323
|
|
|
289
|
-
def charge_filters_uri(external_id, charge_code, filter_id = nil)
|
|
324
|
+
def charge_filters_uri(external_id, charge_code, filter_id = nil, subscription_status: nil)
|
|
290
325
|
url = "#{client.base_api_url}#{api_resource}/#{external_id}/charges/#{charge_code}/filters"
|
|
291
326
|
url += "/#{filter_id}" if filter_id
|
|
292
|
-
URI(url)
|
|
327
|
+
URI(append_status_query(url, subscription_status))
|
|
293
328
|
end
|
|
294
329
|
|
|
295
330
|
def whitelist_subscription_charge_params(params)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'lago/api/resources/base'
|
|
4
|
+
require 'lago/api/resources/customers/wallets/whitelist_params'
|
|
4
5
|
|
|
5
6
|
module Lago
|
|
6
7
|
module Api
|
|
@@ -15,71 +16,7 @@ module Lago
|
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def whitelist_params(params)
|
|
18
|
-
|
|
19
|
-
:external_customer_id,
|
|
20
|
-
:rate_amount,
|
|
21
|
-
:name,
|
|
22
|
-
:code,
|
|
23
|
-
:priority,
|
|
24
|
-
:paid_credits,
|
|
25
|
-
:granted_credits,
|
|
26
|
-
:currency,
|
|
27
|
-
:expiration_at,
|
|
28
|
-
:transaction_metadata,
|
|
29
|
-
:invoice_requires_successful_payment,
|
|
30
|
-
:ignore_paid_top_up_limits_on_creation,
|
|
31
|
-
:transaction_name,
|
|
32
|
-
:paid_top_up_min_amount_cents,
|
|
33
|
-
:paid_top_up_max_amount_cents
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
recurring_rules = whitelist_recurring_rules(params[:recurring_transaction_rules])
|
|
37
|
-
result_hash[:recurring_transaction_rules] = recurring_rules if recurring_rules.any?
|
|
38
|
-
|
|
39
|
-
applies_to = whitelist_applies_to(params[:applies_to])
|
|
40
|
-
result_hash[:applies_to] = applies_to if applies_to.any?
|
|
41
|
-
|
|
42
|
-
metadata = whitelist_metadata(params[:metadata])
|
|
43
|
-
result_hash[:metadata] = metadata if metadata
|
|
44
|
-
|
|
45
|
-
payment_method_params = whitelist_payment_method_params(params[:payment_method])
|
|
46
|
-
result_hash[:payment_method] = payment_method_params if payment_method_params.present?
|
|
47
|
-
|
|
48
|
-
{ root_name => result_hash }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def whitelist_recurring_rules(rules)
|
|
52
|
-
processed_rules = []
|
|
53
|
-
|
|
54
|
-
(rules || []).each do |r|
|
|
55
|
-
result = (r || {}).slice(
|
|
56
|
-
:lago_id,
|
|
57
|
-
:paid_credits,
|
|
58
|
-
:granted_credits,
|
|
59
|
-
:threshold_credits,
|
|
60
|
-
:invoice_requires_successful_payment,
|
|
61
|
-
:trigger,
|
|
62
|
-
:interval,
|
|
63
|
-
:method,
|
|
64
|
-
:started_at,
|
|
65
|
-
:expiration_at,
|
|
66
|
-
:target_ongoing_balance,
|
|
67
|
-
:transaction_metadata,
|
|
68
|
-
:transaction_name,
|
|
69
|
-
:ignore_paid_top_up_limits
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
payment_method_params = whitelist_payment_method_params(r[:payment_method])
|
|
73
|
-
result[:payment_method] = payment_method_params if payment_method_params.present?
|
|
74
|
-
|
|
75
|
-
processed_rules << result unless result.empty?
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
processed_rules
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def whitelist_applies_to(applies_to_params)
|
|
82
|
-
(applies_to_params || {}).slice(:fee_types, :billable_metric_codes)
|
|
19
|
+
Customers::Wallets::WhitelistParams.new.wallet(params)
|
|
83
20
|
end
|
|
84
21
|
|
|
85
22
|
def whitelist_metadata(metadata)
|
|
@@ -28,6 +28,20 @@ module Lago
|
|
|
28
28
|
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def consumptions(wallet_transaction_id, options = {})
|
|
32
|
+
path = "/api/v1/wallet_transactions/#{wallet_transaction_id}/consumptions"
|
|
33
|
+
response = connection.get_all(options, path)
|
|
34
|
+
|
|
35
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def fundings(wallet_transaction_id, options = {})
|
|
39
|
+
path = "/api/v1/wallet_transactions/#{wallet_transaction_id}/fundings"
|
|
40
|
+
response = connection.get_all(options, path)
|
|
41
|
+
|
|
42
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
43
|
+
end
|
|
44
|
+
|
|
31
45
|
def whitelist_params(params)
|
|
32
46
|
result = params.compact.slice(
|
|
33
47
|
:wallet_id,
|
|
@@ -41,7 +55,10 @@ module Lago
|
|
|
41
55
|
)
|
|
42
56
|
|
|
43
57
|
payment_method_params = whitelist_payment_method_params(params[:payment_method])
|
|
44
|
-
result[:payment_method] = payment_method_params if payment_method_params
|
|
58
|
+
result[:payment_method] = payment_method_params if payment_method_params
|
|
59
|
+
|
|
60
|
+
invoice_custom_section = whitelist_invoice_custom_section_params(params[:invoice_custom_section])
|
|
61
|
+
result[:invoice_custom_section] = invoice_custom_section if invoice_custom_section
|
|
45
62
|
|
|
46
63
|
{ 'wallet_transaction' => result }
|
|
47
64
|
end
|
|
@@ -51,6 +68,10 @@ module Lago
|
|
|
51
68
|
def whitelist_payment_method_params(payment_method_param)
|
|
52
69
|
payment_method_param&.slice(:payment_method_type, :payment_method_id)
|
|
53
70
|
end
|
|
71
|
+
|
|
72
|
+
def whitelist_invoice_custom_section_params(invoice_custom_section_param)
|
|
73
|
+
invoice_custom_section_param&.slice(:skip_invoice_custom_sections, :invoice_custom_section_codes)
|
|
74
|
+
end
|
|
54
75
|
end
|
|
55
76
|
end
|
|
56
77
|
end
|
data/lib/lago/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lago-ruby-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.44.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lovro Colic
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-03-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jwt
|
|
@@ -306,6 +306,11 @@ files:
|
|
|
306
306
|
- lib/lago/api/resources/customers/payment_request.rb
|
|
307
307
|
- lib/lago/api/resources/customers/subscription.rb
|
|
308
308
|
- lib/lago/api/resources/customers/wallet.rb
|
|
309
|
+
- lib/lago/api/resources/customers/wallets.rb
|
|
310
|
+
- lib/lago/api/resources/customers/wallets/alert.rb
|
|
311
|
+
- lib/lago/api/resources/customers/wallets/base.rb
|
|
312
|
+
- lib/lago/api/resources/customers/wallets/metadata.rb
|
|
313
|
+
- lib/lago/api/resources/customers/wallets/whitelist_params.rb
|
|
309
314
|
- lib/lago/api/resources/event.rb
|
|
310
315
|
- lib/lago/api/resources/feature.rb
|
|
311
316
|
- lib/lago/api/resources/fee.rb
|
|
@@ -314,6 +319,7 @@ files:
|
|
|
314
319
|
- lib/lago/api/resources/invoice_collection.rb
|
|
315
320
|
- lib/lago/api/resources/invoiced_usage.rb
|
|
316
321
|
- lib/lago/api/resources/mrr.rb
|
|
322
|
+
- lib/lago/api/resources/nested.rb
|
|
317
323
|
- lib/lago/api/resources/organization.rb
|
|
318
324
|
- lib/lago/api/resources/overdue_balance.rb
|
|
319
325
|
- lib/lago/api/resources/payment.rb
|