lago-ruby-client 1.37.0 → 1.43.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 600a30a440f5566e5d00ac7cf7ed11cd892549687f84f7101b3efa123344ed09
4
- data.tar.gz: acf19141562235fbb7fb9b2ebd122c31daa8affcb835ea44a48a28af604f40ed
3
+ metadata.gz: 1cd4e9ed7d1b0f3eac5940fb37ea3b7b2616ceda00c5e3e4e42e0e80b0d0b3ba
4
+ data.tar.gz: 761ed874e1fb31e466ae0a5309132853ded262940f0504fcb6dc827a3af05c87
5
5
  SHA512:
6
- metadata.gz: 41a39e59ded39792a643aa24ee1daa2d844c2f5d054aa984a880df8f9014d976d0c0f0cb47d82e48ebb9b4dfea305b827e17532ac22516556982a7239626361a
7
- data.tar.gz: 7528982c6f111e71c028957cfe039b9802cb86accb28639b0691233184385888534865a5da02b4f0b7cf3d8ef7d2a35b6ac06572098700bb445ddfb1c0fe01d1
6
+ metadata.gz: 21a3cb1cd0b107edb3ac23e4a08738dd4c9f6ae96a8dee6ed07267a72b48cafdeb5d580afc631519961974c761dc44da151358ad9e3951f88c8a8f42e57f7c65
7
+ data.tar.gz: 87d47fc5d9f9039ca63975f697b30f1300314bc2448967e180944c1e68c0fc8576f8ddef53055e8c092cd0f28581fad43640ffeac638f3dcc3c6ca2f79f8d13d
@@ -15,6 +15,7 @@ require 'lago/api/resources/customers/applied_coupon'
15
15
  require 'lago/api/resources/customers/credit_note'
16
16
  require 'lago/api/resources/customers/invoice'
17
17
  require 'lago/api/resources/customers/payment'
18
+ require 'lago/api/resources/customers/payment_method'
18
19
  require 'lago/api/resources/customers/payment_request'
19
20
  require 'lago/api/resources/customers/subscription'
20
21
  require 'lago/api/resources/customers/wallet'
@@ -122,6 +123,10 @@ module Lago
122
123
  Resources::Customers::Payment.new(self, resource_id)
123
124
  end
124
125
 
126
+ def customer_payment_methods(resource_id)
127
+ Resources::Customers::PaymentMethod.new(self, resource_id)
128
+ end
129
+
125
130
  def customer_payment_requests(resource_id)
126
131
  Resources::Customers::PaymentRequest.new(self, resource_id)
127
132
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Lago
4
6
  module Api
5
7
  class Connection
@@ -99,7 +101,7 @@ module Lago
99
101
  def handle_response(response)
100
102
  raise_error(response) unless RESPONSE_SUCCESS_CODES.include?(response.code.to_i)
101
103
 
102
- response.body.empty? ? true : JSON.parse(response.body)
104
+ response.body.empty? || JSON.parse(response.body)
103
105
  rescue JSON::ParserError
104
106
  response.body
105
107
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  require 'lago/api/resources/base'
4
6
 
5
7
  module Lago
@@ -15,7 +17,7 @@ module Lago
15
17
  end
16
18
 
17
19
  def destroy(external_customer_id, applied_coupon_id)
18
- path = "/api/v1/customers/#{external_customer_id}/applied_coupons"
20
+ path = "/api/v1/customers/#{CGI.escapeURIComponent(external_customer_id)}/applied_coupons"
19
21
  response = connection.destroy(path, identifier: applied_coupon_id)[root_name]
20
22
 
21
23
  JSON.parse(response.to_json, object_class: OpenStruct)
@@ -21,15 +21,23 @@ module Lago
21
21
  refund_status: params[:refund_status],
22
22
  credit_amount_cents: params[:credit_amount_cents],
23
23
  refund_amount_cents: params[:refund_amount_cents],
24
+ offset_amount_cents: params[:offset_amount_cents],
24
25
  }.compact
25
26
 
26
27
  whitelist_items(params[:items] || []).tap do |items|
27
28
  result_hash[:items] = items unless items.empty?
28
29
  end
29
30
 
31
+ metadata = whitelist_metadata(params[:metadata])
32
+ result_hash[:metadata] = metadata if metadata
33
+
30
34
  { root_name => result_hash }
31
35
  end
32
36
 
37
+ def whitelist_metadata(metadata)
38
+ metadata&.to_h&.transform_keys(&:to_s)&.transform_values { |v| v&.to_s }
39
+ end
40
+
33
41
  def whitelist_items(items)
34
42
  items.each_with_object([]) do |item, result|
35
43
  filtered_item = (item || {}).slice(
@@ -78,6 +86,36 @@ module Lago
78
86
 
79
87
  { root_name => result_hash }
80
88
  end
89
+
90
+ def replace_metadata(credit_note_id, metadata)
91
+ path = "/api/v1/credit_notes/#{credit_note_id}/metadata"
92
+ payload = { metadata: whitelist_metadata(metadata) }
93
+ response = connection.post(payload, path)
94
+
95
+ response['metadata']
96
+ end
97
+
98
+ def merge_metadata(credit_note_id, metadata)
99
+ path = "/api/v1/credit_notes/#{credit_note_id}/metadata"
100
+ payload = { metadata: whitelist_metadata(metadata) }
101
+ response = connection.patch(path, identifier: nil, body: payload)
102
+
103
+ response['metadata']
104
+ end
105
+
106
+ def delete_all_metadata(credit_note_id)
107
+ path = "/api/v1/credit_notes/#{credit_note_id}/metadata"
108
+ response = connection.destroy(path, identifier: nil)
109
+
110
+ response['metadata']
111
+ end
112
+
113
+ def delete_metadata_key(credit_note_id, key)
114
+ path = "/api/v1/credit_notes/#{credit_note_id}/metadata/#{key}"
115
+ response = connection.destroy(path, identifier: nil)
116
+
117
+ response['metadata']
118
+ end
81
119
  end
82
120
  end
83
121
  end
@@ -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
@@ -54,14 +54,17 @@ module Lago
54
54
 
55
55
  def lose_dispute(invoice_id)
56
56
  path = "/api/v1/invoices/#{invoice_id}/lose_dispute"
57
- response = connection.put(path, identifier: nil, body: {})
57
+ response = connection.post({}, path)
58
58
 
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
- response = connection.post({}, path)
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,9 @@ 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.present?
136
+
131
137
  { root_name => result }
132
138
  end
133
139
 
@@ -161,6 +167,12 @@ module Lago
161
167
  credit_amount: params[:credit_amount]
162
168
  }.compact
163
169
  end
170
+
171
+ private
172
+
173
+ def whitelist_payment_method_params(payment_method_param)
174
+ payment_method_param&.slice(:payment_method_type, :payment_method_id)
175
+ end
164
176
  end
165
177
  end
166
178
  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],
@@ -66,6 +177,7 @@ module Lago
66
177
  trial_period: params[:trial_period],
67
178
  pay_in_advance: params[:pay_in_advance],
68
179
  bill_charges_monthly: params[:bill_charges_monthly],
180
+ bill_fixed_charges_monthly: params[:bill_fixed_charges_monthly],
69
181
  tax_codes: params[:tax_codes],
70
182
  cascade_updates: params[:cascade_updates],
71
183
  }.compact
@@ -82,6 +194,13 @@ module Lago
82
194
  result_hash[:usage_thresholds] = usage_thresholds unless usage_thresholds.empty?
83
195
  end
84
196
 
197
+ whitelist_fixed_charges(params[:fixed_charges]).tap do |fixed_charges|
198
+ result_hash[:fixed_charges] = fixed_charges unless fixed_charges.empty?
199
+ end
200
+
201
+ metadata = whitelist_metadata(params[:metadata])
202
+ result_hash[:metadata] = metadata if metadata
203
+
85
204
  { root_name => result_hash }
86
205
  end
87
206
 
@@ -106,10 +225,12 @@ module Lago
106
225
  :regroup_paid_fees,
107
226
  :invoice_display_name,
108
227
  :min_amount_cents,
228
+ :prorated,
109
229
  :properties,
110
230
  :filters,
111
231
  :tax_codes,
112
232
  :applied_pricing_unit,
233
+ :accepts_target_wallet,
113
234
  )
114
235
 
115
236
  processed_charges << result unless result.empty?
@@ -135,12 +256,70 @@ module Lago
135
256
  processed_usage_thresholds
136
257
  end
137
258
 
259
+ def whitelist_fixed_charges(fixed_charges)
260
+ processed_fixed_charges = []
261
+
262
+ fixed_charges&.each do |fc|
263
+ result = (fc || {}).slice(
264
+ :id,
265
+ :add_on_id,
266
+ :charge_model,
267
+ :code,
268
+ :invoice_display_name,
269
+ :units,
270
+ :pay_in_advance,
271
+ :prorated,
272
+ :properties,
273
+ :tax_codes,
274
+ :apply_units_immediately,
275
+ )
276
+
277
+ processed_fixed_charges << result unless result.empty?
278
+ end
279
+
280
+ processed_fixed_charges
281
+ end
282
+
283
+ def whitelist_metadata(metadata)
284
+ metadata&.to_h&.transform_keys(&:to_s)&.transform_values { |v| v&.to_s }
285
+ end
286
+
138
287
  def whitelist_entitlements_params(params)
139
288
  {
140
289
  entitlements: params,
141
290
  }
142
291
  end
143
292
 
293
+ def replace_metadata(plan_code, metadata)
294
+ path = "/api/v1/plans/#{plan_code}/metadata"
295
+ payload = { metadata: whitelist_metadata(metadata) }
296
+ response = connection.post(payload, path)
297
+
298
+ response['metadata']
299
+ end
300
+
301
+ def merge_metadata(plan_code, metadata)
302
+ path = "/api/v1/plans/#{plan_code}/metadata"
303
+ payload = { metadata: whitelist_metadata(metadata) }
304
+ response = connection.patch(path, identifier: nil, body: payload)
305
+
306
+ response['metadata']
307
+ end
308
+
309
+ def delete_all_metadata(plan_code)
310
+ path = "/api/v1/plans/#{plan_code}/metadata"
311
+ response = connection.destroy(path, identifier: nil)
312
+
313
+ response['metadata']
314
+ end
315
+
316
+ def delete_metadata_key(plan_code, key)
317
+ path = "/api/v1/plans/#{plan_code}/metadata/#{key}"
318
+ response = connection.destroy(path, identifier: nil)
319
+
320
+ response['metadata']
321
+ end
322
+
144
323
  private
145
324
 
146
325
  def entitlements_uri(plan_code, feature_code = nil, action = nil)
@@ -149,6 +328,76 @@ module Lago
149
328
  url += "/#{action}" if action
150
329
  URI(url)
151
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
152
401
  end
153
402
  end
154
403
  end
@@ -94,19 +94,110 @@ module Lago
94
94
  JSON.parse(response.to_json, object_class: OpenStruct).alert
95
95
  end
96
96
 
97
+ def create_alerts(external_subscription_id, params)
98
+ response = connection.post(
99
+ whitelist_alert_batch_create_params(params),
100
+ alert_uri(external_subscription_id),
101
+ )
102
+ JSON.parse(response.to_json, object_class: OpenStruct).alerts
103
+ end
104
+
105
+ def delete_alerts(external_subscription_id)
106
+ connection.destroy(alert_uri(external_subscription_id), identifier: nil)
107
+ end
108
+
109
+ # Charges
110
+ def get_all_charges(external_id, options = {})
111
+ response = connection.get_all(options, charges_uri(external_id))
112
+ JSON.parse(response.to_json, object_class: OpenStruct)
113
+ end
114
+
115
+ def get_charge(external_id, charge_code)
116
+ response = connection.get(charges_uri(external_id, charge_code), identifier: nil)
117
+ JSON.parse(response.to_json, object_class: OpenStruct).charge
118
+ end
119
+
120
+ def update_charge(external_id, charge_code, params)
121
+ response = connection.put(
122
+ charges_uri(external_id, charge_code),
123
+ identifier: nil,
124
+ body: whitelist_subscription_charge_params(params),
125
+ )
126
+ JSON.parse(response.to_json, object_class: OpenStruct).charge
127
+ end
128
+
129
+ # Fixed Charges
130
+ def get_all_fixed_charges(external_id, options = {})
131
+ response = connection.get_all(options, fixed_charges_uri(external_id))
132
+ JSON.parse(response.to_json, object_class: OpenStruct)
133
+ end
134
+
135
+ def get_fixed_charge(external_id, fixed_charge_code)
136
+ response = connection.get(fixed_charges_uri(external_id, fixed_charge_code), identifier: nil)
137
+ JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
138
+ end
139
+
140
+ def update_fixed_charge(external_id, fixed_charge_code, params)
141
+ response = connection.put(
142
+ fixed_charges_uri(external_id, fixed_charge_code),
143
+ identifier: nil,
144
+ body: whitelist_subscription_fixed_charge_params(params),
145
+ )
146
+ JSON.parse(response.to_json, object_class: OpenStruct).fixed_charge
147
+ end
148
+
149
+ # Charge Filters
150
+ def get_all_charge_filters(external_id, charge_code, options = {})
151
+ response = connection.get_all(options, charge_filters_uri(external_id, charge_code))
152
+ JSON.parse(response.to_json, object_class: OpenStruct)
153
+ end
154
+
155
+ def get_charge_filter(external_id, charge_code, filter_id)
156
+ response = connection.get(charge_filters_uri(external_id, charge_code, filter_id), identifier: nil)
157
+ JSON.parse(response.to_json, object_class: OpenStruct).filter
158
+ end
159
+
160
+ def create_charge_filter(external_id, charge_code, params)
161
+ response = connection.post(
162
+ whitelist_subscription_charge_filter_params(params),
163
+ charge_filters_uri(external_id, charge_code),
164
+ )
165
+ JSON.parse(response.to_json, object_class: OpenStruct).filter
166
+ end
167
+
168
+ def update_charge_filter(external_id, charge_code, filter_id, params)
169
+ response = connection.put(
170
+ charge_filters_uri(external_id, charge_code, filter_id),
171
+ identifier: nil,
172
+ body: whitelist_subscription_charge_filter_params(params),
173
+ )
174
+ JSON.parse(response.to_json, object_class: OpenStruct).filter
175
+ end
176
+
177
+ def destroy_charge_filter(external_id, charge_code, filter_id)
178
+ response = connection.destroy(
179
+ charge_filters_uri(external_id, charge_code, filter_id),
180
+ identifier: nil,
181
+ )
182
+ JSON.parse(response.to_json, object_class: OpenStruct).filter
183
+ end
184
+
97
185
  def whitelist_params(params)
98
- {
99
- root_name => {
100
- external_customer_id: params[:external_customer_id],
101
- plan_code: params[:plan_code],
102
- name: params[:name],
103
- external_id: params[:external_id],
104
- billing_time: params[:billing_time],
105
- subscription_at: params[:subscription_at],
106
- ending_at: params[:ending_at],
107
- plan_overrides: params[:plan_overrides],
108
- }.compact,
109
- }
186
+ result = {
187
+ external_customer_id: params[:external_customer_id],
188
+ plan_code: params[:plan_code],
189
+ name: params[:name],
190
+ external_id: params[:external_id],
191
+ billing_time: params[:billing_time],
192
+ subscription_at: params[:subscription_at],
193
+ ending_at: params[:ending_at],
194
+ plan_overrides: params[:plan_overrides],
195
+ }.compact
196
+
197
+ payment_method_params = whitelist_payment_method_params(params[:payment_method])
198
+ result[:payment_method] = payment_method_params if payment_method_params.present?
199
+
200
+ { root_name => result }
110
201
  end
