lago-ruby-client 1.37.0 → 1.40.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: 37c60d46c38643113860ccaa8eea0beb2e9ff735c84c494575458729ba4e1340
4
+ data.tar.gz: 17259c33488215f546afb8d5a0fd4541a67a3812486233a417223d1e484a6a6c
5
5
  SHA512:
6
- metadata.gz: 41a39e59ded39792a643aa24ee1daa2d844c2f5d054aa984a880df8f9014d976d0c0f0cb47d82e48ebb9b4dfea305b827e17532ac22516556982a7239626361a
7
- data.tar.gz: 7528982c6f111e71c028957cfe039b9802cb86accb28639b0691233184385888534865a5da02b4f0b7cf3d8ef7d2a35b6ac06572098700bb445ddfb1c0fe01d1
6
+ metadata.gz: c85b6545df50a21700f6392ee592944cc873961c9ecb7b553c0447b26a40de6697c634f14a0a2e1cfabd3ade4e76026bf1c14c32ead3de3e02e55fc6ce9ef13c
7
+ data.tar.gz: a36624870091a68b739c7e112a7c8be41bb79b36a51800fae1b06c17c0bb73145451785c99f5bc40e97b75fb3a6a46d1136b12b645dea782110ee6dbdd297716
@@ -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
@@ -54,7 +54,7 @@ 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
@@ -66,6 +66,7 @@ module Lago
66
66
  trial_period: params[:trial_period],
67
67
  pay_in_advance: params[:pay_in_advance],
68
68
  bill_charges_monthly: params[:bill_charges_monthly],
69
+ bill_fixed_charges_monthly: params[:bill_fixed_charges_monthly],
69
70
  tax_codes: params[:tax_codes],
70
71
  cascade_updates: params[:cascade_updates],
71
72
  }.compact
@@ -82,6 +83,13 @@ module Lago
82
83
  result_hash[:usage_thresholds] = usage_thresholds unless usage_thresholds.empty?
83
84
  end
84
85
 
86
+ whitelist_fixed_charges(params[:fixed_charges]).tap do |fixed_charges|
87
+ result_hash[:fixed_charges] = fixed_charges unless fixed_charges.empty?
88
+ end
89
+
90
+ metadata = whitelist_metadata(params[:metadata])
91
+ result_hash[:metadata] = metadata if metadata
92
+
85
93
  { root_name => result_hash }
86
94
  end
87
95
 
@@ -106,6 +114,7 @@ module Lago
106
114
  :regroup_paid_fees,
107
115
  :invoice_display_name,
108
116
  :min_amount_cents,
117
+ :prorated,
109
118
  :properties,
110
119
  :filters,
111
120
  :tax_codes,
@@ -135,12 +144,70 @@ module Lago
135
144
  processed_usage_thresholds
136
145
  end
137
146
 
147
+ def whitelist_fixed_charges(fixed_charges)
148
+ processed_fixed_charges = []
149
+
150
+ fixed_charges&.each do |fc|
151
+ result = (fc || {}).slice(
152
+ :id,
153
+ :add_on_id,
154
+ :charge_model,
155
+ :code,
156
+ :invoice_display_name,
157
+ :units,
158
+ :pay_in_advance,
159
+ :prorated,
160
+ :properties,
161
+ :tax_codes,
162
+ :apply_units_immediately,
163
+ )
164
+
165
+ processed_fixed_charges << result unless result.empty?
166
+ end
167
+
168
+ processed_fixed_charges
169
+ end
170
+
171
+ def whitelist_metadata(metadata)
172
+ metadata&.to_h&.transform_keys(&:to_s)&.transform_values { |v| v&.to_s }
173
+ end
174
+
138
175
  def whitelist_entitlements_params(params)
139
176
  {
140
177
  entitlements: params,
141
178
  }
142
179
  end
143
180
 
