lago-ruby-client 1.40.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 +10 -0
- data/lib/lago/api/resources/customer.rb +12 -1
- data/lib/lago/api/resources/customers/payment_method.rb +36 -0
- 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 +21 -2
- data/lib/lago/api/resources/nested.rb +65 -0
- data/lib/lago/api/resources/plan.rb +182 -0
- data/lib/lago/api/resources/subscription.rb +230 -41
- data/lib/lago/api/resources/wallet.rb +8 -58
- data/lib/lago/api/resources/wallet_transaction.rb +42 -12
- data/lib/lago/version.rb +1 -1
- metadata +9 -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'
|
|
@@ -15,9 +16,14 @@ require 'lago/api/resources/customers/applied_coupon'
|
|
|
15
16
|
require 'lago/api/resources/customers/credit_note'
|
|
16
17
|
require 'lago/api/resources/customers/invoice'
|
|
17
18
|
require 'lago/api/resources/customers/payment'
|
|
19
|
+
require 'lago/api/resources/customers/payment_method'
|
|
18
20
|
require 'lago/api/resources/customers/payment_request'
|
|
19
21
|
require 'lago/api/resources/customers/subscription'
|
|
20
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'
|
|
21
27
|
require 'lago/api/resources/event'
|
|
22
28
|
require 'lago/api/resources/feature'
|
|
23
29
|
require 'lago/api/resources/fee'
|
|
@@ -122,6 +128,10 @@ module Lago
|
|
|
122
128
|
Resources::Customers::Payment.new(self, resource_id)
|
|
123
129
|
end
|
|
124
130
|
|
|
131
|
+
def customer_payment_methods(resource_id)
|
|
132
|
+
Resources::Customers::PaymentMethod.new(self, resource_id)
|
|
133
|
+
end
|
|
134
|
+
|
|
125
135
|
def customer_payment_requests(resource_id)
|
|
126
136
|
Resources::Customers::PaymentRequest.new(self, resource_id)
|
|
127
137
|
end
|
|
@@ -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,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'lago/api/resources/customers/base'
|
|
4
|
+
|
|
5
|
+
module Lago
|
|
6
|
+
module Api
|
|
7
|
+
module Resources
|
|
8
|
+
module Customers
|
|
9
|
+
class PaymentMethod < Base
|
|
10
|
+
def api_resource
|
|
11
|
+
"#{base_api_resource}/payment_methods"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def root_name
|
|
15
|
+
'payment_method'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def destroy(id, options: nil)
|
|
19
|
+
response = connection.destroy(identifier: id, options:)[root_name]
|
|
20
|
+
|
|
21
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# rubocop:disable Naming/AccessorMethodName
|
|
25
|
+
def set_as_default(payment_method_id)
|
|
26
|
+
path = "/api/v1/#{api_resource}/#{payment_method_id}/set_as_default"
|
|
27
|
+
response = connection.put(path, identifier: nil, body: {})[root_name]
|
|
28
|
+
|
|
29
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
30
|
+
end
|
|
31
|
+
# rubocop:enable Naming/AccessorMethodName
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -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
|
|
@@ -59,9 +59,12 @@ module Lago
|
|
|
59
59
|
JSON.parse(response.to_json, object_class: OpenStruct).invoice
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
def retry_payment(invoice_id)
|
|
62
|
+
def retry_payment(invoice_id, params = {})
|
|
63
63
|
path = "/api/v1/invoices/#{invoice_id}/retry_payment"
|
|
64
|
-
|
|
64
|
+
payment_method_params = whitelist_payment_method_params(params[:payment_method])
|
|
65
|
+
payload = { payment_method: payment_method_params }.compact
|
|
66
|
+
|
|
67
|
+
response = connection.post(payload, path)
|
|
65
68
|
|
|
66
69
|
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
67
70
|
end
|
|
@@ -128,6 +131,12 @@ module Lago
|
|
|
128
131
|
fees = whitelist_fees(params[:fees])
|
|
129
132
|
result[:fees] = fees unless fees.empty?
|
|
130
133
|
|
|
134
|
+
payment_method_params = whitelist_payment_method_params(params[:payment_method])
|
|
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
|
|
139
|
+
|
|
131
140
|
{ root_name => result }
|
|
132
141
|
end
|
|
133
142
|
|
|
@@ -161,6 +170,16 @@ module Lago
|
|
|
161
170
|
credit_amount: params[:credit_amount]
|
|
162
171
|
}.compact
|
|
163
172
|
end
|
|
173
|
+
|
|
174
|
+
private
|
|
175
|
+
|
|
176
|
+
def whitelist_payment_method_params(payment_method_param)
|
|
177
|
+
payment_method_param&.slice(:payment_method_type, :payment_method_id)
|
|
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
|
|
164
183
|
end
|
|
165
184
|
end
|
|
166
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
|
|
@@ -54,6 +54,117 @@ module Lago
|
|
|
54
54
|
JSON.parse(response.to_json, object_class: OpenStruct).entitlement
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
# Charges
|
|
58
|
+
def get_all_charges(plan_code, options = {})
|
|
59
|
+
response = connection.get_all(options, charges_uri(plan_code))
|
|
60
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def get_charge(plan_code, charge_code)
|
|
64
|
+
response = connection.get(charges_uri(plan_code, charge_code), identifier: nil)
|
|
65
|
+
JSON.parse(response.to_json, object_class: OpenStruct).charge
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def create_charge(plan_code, params)
|
|
69
|
+
response = connection.post(
|
|
70
|
+
whitelist_charge_params(params),
|
|
71
|
+
charges_uri(plan_code),
|
|
72
|
+
)
|
|
73
|
+
JSON.parse(response.to_json, object_class: OpenStruct).charge
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def update_charge(plan_code, charge_code, params)
|
|
77
|
+
response = connection.put(
|
|
78
|
+
charges_uri(plan_code, charge_code),
|
|
79
|
+
identifier: nil,
|
|
80
|
+
body: whitelist_charge_params(params),
|
|
81
|
+
)
|
|
82
|
+
JSON.parse(response.to_json, object_class: OpenStruct).charge
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def destroy_charge(plan_code, charge_code, params = {})
|
|
86
|
+
response = connection.destroy(
|
|
87
|
+
charges_uri(plan_code, charge_code),
|
|
88
|
+
identifier: nil,
|
|
89
|
+
options: params.empty? ? nil : params,
|
|
90
|
+
)
|
|
91
|
+
JSON.parse(response.to_json, object_class: OpenStruct).charge
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Fixed Charges
|
|
95
|
+
def get_all_fixed_charges(plan_code, options = {})
|
|
96
|
+
response = connection.get_all(options, fixed_charges_uri(plan_code))
|
|
97
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def get_fixed_charge(plan_code, fixed_charge_code)
|
|
101
|
+
response = connection.get(fixed_charges_uri(plan_code, fixed_charge_code), identifier: nil)
|
|
102
|
+
JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def create_fixed_charge(plan_code, params)
|
|
106
|
+
response = connection.post(
|
|
107
|
+
whitelist_fixed_charge_params(params),
|
|
108
|
+
fixed_charges_uri(plan_code),
|
|
109
|
+
)
|
|
110
|
+
JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def update_fixed_charge(plan_code, fixed_charge_code, params)
|
|
114
|
+
response = connection.put(
|
|
115
|
+
fixed_charges_uri(plan_code, fixed_charge_code),
|
|
116
|
+
identifier: nil,
|
|
117
|
+
body: whitelist_fixed_charge_params(params),
|
|
118
|
+
)
|
|
119
|
+
JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def destroy_fixed_charge(plan_code, fixed_charge_code, params = {})
|
|
123
|
+
response = connection.destroy(
|
|
124
|
+
fixed_charges_uri(plan_code, fixed_charge_code),
|
|
125
|
+
identifier: nil,
|
|
126
|
+
options: params.empty? ? nil : params,
|
|
127
|
+
)
|
|
128
|
+
JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Charge Filters
|
|
132
|
+
def get_all_charge_filters(plan_code, charge_code, options = {})
|
|
133
|
+
response = connection.get_all(options, charge_filters_uri(plan_code, charge_code))
|
|
134
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def get_charge_filter(plan_code, charge_code, filter_id)
|
|
138
|
+
response = connection.get(charge_filters_uri(plan_code, charge_code, filter_id), identifier: nil)
|
|
139
|
+
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def create_charge_filter(plan_code, charge_code, params)
|
|
143
|
+
response = connection.post(
|
|
144
|
+
whitelist_charge_filter_params(params),
|
|
145
|
+
charge_filters_uri(plan_code, charge_code),
|
|
146
|
+
)
|
|
147
|
+
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def update_charge_filter(plan_code, charge_code, filter_id, params)
|
|
151
|
+
response = connection.put(
|
|
152
|
+
charge_filters_uri(plan_code, charge_code, filter_id),
|
|
153
|
+
identifier: nil,
|
|
154
|
+
body: whitelist_charge_filter_params(params),
|
|
155
|
+
)
|
|
156
|
+
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def destroy_charge_filter(plan_code, charge_code, filter_id, params = {})
|
|
160
|
+
response = connection.destroy(
|
|
161
|
+
charge_filters_uri(plan_code, charge_code, filter_id),
|
|
162
|
+
identifier: nil,
|
|
163
|
+
options: params.empty? ? nil : params,
|
|
164
|
+
)
|
|
165
|
+
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
166
|
+
end
|
|
167
|
+
|
|
57
168
|
def whitelist_params(params)
|
|
58
169
|
result_hash = {
|
|
59
170
|
name: params[:name],
|
|
@@ -119,6 +230,7 @@ module Lago
|
|
|
119
230
|
:filters,
|
|
120
231
|
:tax_codes,
|
|
121
232
|
:applied_pricing_unit,
|
|
233
|
+
:accepts_target_wallet,
|
|
122
234
|
)
|
|
123
235
|
|
|
124
236
|
processed_charges << result unless result.empty?
|
|
@@ -216,6 +328,76 @@ module Lago
|
|
|
216
328
|
url += "/#{action}" if action
|
|
217
329
|
URI(url)
|
|
218
330
|
end
|
|
331
|
+
|
|
332
|
+
def charges_uri(plan_code, charge_code = nil)
|
|
333
|
+
url = "#{client.base_api_url}#{api_resource}/#{plan_code}/charges"
|
|
334
|
+
url += "/#{charge_code}" if charge_code
|
|
335
|
+
URI(url)
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def fixed_charges_uri(plan_code, fixed_charge_code = nil)
|
|
339
|
+
url = "#{client.base_api_url}#{api_resource}/#{plan_code}/fixed_charges"
|
|
340
|
+
url += "/#{fixed_charge_code}" if fixed_charge_code
|
|
341
|
+
URI(url)
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
def charge_filters_uri(plan_code, charge_code, filter_id = nil)
|
|
345
|
+
url = "#{client.base_api_url}#{api_resource}/#{plan_code}/charges/#{charge_code}/filters"
|
|
346
|
+
url += "/#{filter_id}" if filter_id
|
|
347
|
+
URI(url)
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def whitelist_charge_params(params)
|
|
351
|
+
{
|
|
352
|
+
charge: (params || {}).slice(
|
|
353
|
+
:billable_metric_id,
|
|
354
|
+
:code,
|
|
355
|
+
:invoice_display_name,
|
|
356
|
+
:charge_model,
|
|
357
|
+
:pay_in_advance,
|
|
358
|
+
:prorated,
|
|
359
|
+
:invoiceable,
|
|
360
|
+
:regroup_paid_fees,
|
|
361
|
+
:min_amount_cents,
|
|
362
|
+
:accepts_target_wallet,
|
|
363
|
+
:properties,
|
|
364
|
+
:filters,
|
|
365
|
+
:tax_codes,
|
|
366
|
+
:applied_pricing_unit,
|
|
367
|
+
:cascade_updates,
|
|
368
|
+
),
|
|
369
|
+
}
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
def whitelist_fixed_charge_params(params)
|
|
373
|
+
{
|
|
374
|
+
fixed_charge: (params || {}).slice(
|
|
375
|
+
:add_on_id,
|
|
376
|
+
:add_on_code,
|
|
377
|
+
:code,
|
|
378
|
+
:invoice_display_name,
|
|
379
|
+
:charge_model,
|
|
380
|
+
:pay_in_advance,
|
|
381
|
+
:prorated,
|
|
382
|
+
:units,
|
|
383
|
+
:apply_units_immediately,
|
|
384
|
+
:properties,
|
|
385
|
+
:tax_codes,
|
|
386
|
+
:cascade_updates,
|
|
387
|
+
),
|
|
388
|
+
}
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
def whitelist_charge_filter_params(params)
|
|
392
|
+
{
|
|
393
|
+
filter: (params || {}).slice(
|
|
394
|
+
:invoice_display_name,
|
|
395
|
+
:properties,
|
|
396
|
+
:values,
|
|
397
|
+
:cascade_updates,
|
|
398
|
+
),
|
|
399
|
+
}
|
|
400
|
+
end
|
|
219
401
|
end
|
|
220
402
|
end
|
|
221
403
|
end
|
|
@@ -35,86 +35,192 @@ 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
|
|
90
|
-
|
|
91
|
-
|
|
103
|
+
def create_alert(external_subscription_id, params, subscription_status: nil)
|
|
104
|
+
response = connection.post(
|
|
105
|
+
whitelist_alert_create_params(params),
|
|
106
|
+
alert_uri(external_subscription_id, subscription_status:),
|
|
92
107
|
)
|
|
93
|
-
response
|
|
94
|
-
JSON.parse(response.to_json, object_class: OpenStruct).fixed_charges
|
|
108
|
+
JSON.parse(response.to_json, object_class: OpenStruct).alert
|
|
95
109
|
end
|
|
96
110
|
|
|
97
|
-
def
|
|
111
|
+
def create_alerts(external_subscription_id, params, subscription_status: nil)
|
|
98
112
|
response = connection.post(
|
|
99
|
-
|
|
100
|
-
alert_uri(external_subscription_id),
|
|
113
|
+
whitelist_alert_batch_create_params(params),
|
|
114
|
+
alert_uri(external_subscription_id, subscription_status:),
|
|
101
115
|
)
|
|
102
|
-
JSON.parse(response.to_json, object_class: OpenStruct).
|
|
116
|
+
JSON.parse(response.to_json, object_class: OpenStruct).alerts
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def delete_alerts(external_subscription_id, subscription_status: nil)
|
|
120
|
+
connection.destroy(alert_uri(external_subscription_id, subscription_status:), identifier: nil)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Charges
|
|
124
|
+
def get_all_charges(external_id, options = {})
|
|
125
|
+
response = connection.get_all(options, charges_uri(external_id))
|
|
126
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
127
|
+
end
|
|
128
|
+
|
|
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)
|
|
131
|
+
JSON.parse(response.to_json, object_class: OpenStruct).charge
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def update_charge(external_id, charge_code, params, subscription_status: nil)
|
|
135
|
+
response = connection.put(
|
|
136
|
+
charges_uri(external_id, charge_code, subscription_status:),
|
|
137
|
+
identifier: nil,
|
|
138
|
+
body: whitelist_subscription_charge_params(params),
|
|
139
|
+
)
|
|
140
|
+
JSON.parse(response.to_json, object_class: OpenStruct).charge
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Fixed Charges
|
|
144
|
+
def get_all_fixed_charges(external_id, options = {})
|
|
145
|
+
response = connection.get_all(options, fixed_charges_uri(external_id))
|
|
146
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
147
|
+
end
|
|
148
|
+
|
|
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
|
+
)
|
|
154
|
+
JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def update_fixed_charge(external_id, fixed_charge_code, params, subscription_status: nil)
|
|
158
|
+
response = connection.put(
|
|
159
|
+
fixed_charges_uri(external_id, fixed_charge_code, subscription_status:),
|
|
160
|
+
identifier: nil,
|
|
161
|
+
body: whitelist_subscription_fixed_charge_params(params),
|
|
162
|
+
)
|
|
163
|
+
JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Charge Filters
|
|
167
|
+
def get_all_charge_filters(external_id, charge_code, options = {})
|
|
168
|
+
response = connection.get_all(options, charge_filters_uri(external_id, charge_code))
|
|
169
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
|
170
|
+
end
|
|
171
|
+
|
|
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
|
+
)
|
|
177
|
+
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def create_charge_filter(external_id, charge_code, params, subscription_status: nil)
|
|
181
|
+
response = connection.post(
|
|
182
|
+
whitelist_subscription_charge_filter_params(params),
|
|
183
|
+
charge_filters_uri(external_id, charge_code, subscription_status:),
|
|
184
|
+
)
|
|
185
|
+
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def update_charge_filter(external_id, charge_code, filter_id, params, subscription_status: nil)
|
|
189
|
+
response = connection.put(
|
|
190
|
+
charge_filters_uri(external_id, charge_code, filter_id, subscription_status:),
|
|
191
|
+
identifier: nil,
|
|
192
|
+
body: whitelist_subscription_charge_filter_params(params),
|
|
193
|
+
)
|
|
194
|
+
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def destroy_charge_filter(external_id, charge_code, filter_id, subscription_status: nil)
|
|
198
|
+
response = connection.destroy(
|
|
199
|
+
charge_filters_uri(external_id, charge_code, filter_id, subscription_status:),
|
|
200
|
+
identifier: nil,
|
|
201
|
+
)
|
|
202
|
+
JSON.parse(response.to_json, object_class: OpenStruct).filter
|
|
103
203
|
end
|
|
104
204
|
|
|
105
205
|
def whitelist_params(params)
|
|
106
|
-
{
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
206
|
+
result = {
|
|
207
|
+
external_customer_id: params[:external_customer_id],
|
|
208
|
+
plan_code: params[:plan_code],
|
|
209
|
+
name: params[:name],
|
|
210
|
+
external_id: params[:external_id],
|
|
211
|
+
billing_time: params[:billing_time],
|
|
212
|
+
subscription_at: params[:subscription_at],
|
|
213
|
+
ending_at: params[:ending_at],
|
|
214
|
+
plan_overrides: params[:plan_overrides],
|
|
215
|
+
}.compact
|
|
216
|
+
|
|
217
|
+
payment_method_params = whitelist_payment_method_params(params[:payment_method])
|
|
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
|
|
222
|
+
|
|
223
|
+
{ root_name => result }
|
|
118
224
|
end
|
|
119
225
|
|
|
120
226
|
def whitelist_lifetime_usage_params(params)
|
|
@@ -137,6 +243,20 @@ module Lago
|
|
|
137
243
|
}
|
|
138
244
|
end
|
|
139
245
|
|
|
246
|
+
def whitelist_alert_batch_create_params(params)
|
|
247
|
+
{
|
|
248
|
+
alerts: (params[:alerts] || []).map do |alert|
|
|
249
|
+
{
|
|
250
|
+
alert_type: alert[:alert_type],
|
|
251
|
+
name: alert[:name],
|
|
252
|
+
code: alert[:code],
|
|
253
|
+
billable_metric_code: alert[:billable_metric_code],
|
|
254
|
+
thresholds: alert[:thresholds],
|
|
255
|
+
}.compact
|
|
256
|
+
end,
|
|
257
|
+
}
|
|
258
|
+
end
|
|
259
|
+
|
|
140
260
|
def whitelist_alert_update_params(params)
|
|
141
261
|
{
|
|
142
262
|
alert: {
|
|
@@ -162,15 +282,84 @@ module Lago
|
|
|
162
282
|
|
|
163
283
|
private
|
|
164
284
|
|
|
165
|
-
def
|
|
285
|
+
def whitelist_payment_method_params(payment_method_param)
|
|
286
|
+
payment_method_param&.slice(:payment_method_type, :payment_method_id)
|
|
287
|
+
end
|
|
288
|
+
|
|
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)
|
|
166
301
|
url = "#{client.base_api_url}#{api_resource}/#{external_subscription_id}/entitlements"
|
|
167
302
|
url += "/#{feature_code}" if feature_code
|
|
168
303
|
url += "/#{action}" if action
|
|
169
|
-
URI(url)
|
|
304
|
+
URI(append_status_query(url, subscription_status))
|
|
305
|
+
end
|
|
306
|
+
|
|
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))
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def charges_uri(external_id, charge_code = nil, subscription_status: nil)
|
|
313
|
+
url = "#{client.base_api_url}#{api_resource}/#{external_id}/charges"
|
|
314
|
+
url += "/#{charge_code}" if charge_code
|
|
315
|
+
URI(append_status_query(url, subscription_status))
|
|
170
316
|
end
|
|
171
317
|
|
|
172
|
-
def
|
|
173
|
-
|
|
318
|
+
def fixed_charges_uri(external_id, fixed_charge_code = nil, subscription_status: nil)
|
|
319
|
+
url = "#{client.base_api_url}#{api_resource}/#{external_id}/fixed_charges"
|
|
320
|
+
url += "/#{fixed_charge_code}" if fixed_charge_code
|
|
321
|
+
URI(append_status_query(url, subscription_status))
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def charge_filters_uri(external_id, charge_code, filter_id = nil, subscription_status: nil)
|
|
325
|
+
url = "#{client.base_api_url}#{api_resource}/#{external_id}/charges/#{charge_code}/filters"
|
|
326
|
+
url += "/#{filter_id}" if filter_id
|
|
327
|
+
URI(append_status_query(url, subscription_status))
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def whitelist_subscription_charge_params(params)
|
|
331
|
+
{
|
|
332
|
+
charge: (params || {}).slice(
|
|
333
|
+
:invoice_display_name,
|
|
334
|
+
:min_amount_cents,
|
|
335
|
+
:properties,
|
|
336
|
+
:filters,
|
|
337
|
+
:tax_codes,
|
|
338
|
+
:applied_pricing_unit,
|
|
339
|
+
),
|
|
340
|
+
}
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
def whitelist_subscription_fixed_charge_params(params)
|
|
344
|
+
{
|
|
345
|
+
fixed_charge: (params || {}).slice(
|
|
346
|
+
:invoice_display_name,
|
|
347
|
+
:units,
|
|
348
|
+
:apply_units_immediately,
|
|
349
|
+
:properties,
|
|
350
|
+
:tax_codes,
|
|
351
|
+
),
|
|
352
|
+
}
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
def whitelist_subscription_charge_filter_params(params)
|
|
356
|
+
{
|
|
357
|
+
filter: (params || {}).slice(
|
|
358
|
+
:invoice_display_name,
|
|
359
|
+
:properties,
|
|
360
|
+
:values,
|
|
361
|
+
),
|
|
362
|
+
}
|
|
174
363
|
end
|
|
175
364
|
end
|
|
176
365
|
end
|
|
@@ -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,64 +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
|
-
:priority,
|
|
23
|
-
:paid_credits,
|
|
24
|
-
:granted_credits,
|
|
25
|
-
:currency,
|
|
26
|
-
:expiration_at,
|
|
27
|
-
:transaction_metadata,
|
|
28
|
-
:invoice_requires_successful_payment,
|
|
29
|
-
:ignore_paid_top_up_limits_on_creation,
|
|
30
|
-
:transaction_name,
|
|
31
|
-
:paid_top_up_min_amount_cents,
|
|
32
|
-
:paid_top_up_max_amount_cents
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
recurring_rules = whitelist_recurring_rules(params[:recurring_transaction_rules])
|
|
36
|
-
result_hash[:recurring_transaction_rules] = recurring_rules if recurring_rules.any?
|
|
37
|
-
|
|
38
|
-
applies_to = whitelist_applies_to(params[:applies_to])
|
|
39
|
-
result_hash[:applies_to] = applies_to if applies_to.any?
|
|
40
|
-
|
|
41
|
-
metadata = whitelist_metadata(params[:metadata])
|
|
42
|
-
result_hash[:metadata] = metadata if metadata
|
|
43
|
-
|
|
44
|
-
{ root_name => result_hash }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def whitelist_recurring_rules(rules)
|
|
48
|
-
processed_rules = []
|
|
49
|
-
|
|
50
|
-
(rules || []).each do |r|
|
|
51
|
-
result = (r || {}).slice(
|
|
52
|
-
:lago_id,
|
|
53
|
-
:paid_credits,
|
|
54
|
-
:granted_credits,
|
|
55
|
-
:threshold_credits,
|
|
56
|
-
:invoice_requires_successful_payment,
|
|
57
|
-
:trigger,
|
|
58
|
-
:interval,
|
|
59
|
-
:method,
|
|
60
|
-
:started_at,
|
|
61
|
-
:expiration_at,
|
|
62
|
-
:target_ongoing_balance,
|
|
63
|
-
:transaction_metadata,
|
|
64
|
-
:transaction_name,
|
|
65
|
-
:ignore_paid_top_up_limits
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
processed_rules << result unless result.empty?
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
processed_rules
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def whitelist_applies_to(applies_to_params)
|
|
75
|
-
(applies_to_params || {}).slice(:fee_types, :billable_metric_codes)
|
|
19
|
+
Customers::Wallets::WhitelistParams.new.wallet(params)
|
|
76
20
|
end
|
|
77
21
|
|
|
78
22
|
def whitelist_metadata(metadata)
|
|
@@ -108,6 +52,12 @@ module Lago
|
|
|
108
52
|
|
|
109
53
|
response['metadata']
|
|
110
54
|
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def whitelist_payment_method_params(payment_method_param)
|
|
59
|
+
payment_method_param&.slice(:payment_method_type, :payment_method_id)
|
|
60
|
+
end
|
|
111
61
|
end
|
|
112
62
|
end
|
|
113
63
|
end
|
|
@@ -28,19 +28,49 @@ 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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
result = params.compact.slice(
|
|
47
|
+
:wallet_id,
|
|
48
|
+
:name,
|
|
49
|
+
:paid_credits,
|
|
50
|
+
:granted_credits,
|
|
51
|
+
:voided_credits,
|
|
52
|
+
:invoice_requires_successful_payment,
|
|
53
|
+
:ignore_paid_top_up_limits,
|
|
54
|
+
:metadata,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
payment_method_params = whitelist_payment_method_params(params[:payment_method])
|
|
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
|
|
62
|
+
|
|
63
|
+
{ 'wallet_transaction' => result }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def whitelist_payment_method_params(payment_method_param)
|
|
69
|
+
payment_method_param&.slice(:payment_method_type, :payment_method_id)
|
|
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)
|
|
44
74
|
end
|
|
45
75
|
end
|
|
46
76
|
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
|
|
@@ -302,9 +302,15 @@ files:
|
|
|
302
302
|
- lib/lago/api/resources/customers/credit_note.rb
|
|
303
303
|
- lib/lago/api/resources/customers/invoice.rb
|
|
304
304
|
- lib/lago/api/resources/customers/payment.rb
|
|
305
|
+
- lib/lago/api/resources/customers/payment_method.rb
|
|
305
306
|
- lib/lago/api/resources/customers/payment_request.rb
|
|
306
307
|
- lib/lago/api/resources/customers/subscription.rb
|
|
307
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
|
|
308
314
|
- lib/lago/api/resources/event.rb
|
|
309
315
|
- lib/lago/api/resources/feature.rb
|
|
310
316
|
- lib/lago/api/resources/fee.rb
|
|
@@ -313,6 +319,7 @@ files:
|
|
|
313
319
|
- lib/lago/api/resources/invoice_collection.rb
|
|
314
320
|
- lib/lago/api/resources/invoiced_usage.rb
|
|
315
321
|
- lib/lago/api/resources/mrr.rb
|
|
322
|
+
- lib/lago/api/resources/nested.rb
|
|
316
323
|
- lib/lago/api/resources/organization.rb
|
|
317
324
|
- lib/lago/api/resources/overdue_balance.rb
|
|
318
325
|
- lib/lago/api/resources/payment.rb
|