111
202
 
112
203
  def whitelist_lifetime_usage_params(params)
@@ -129,6 +220,20 @@ module Lago
129
220
  }
130
221
  end
131
222
 
223
+ def whitelist_alert_batch_create_params(params)
224
+ {
225
+ alerts: (params[:alerts] || []).map do |alert|
226
+ {
227
+ alert_type: alert[:alert_type],
228
+ name: alert[:name],
229
+ code: alert[:code],
230
+ billable_metric_code: alert[:billable_metric_code],
231
+ thresholds: alert[:thresholds],
232
+ }.compact
233
+ end,
234
+ }
235
+ end
236
+
132
237
  def whitelist_alert_update_params(params)
133
238
  {
134
239
  alert: {
@@ -154,6 +259,10 @@ module Lago
154
259
 
155
260
  private
156
261
 
262
+ def whitelist_payment_method_params(payment_method_param)
263
+ payment_method_param&.slice(:payment_method_type, :payment_method_id)
264
+ end
265
+
157
266
  def entitlements_uri(external_subscription_id, feature_code = nil, action = nil)
158
267
  url = "#{client.base_api_url}#{api_resource}/#{external_subscription_id}/entitlements"
159
268
  url += "/#{feature_code}" if feature_code
@@ -164,6 +273,59 @@ module Lago
164
273
  def alert_uri(external_subscription_id, code = nil)
165
274
  URI("#{client.base_api_url}#{api_resource}/#{external_subscription_id}/alerts#{code ? "/#{code}" : ''}")
166
275
  end
276
+
277
+ def charges_uri(external_id, charge_code = nil)
278
+ url = "#{client.base_api_url}#{api_resource}/#{external_id}/charges"
279
+ url += "/#{charge_code}" if charge_code
280
+ URI(url)
281
+ end
282
+
283
+ def fixed_charges_uri(external_id, fixed_charge_code = nil)
284
+ url = "#{client.base_api_url}#{api_resource}/#{external_id}/fixed_charges"
285
+ url += "/#{fixed_charge_code}" if fixed_charge_code
286
+ URI(url)
287
+ end
288
+
289
+ def charge_filters_uri(external_id, charge_code, filter_id = nil)
290
+ url = "#{client.base_api_url}#{api_resource}/#{external_id}/charges/#{charge_code}/filters"
291
+ url += "/#{filter_id}" if filter_id
292
+ URI(url)
293
+ end
294
+
295
+ def whitelist_subscription_charge_params(params)
296
+ {
297
+ charge: (params || {}).slice(
298
+ :invoice_display_name,
299
+ :min_amount_cents,
300
+ :properties,
301
+ :filters,
302
+ :tax_codes,
303
+ :applied_pricing_unit,
304
+ ),
305
+ }
306
+ end
307
+
308
+ def whitelist_subscription_fixed_charge_params(params)
309
+ {
310
+ fixed_charge: (params || {}).slice(
311
+ :invoice_display_name,
312
+ :units,
313
+ :apply_units_immediately,
314
+ :properties,
315
+ :tax_codes,
316
+ ),
317
+ }
318
+ end
319
+
320
+ def whitelist_subscription_charge_filter_params(params)
321
+ {
322
+ filter: (params || {}).slice(
323
+ :invoice_display_name,
324
+ :properties,
325
+ :values,
326
+ ),
327
+ }
328
+ end
167
329
  end
168
330
  end
169
331
  end
@@ -19,6 +19,8 @@ module Lago
19
19
  :external_customer_id,
20
20
  :rate_amount,
21
21
  :name,
22
+ :code,
23
+ :priority,
22
24
  :paid_credits,
23
25
  :granted_credits,
24
26
  :currency,
@@ -37,6 +39,12 @@ module Lago
37
39
  applies_to = whitelist_applies_to(params[:applies_to])
38
40
  result_hash[:applies_to] = applies_to if applies_to.any?
39
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
+
40
48
  { root_name => result_hash }
41
49
  end
42
50
 
@@ -61,6 +69,9 @@ module Lago
61
69
  :ignore_paid_top_up_limits
62
70
  )
63
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
+
64
75
  processed_rules << result unless result.empty?
65
76
  end
66
77
 
@@ -70,6 +81,46 @@ module Lago
70
81
  def whitelist_applies_to(applies_to_params)
71
82
  (applies_to_params || {}).slice(:fee_types, :billable_metric_codes)
72
83
  end
84
+
85
+ def whitelist_metadata(metadata)
86
+ metadata&.to_h&.transform_keys(&:to_s)&.transform_values { |v| v&.to_s }
87
+ end
88
+
89
+ def replace_metadata(wallet_id, metadata)
90
+ path = "/api/v1/wallets/#{wallet_id}/metadata"
91
+ payload = { metadata: whitelist_metadata(metadata) }
92
+ response = connection.post(payload, path)
93
+
94
+ response['metadata']
95
+ end
96
+
97
+ def merge_metadata(wallet_id, metadata)
98
+ path = "/api/v1/wallets/#{wallet_id}/metadata"
99
+ payload = { metadata: whitelist_metadata(metadata) }
100
+ response = connection.patch(path, identifier: nil, body: payload)
101
+
102
+ response['metadata']
103
+ end
104
+
105
+ def delete_all_metadata(wallet_id)
106
+ path = "/api/v1/wallets/#{wallet_id}/metadata"
107
+ response = connection.destroy(path, identifier: nil)
108
+
109
+ response['metadata']
110
+ end
111
+
112
+ def delete_metadata_key(wallet_id, key)
113
+ path = "/api/v1/wallets/#{wallet_id}/metadata/#{key}"
114
+ response = connection.destroy(path, identifier: nil)
115
+
116
+ response['metadata']
117
+ end
118
+
119
+ private
120
+
121
+ def whitelist_payment_method_params(payment_method_param)
122
+ payment_method_param&.slice(:payment_method_type, :payment_method_id)
123
+ end
73
124
  end
74
125
  end
75
126
  end
@@ -29,18 +29,27 @@ module Lago
29
29
  end
30
30
 
31
31
  def whitelist_params(params)
32
- {
33
- 'wallet_transaction' => params.compact.slice(
34
- :wallet_id,
35
- :name,
36
- :paid_credits,
37
- :granted_credits,
38
- :voided_credits,
39
- :invoice_requires_successful_payment,
40
- :ignore_paid_top_up_limits,
41
- :metadata,
42
- )
43
- }
32
+ result = params.compact.slice(
33
+ :wallet_id,
34
+ :name,
35
+ :paid_credits,
36
+ :granted_credits,
37
+ :voided_credits,
38
+ :invoice_requires_successful_payment,
39
+ :ignore_paid_top_up_limits,
40
+ :metadata,
41
+ )
42
+
43
+ payment_method_params = whitelist_payment_method_params(params[:payment_method])
44
+ result[:payment_method] = payment_method_params if payment_method_params.present?
45
+
46
+ { 'wallet_transaction' => result }
47
+ end
48
+
49
+ private
50
+
51
+ def whitelist_payment_method_params(payment_method_param)
52
+ payment_method_param&.slice(:payment_method_type, :payment_method_id)
44
53
  end
45
54
  end
46
55
  end
data/lib/lago/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lago
4
- VERSION = '1.37.0'
4
+ VERSION = '1.43.0'
5
5
  end
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.37.0
4
+ version: 1.43.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: 2025-12-09 00:00:00.000000000 Z
11
+ date: 2026-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -302,6 +302,7 @@ 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