181
+ def replace_metadata(plan_code, metadata)
182
+ path = "/api/v1/plans/#{plan_code}/metadata"
183
+ payload = { metadata: whitelist_metadata(metadata) }
184
+ response = connection.post(payload, path)
185
+
186
+ response['metadata']
187
+ end
188
+
189
+ def merge_metadata(plan_code, metadata)
190
+ path = "/api/v1/plans/#{plan_code}/metadata"
191
+ payload = { metadata: whitelist_metadata(metadata) }
192
+ response = connection.patch(path, identifier: nil, body: payload)
193
+
194
+ response['metadata']
195
+ end
196
+
197
+ def delete_all_metadata(plan_code)
198
+ path = "/api/v1/plans/#{plan_code}/metadata"
199
+ response = connection.destroy(path, identifier: nil)
200
+
201
+ response['metadata']
202
+ end
203
+
204
+ def delete_metadata_key(plan_code, key)
205
+ path = "/api/v1/plans/#{plan_code}/metadata/#{key}"
206
+ response = connection.destroy(path, identifier: nil)
207
+
208
+ response['metadata']
209
+ end
210
+
144
211
  private
145
212
 
146
213
  def entitlements_uri(plan_code, feature_code = nil, action = nil)
@@ -86,6 +86,14 @@ module Lago
86
86
  JSON.parse(response.to_json, object_class: OpenStruct).alerts
87
87
  end
88
88
 
89
+ def fixed_charges(external_subscription_id)
90
+ uri = URI(
91
+ "#{client.base_api_url}#{api_resource}/#{external_subscription_id}/fixed_charges",
92
+ )
93
+ response = connection.get(uri, identifier: nil)
94
+ JSON.parse(response.to_json, object_class: OpenStruct).fixed_charges
95
+ end
96
+
89
97
  def create_alert(external_subscription_id, params)
90
98
  response = connection.post(
91
99
  whitelist_alert_create_params(params),
@@ -19,6 +19,7 @@ module Lago
19
19
  :external_customer_id,
20
20
  :rate_amount,
21
21
  :name,
22
+ :priority,
22
23
  :paid_credits,
23
24
  :granted_credits,
24
25
  :currency,
@@ -37,6 +38,9 @@ module Lago
37
38
  applies_to = whitelist_applies_to(params[:applies_to])
38
39
  result_hash[:applies_to] = applies_to if applies_to.any?
39
40
 
41
+ metadata = whitelist_metadata(params[:metadata])
42
+ result_hash[:metadata] = metadata if metadata
43
+
40
44
  { root_name => result_hash }
41
45
  end
42
46
 
@@ -70,6 +74,40 @@ module Lago
70
74
  def whitelist_applies_to(applies_to_params)
71
75
  (applies_to_params || {}).slice(:fee_types, :billable_metric_codes)
72
76
  end
77
+
78
+ def whitelist_metadata(metadata)
79
+ metadata&.to_h&.transform_keys(&:to_s)&.transform_values { |v| v&.to_s }
80
+ end
81
+
82
+ def replace_metadata(wallet_id, metadata)
83
+ path = "/api/v1/wallets/#{wallet_id}/metadata"
84
+ payload = { metadata: whitelist_metadata(metadata) }
85
+ response = connection.post(payload, path)
86
+
87
+ response['metadata']
88
+ end
89
+
90
+ def merge_metadata(wallet_id, metadata)
91
+ path = "/api/v1/wallets/#{wallet_id}/metadata"
92
+ payload = { metadata: whitelist_metadata(metadata) }
93
+ response = connection.patch(path, identifier: nil, body: payload)
94
+
95
+ response['metadata']
96
+ end
97
+
98
+ def delete_all_metadata(wallet_id)
99
+ path = "/api/v1/wallets/#{wallet_id}/metadata"
100
+ response = connection.destroy(path, identifier: nil)
101
+
102
+ response['metadata']
103
+ end
104
+
105
+ def delete_metadata_key(wallet_id, key)
106
+ path = "/api/v1/wallets/#{wallet_id}/metadata/#{key}"
107
+ response = connection.destroy(path, identifier: nil)
108
+
109
+ response['metadata']
110
+ end
73
111
  end
74
112
  end
75
113
  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.40.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.40.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-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt