pago-sdk 1.0.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +131 -0
- data/lib/pago/base_client.rb +116 -0
- data/lib/pago/errors.rb +83 -0
- data/lib/pago/http.rb +78 -0
- data/lib/pago/model.rb +86 -0
- data/lib/pago/paginator.rb +67 -0
- data/lib/pago/serde.rb +186 -0
- data/lib/pago/service.rb +17 -0
- data/lib/pago/v2026_04/client.rb +124 -0
- data/lib/pago/v2026_04/enums.rb +4552 -0
- data/lib/pago/v2026_04/errors.rb +1121 -0
- data/lib/pago/v2026_04/models.rb +46344 -0
- data/lib/pago/v2026_04/services/benefit_grants.rb +48 -0
- data/lib/pago/v2026_04/services/benefits.rb +179 -0
- data/lib/pago/v2026_04/services/checkout_links.rb +131 -0
- data/lib/pago/v2026_04/services/checkouts.rb +185 -0
- data/lib/pago/v2026_04/services/custom_fields.rb +132 -0
- data/lib/pago/v2026_04/services/customer_meters.rb +69 -0
- data/lib/pago/v2026_04/services/customer_portal.rb +1181 -0
- data/lib/pago/v2026_04/services/customer_seats.rb +137 -0
- data/lib/pago/v2026_04/services/customer_sessions.rb +35 -0
- data/lib/pago/v2026_04/services/customers.rb +556 -0
- data/lib/pago/v2026_04/services/discounts.rb +131 -0
- data/lib/pago/v2026_04/services/disputes.rb +93 -0
- data/lib/pago/v2026_04/services/event_types.rb +74 -0
- data/lib/pago/v2026_04/services/events.rb +126 -0
- data/lib/pago/v2026_04/services/files.rb +135 -0
- data/lib/pago/v2026_04/services/license_keys.rb +183 -0
- data/lib/pago/v2026_04/services/members.rb +47 -0
- data/lib/pago/v2026_04/services/meters.rb +142 -0
- data/lib/pago/v2026_04/services/metrics.rb +188 -0
- data/lib/pago/v2026_04/services/oauth2.rb +175 -0
- data/lib/pago/v2026_04/services/orders.rb +238 -0
- data/lib/pago/v2026_04/services/organizations.rb +113 -0
- data/lib/pago/v2026_04/services/payments.rb +72 -0
- data/lib/pago/v2026_04/services/products.rb +142 -0
- data/lib/pago/v2026_04/services/refunds.rb +73 -0
- data/lib/pago/v2026_04/services/subscriptions.rb +171 -0
- data/lib/pago/v2026_04/services/webhooks.rb +212 -0
- data/lib/pago/v2026_04/unions.rb +739 -0
- data/lib/pago/v2026_04/webhooks.rb +86 -0
- data/lib/pago/version.rb +5 -0
- data/lib/pago/webhooks.rb +159 -0
- data/lib/pago.rb +39 -0
- data/sig/pago/v2026_04/generated.rbs +12401 -0
- data/sig/pago.rbs +204 -0
- metadata +91 -0
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pago
|
|
4
|
+
module V2026_04
|
|
5
|
+
module Services
|
|
6
|
+
class Customers < ::Pago::Service
|
|
7
|
+
# @return [Members]
|
|
8
|
+
def members = @members ||= Members.new(client)
|
|
9
|
+
|
|
10
|
+
# List customers.
|
|
11
|
+
#
|
|
12
|
+
# **Scopes**: `customers:read` `customers:write`
|
|
13
|
+
#
|
|
14
|
+
# @param organization_id [String, Array<String>, nil] Filter by organization ID.
|
|
15
|
+
# @param email [String, nil] Filter by exact email.
|
|
16
|
+
# @param query [String, nil] Filter by name, email, or external ID.
|
|
17
|
+
# @param active [Boolean, nil] Filter by active customers, i.e. customers with at least one trialing, active or past_due subscription.
|
|
18
|
+
# @param page [Integer] Page number, defaults to 1.
|
|
19
|
+
# @param limit [Integer] Size of a page, defaults to 10. Maximum is 100.
|
|
20
|
+
# @param sorting [Array<String>, nil] Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign `-` before the criteria name to sort by descending order.
|
|
21
|
+
# @param metadata [Object] Filter by metadata key-value pairs. It uses the `deepObject` style, e.g. `?metadata[key]=value`.
|
|
22
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
23
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
24
|
+
# @return [Models::ListResourceCustomer]
|
|
25
|
+
def list(organization_id: nil, email: nil, query: nil, active: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil)
|
|
26
|
+
data = client.request(
|
|
27
|
+
http_method: "GET",
|
|
28
|
+
path: "/v1/customers/",
|
|
29
|
+
path_params: {},
|
|
30
|
+
query: { "organization_id" => organization_id, "email" => email, "query" => query, "active" => active, "page" => page, "limit" => limit, "sorting" => sorting, "metadata" => metadata },
|
|
31
|
+
response_type: :json,
|
|
32
|
+
errors: { 422 => Errors::HTTPValidationError }
|
|
33
|
+
)
|
|
34
|
+
Models::ListResourceCustomer.from_json(data)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Enumerate every item of `list`, fetching pages on demand.
|
|
38
|
+
#
|
|
39
|
+
# @yieldparam item [Object]
|
|
40
|
+
# @return [Pago::Paginator] when called without a block.
|
|
41
|
+
def list_each(organization_id: nil, email: nil, query: nil, active: nil, limit: 10, sorting: ["-created_at"], metadata: nil, &block)
|
|
42
|
+
paginator = ::Pago::Paginator.new do |page_number|
|
|
43
|
+
list(organization_id: organization_id, email: email, query: query, active: active, page: page_number, limit: limit, sorting: sorting, metadata: metadata)
|
|
44
|
+
end
|
|
45
|
+
block ? paginator.each(&block) : paginator
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Create a customer.
|
|
49
|
+
#
|
|
50
|
+
# **Scopes**: `customers:write`
|
|
51
|
+
#
|
|
52
|
+
# @param body [Hash, Object] the request body.
|
|
53
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
54
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
55
|
+
# @return [Object]
|
|
56
|
+
def create(body: {})
|
|
57
|
+
data = client.request(
|
|
58
|
+
http_method: "POST",
|
|
59
|
+
path: "/v1/customers/",
|
|
60
|
+
path_params: {},
|
|
61
|
+
query: {},
|
|
62
|
+
body: body,
|
|
63
|
+
response_type: :json,
|
|
64
|
+
errors: { 422 => Errors::HTTPValidationError }
|
|
65
|
+
)
|
|
66
|
+
Unions::Customer.from_json(data)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Export customers as a CSV file.
|
|
70
|
+
#
|
|
71
|
+
# **Scopes**: `customers:read` `customers:write`
|
|
72
|
+
#
|
|
73
|
+
# @param organization_id [String, Array<String>, nil] Filter by organization ID.
|
|
74
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
75
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
76
|
+
# @return [String]
|
|
77
|
+
def export(organization_id: nil)
|
|
78
|
+
client.request(
|
|
79
|
+
http_method: "GET",
|
|
80
|
+
path: "/v1/customers/export",
|
|
81
|
+
path_params: {},
|
|
82
|
+
query: { "organization_id" => organization_id },
|
|
83
|
+
response_type: :text,
|
|
84
|
+
errors: { 422 => Errors::HTTPValidationError }
|
|
85
|
+
)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Get a customer by ID.
|
|
89
|
+
#
|
|
90
|
+
# **Scopes**: `customers:read` `customers:write`
|
|
91
|
+
#
|
|
92
|
+
# @param id [String] The customer ID.
|
|
93
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
94
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
95
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
96
|
+
# @return [Object]
|
|
97
|
+
def get(id)
|
|
98
|
+
data = client.request(
|
|
99
|
+
http_method: "GET",
|
|
100
|
+
path: "/v1/customers/{id}",
|
|
101
|
+
path_params: { "id" => id },
|
|
102
|
+
query: {},
|
|
103
|
+
response_type: :json,
|
|
104
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
105
|
+
)
|
|
106
|
+
Unions::Customer.from_json(data)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Delete a customer.
|
|
110
|
+
#
|
|
111
|
+
# This action cannot be undone and will immediately:
|
|
112
|
+
# - Cancel any active subscriptions for the customer
|
|
113
|
+
# - Revoke all their benefits
|
|
114
|
+
# - Clear any `external_id`
|
|
115
|
+
#
|
|
116
|
+
# Use it only in the context of deleting a user within your
|
|
117
|
+
# own service. Otherwise, use more granular API endpoints to cancel
|
|
118
|
+
# a specific subscription or revoke certain benefits.
|
|
119
|
+
#
|
|
120
|
+
# Note: The customers information will nonetheless be retained for historic
|
|
121
|
+
# orders and subscriptions.
|
|
122
|
+
#
|
|
123
|
+
# Set `anonymize=true` to also anonymize PII for GDPR compliance.
|
|
124
|
+
#
|
|
125
|
+
# **Scopes**: `customers:write`
|
|
126
|
+
#
|
|
127
|
+
# @param id [String] The customer ID.
|
|
128
|
+
# @param anonymize [Boolean] If true, also anonymize the customer's personal data for GDPR compliance. This replaces email with a hashed version, hashes name and billing name (name preserved for businesses with tax_id), clears billing address, and removes OAuth account data.
|
|
129
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
130
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
131
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
132
|
+
# @return [nil]
|
|
133
|
+
def delete(id, anonymize: false)
|
|
134
|
+
client.request(
|
|
135
|
+
http_method: "DELETE",
|
|
136
|
+
path: "/v1/customers/{id}",
|
|
137
|
+
path_params: { "id" => id },
|
|
138
|
+
query: { "anonymize" => anonymize },
|
|
139
|
+
response_type: :none,
|
|
140
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
141
|
+
)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Update a customer.
|
|
145
|
+
#
|
|
146
|
+
# **Scopes**: `customers:write`
|
|
147
|
+
#
|
|
148
|
+
# @param id [String] The customer ID.
|
|
149
|
+
# @param body [Hash, Models::CustomerUpdate] the request body.
|
|
150
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
151
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
152
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
153
|
+
# @return [Object]
|
|
154
|
+
def update(id, body: {})
|
|
155
|
+
data = client.request(
|
|
156
|
+
http_method: "PATCH",
|
|
157
|
+
path: "/v1/customers/{id}",
|
|
158
|
+
path_params: { "id" => id },
|
|
159
|
+
query: {},
|
|
160
|
+
body: body,
|
|
161
|
+
response_type: :json,
|
|
162
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
163
|
+
)
|
|
164
|
+
Unions::Customer.from_json(data)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Get a customer by external ID.
|
|
168
|
+
#
|
|
169
|
+
# **Scopes**: `customers:read` `customers:write`
|
|
170
|
+
#
|
|
171
|
+
# @param external_id [String] The customer external ID.
|
|
172
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
173
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
174
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
175
|
+
# @return [Object]
|
|
176
|
+
def get_external(external_id)
|
|
177
|
+
data = client.request(
|
|
178
|
+
http_method: "GET",
|
|
179
|
+
path: "/v1/customers/external/{external_id}",
|
|
180
|
+
path_params: { "external_id" => external_id },
|
|
181
|
+
query: {},
|
|
182
|
+
response_type: :json,
|
|
183
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
184
|
+
)
|
|
185
|
+
Unions::Customer.from_json(data)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Delete a customer by external ID.
|
|
189
|
+
#
|
|
190
|
+
# Immediately cancels any active subscriptions and revokes any active benefits.
|
|
191
|
+
#
|
|
192
|
+
# Set `anonymize=true` to also anonymize PII for GDPR compliance.
|
|
193
|
+
#
|
|
194
|
+
# **Scopes**: `customers:write`
|
|
195
|
+
#
|
|
196
|
+
# @param external_id [String] The customer external ID.
|
|
197
|
+
# @param anonymize [Boolean] If true, also anonymize the customer's personal data for GDPR compliance.
|
|
198
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
199
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
200
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
201
|
+
# @return [nil]
|
|
202
|
+
def delete_external(external_id, anonymize: false)
|
|
203
|
+
client.request(
|
|
204
|
+
http_method: "DELETE",
|
|
205
|
+
path: "/v1/customers/external/{external_id}",
|
|
206
|
+
path_params: { "external_id" => external_id },
|
|
207
|
+
query: { "anonymize" => anonymize },
|
|
208
|
+
response_type: :none,
|
|
209
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
210
|
+
)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Update a customer by external ID.
|
|
214
|
+
#
|
|
215
|
+
# **Scopes**: `customers:write`
|
|
216
|
+
#
|
|
217
|
+
# @param external_id [String] The customer external ID.
|
|
218
|
+
# @param body [Hash, Models::CustomerUpdateExternalID] the request body.
|
|
219
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
220
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
221
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
222
|
+
# @return [Object]
|
|
223
|
+
def update_external(external_id, body: {})
|
|
224
|
+
data = client.request(
|
|
225
|
+
http_method: "PATCH",
|
|
226
|
+
path: "/v1/customers/external/{external_id}",
|
|
227
|
+
path_params: { "external_id" => external_id },
|
|
228
|
+
query: {},
|
|
229
|
+
body: body,
|
|
230
|
+
response_type: :json,
|
|
231
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
232
|
+
)
|
|
233
|
+
Unions::Customer.from_json(data)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# Get a customer state by ID.
|
|
237
|
+
#
|
|
238
|
+
# The customer state includes information about
|
|
239
|
+
# the customer's active subscriptions and benefits.
|
|
240
|
+
#
|
|
241
|
+
# It's the ideal endpoint to use when you need to get a full overview
|
|
242
|
+
# of a customer's status.
|
|
243
|
+
#
|
|
244
|
+
# **Scopes**: `customers:read` `customers:write`
|
|
245
|
+
#
|
|
246
|
+
# @param id [String] The customer ID.
|
|
247
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
248
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
249
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
250
|
+
# @return [Object]
|
|
251
|
+
def get_state(id)
|
|
252
|
+
data = client.request(
|
|
253
|
+
http_method: "GET",
|
|
254
|
+
path: "/v1/customers/{id}/state",
|
|
255
|
+
path_params: { "id" => id },
|
|
256
|
+
query: {},
|
|
257
|
+
response_type: :json,
|
|
258
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
259
|
+
)
|
|
260
|
+
Unions::CustomerState.from_json(data)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# Get a customer state by external ID.
|
|
264
|
+
#
|
|
265
|
+
# The customer state includes information about
|
|
266
|
+
# the customer's active subscriptions and benefits.
|
|
267
|
+
#
|
|
268
|
+
# It's the ideal endpoint to use when you need to get a full overview
|
|
269
|
+
# of a customer's status.
|
|
270
|
+
#
|
|
271
|
+
# **Scopes**: `customers:read` `customers:write`
|
|
272
|
+
#
|
|
273
|
+
# @param external_id [String] The customer external ID.
|
|
274
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
275
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
276
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
277
|
+
# @return [Object]
|
|
278
|
+
def get_state_external(external_id)
|
|
279
|
+
data = client.request(
|
|
280
|
+
http_method: "GET",
|
|
281
|
+
path: "/v1/customers/external/{external_id}/state",
|
|
282
|
+
path_params: { "external_id" => external_id },
|
|
283
|
+
query: {},
|
|
284
|
+
response_type: :json,
|
|
285
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
286
|
+
)
|
|
287
|
+
Unions::CustomerState.from_json(data)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# Get saved payment methods of a customer.
|
|
291
|
+
#
|
|
292
|
+
# **Scopes**: `customers:read` `customers:write`
|
|
293
|
+
#
|
|
294
|
+
# @param id [String] The customer ID.
|
|
295
|
+
# @param page [Integer] Page number, defaults to 1.
|
|
296
|
+
# @param limit [Integer] Size of a page, defaults to 10. Maximum is 100.
|
|
297
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
298
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
299
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
300
|
+
# @return [Models::ListResourcePaymentMethod]
|
|
301
|
+
def list_payment_methods(id, page: 1, limit: 10)
|
|
302
|
+
data = client.request(
|
|
303
|
+
http_method: "GET",
|
|
304
|
+
path: "/v1/customers/{id}/payment-methods",
|
|
305
|
+
path_params: { "id" => id },
|
|
306
|
+
query: { "page" => page, "limit" => limit },
|
|
307
|
+
response_type: :json,
|
|
308
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
309
|
+
)
|
|
310
|
+
Models::ListResourcePaymentMethod.from_json(data)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
# Enumerate every item of `list_payment_methods`, fetching pages on demand.
|
|
314
|
+
#
|
|
315
|
+
# @yieldparam item [Object]
|
|
316
|
+
# @return [Pago::Paginator] when called without a block.
|
|
317
|
+
def list_payment_methods_each(id, limit: 10, &block)
|
|
318
|
+
paginator = ::Pago::Paginator.new do |page_number|
|
|
319
|
+
list_payment_methods(id, page: page_number, limit: limit)
|
|
320
|
+
end
|
|
321
|
+
block ? paginator.each(&block) : paginator
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# Get saved payment methods of a customer by external ID.
|
|
325
|
+
#
|
|
326
|
+
# **Scopes**: `customers:read` `customers:write`
|
|
327
|
+
#
|
|
328
|
+
# @param external_id [String] The customer external ID.
|
|
329
|
+
# @param page [Integer] Page number, defaults to 1.
|
|
330
|
+
# @param limit [Integer] Size of a page, defaults to 10. Maximum is 100.
|
|
331
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
332
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
333
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
334
|
+
# @return [Models::ListResourcePaymentMethod]
|
|
335
|
+
def list_payment_methods_external(external_id, page: 1, limit: 10)
|
|
336
|
+
data = client.request(
|
|
337
|
+
http_method: "GET",
|
|
338
|
+
path: "/v1/customers/external/{external_id}/payment-methods",
|
|
339
|
+
path_params: { "external_id" => external_id },
|
|
340
|
+
query: { "page" => page, "limit" => limit },
|
|
341
|
+
response_type: :json,
|
|
342
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
343
|
+
)
|
|
344
|
+
Models::ListResourcePaymentMethod.from_json(data)
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
# Enumerate every item of `list_payment_methods_external`, fetching pages on demand.
|
|
348
|
+
#
|
|
349
|
+
# @yieldparam item [Object]
|
|
350
|
+
# @return [Pago::Paginator] when called without a block.
|
|
351
|
+
def list_payment_methods_external_each(external_id, limit: 10, &block)
|
|
352
|
+
paginator = ::Pago::Paginator.new do |page_number|
|
|
353
|
+
list_payment_methods_external(external_id, page: page_number, limit: limit)
|
|
354
|
+
end
|
|
355
|
+
block ? paginator.each(&block) : paginator
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
class Members < ::Pago::Service
|
|
359
|
+
# Create a new member for a customer.
|
|
360
|
+
#
|
|
361
|
+
# Only B2B customers with the member management feature enabled can add members.
|
|
362
|
+
# The authenticated user or organization must have access to the customer's organization.
|
|
363
|
+
#
|
|
364
|
+
# **Scopes**: `members:write`
|
|
365
|
+
#
|
|
366
|
+
# @param id [String] The customer ID.
|
|
367
|
+
# @param body [Hash, Models::MemberCreateFromCustomer] the request body.
|
|
368
|
+
# @raise [Errors::NotPermitted] on HTTP 403.
|
|
369
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
370
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
371
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
372
|
+
# @return [Models::Member]
|
|
373
|
+
def create(id, body: {})
|
|
374
|
+
data = client.request(
|
|
375
|
+
http_method: "POST",
|
|
376
|
+
path: "/v1/customers/{id}/members",
|
|
377
|
+
path_params: { "id" => id },
|
|
378
|
+
query: {},
|
|
379
|
+
body: body,
|
|
380
|
+
response_type: :json,
|
|
381
|
+
errors: { 403 => Errors::NotPermitted, 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
382
|
+
)
|
|
383
|
+
Models::Member.from_json(data)
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Create a new member for a customer identified by its external ID.
|
|
387
|
+
#
|
|
388
|
+
# **Scopes**: `members:write`
|
|
389
|
+
#
|
|
390
|
+
# @param external_id_path [String] The customer external ID.
|
|
391
|
+
# @param body [Hash, Models::MemberCreateFromCustomer] the request body.
|
|
392
|
+
# @raise [Errors::NotPermitted] on HTTP 403.
|
|
393
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
394
|
+
# @raise [Errors::AmbiguousExternalCustomerID] on HTTP 409.
|
|
395
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
396
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
397
|
+
# @return [Models::Member]
|
|
398
|
+
def create_external(external_id_path, body: {})
|
|
399
|
+
data = client.request(
|
|
400
|
+
http_method: "POST",
|
|
401
|
+
path: "/v1/customers/external/{external_id}/members",
|
|
402
|
+
path_params: { "external_id" => external_id_path },
|
|
403
|
+
query: {},
|
|
404
|
+
body: body,
|
|
405
|
+
response_type: :json,
|
|
406
|
+
errors: { 403 => Errors::NotPermitted, 404 => Errors::ResourceNotFound, 409 => Errors::AmbiguousExternalCustomerID, 422 => Errors::HTTPValidationError }
|
|
407
|
+
)
|
|
408
|
+
Models::Member.from_json(data)
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
# Get a member of a customer by its ID.
|
|
412
|
+
#
|
|
413
|
+
# **Scopes**: `members:read` `members:write`
|
|
414
|
+
#
|
|
415
|
+
# @param id [String] The customer ID.
|
|
416
|
+
# @param member_id [String]
|
|
417
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
418
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
419
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
420
|
+
# @return [Models::Member]
|
|
421
|
+
def get(id, member_id)
|
|
422
|
+
data = client.request(
|
|
423
|
+
http_method: "GET",
|
|
424
|
+
path: "/v1/customers/{id}/members/{member_id}",
|
|
425
|
+
path_params: { "id" => id, "member_id" => member_id },
|
|
426
|
+
query: {},
|
|
427
|
+
response_type: :json,
|
|
428
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
429
|
+
)
|
|
430
|
+
Models::Member.from_json(data)
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
# Delete a member of a customer.
|
|
434
|
+
#
|
|
435
|
+
# **Scopes**: `members:write`
|
|
436
|
+
#
|
|
437
|
+
# @param id [String] The customer ID.
|
|
438
|
+
# @param member_id [String]
|
|
439
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
440
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
441
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
442
|
+
# @return [nil]
|
|
443
|
+
def delete(id, member_id)
|
|
444
|
+
client.request(
|
|
445
|
+
http_method: "DELETE",
|
|
446
|
+
path: "/v1/customers/{id}/members/{member_id}",
|
|
447
|
+
path_params: { "id" => id, "member_id" => member_id },
|
|
448
|
+
query: {},
|
|
449
|
+
response_type: :none,
|
|
450
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
451
|
+
)
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
# Update a member of a customer.
|
|
455
|
+
#
|
|
456
|
+
# Only name, email and role can be updated.
|
|
457
|
+
#
|
|
458
|
+
# **Scopes**: `members:write`
|
|
459
|
+
#
|
|
460
|
+
# @param id [String] The customer ID.
|
|
461
|
+
# @param member_id [String]
|
|
462
|
+
# @param body [Hash, Models::MemberUpdate] the request body.
|
|
463
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
464
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
465
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
466
|
+
# @return [Models::Member]
|
|
467
|
+
def update(id, member_id, body: {})
|
|
468
|
+
data = client.request(
|
|
469
|
+
http_method: "PATCH",
|
|
470
|
+
path: "/v1/customers/{id}/members/{member_id}",
|
|
471
|
+
path_params: { "id" => id, "member_id" => member_id },
|
|
472
|
+
query: {},
|
|
473
|
+
body: body,
|
|
474
|
+
response_type: :json,
|
|
475
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
476
|
+
)
|
|
477
|
+
Models::Member.from_json(data)
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
# Get a member by external ID for a customer identified by its external ID.
|
|
481
|
+
#
|
|
482
|
+
# **Scopes**: `members:read` `members:write`
|
|
483
|
+
#
|
|
484
|
+
# @param external_id [String] The customer external ID.
|
|
485
|
+
# @param member_external_id [String] The member external ID.
|
|
486
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
487
|
+
# @raise [Errors::AmbiguousExternalCustomerID] on HTTP 409.
|
|
488
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
489
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
490
|
+
# @return [Models::Member]
|
|
491
|
+
def get_external(external_id, member_external_id)
|
|
492
|
+
data = client.request(
|
|
493
|
+
http_method: "GET",
|
|
494
|
+
path: "/v1/customers/external/{external_id}/members/{member_external_id}",
|
|
495
|
+
path_params: { "external_id" => external_id, "member_external_id" => member_external_id },
|
|
496
|
+
query: {},
|
|
497
|
+
response_type: :json,
|
|
498
|
+
errors: { 404 => Errors::ResourceNotFound, 409 => Errors::AmbiguousExternalCustomerID, 422 => Errors::HTTPValidationError }
|
|
499
|
+
)
|
|
500
|
+
Models::Member.from_json(data)
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
# Delete a member by external ID for a customer identified by its external ID.
|
|
504
|
+
#
|
|
505
|
+
# **Scopes**: `members:write`
|
|
506
|
+
#
|
|
507
|
+
# @param external_id [String] The customer external ID.
|
|
508
|
+
# @param member_external_id [String] The member external ID.
|
|
509
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
510
|
+
# @raise [Errors::AmbiguousExternalCustomerID] on HTTP 409.
|
|
511
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
512
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
513
|
+
# @return [nil]
|
|
514
|
+
def delete_external(external_id, member_external_id)
|
|
515
|
+
client.request(
|
|
516
|
+
http_method: "DELETE",
|
|
517
|
+
path: "/v1/customers/external/{external_id}/members/{member_external_id}",
|
|
518
|
+
path_params: { "external_id" => external_id, "member_external_id" => member_external_id },
|
|
519
|
+
query: {},
|
|
520
|
+
response_type: :none,
|
|
521
|
+
errors: { 404 => Errors::ResourceNotFound, 409 => Errors::AmbiguousExternalCustomerID, 422 => Errors::HTTPValidationError }
|
|
522
|
+
)
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
# Update a member by external ID for a customer identified by its external ID.
|
|
526
|
+
#
|
|
527
|
+
# **Scopes**: `members:write`
|
|
528
|
+
#
|
|
529
|
+
# @param external_id [String] The customer external ID.
|
|
530
|
+
# @param member_external_id [String] The member external ID.
|
|
531
|
+
# @param body [Hash, Models::MemberUpdate] the request body.
|
|
532
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
533
|
+
# @raise [Errors::AmbiguousExternalCustomerID] on HTTP 409.
|
|
534
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
535
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
536
|
+
# @return [Models::Member]
|
|
537
|
+
def update_external(external_id, member_external_id, body: {})
|
|
538
|
+
data = client.request(
|
|
539
|
+
http_method: "PATCH",
|
|
540
|
+
path: "/v1/customers/external/{external_id}/members/{member_external_id}",
|
|
541
|
+
path_params: { "external_id" => external_id, "member_external_id" => member_external_id },
|
|
542
|
+
query: {},
|
|
543
|
+
body: body,
|
|
544
|
+
response_type: :json,
|
|
545
|
+
errors: { 404 => Errors::ResourceNotFound, 409 => Errors::AmbiguousExternalCustomerID, 422 => Errors::HTTPValidationError }
|
|
546
|
+
)
|
|
547
|
+
Models::Member.from_json(data)
|
|
548
|
+
end
|
|
549
|
+
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
end
|
|
555
|
+
end
|
|
556
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pago
|
|
4
|
+
module V2026_04
|
|
5
|
+
module Services
|
|
6
|
+
class Discounts < ::Pago::Service
|
|
7
|
+
# List discounts.
|
|
8
|
+
#
|
|
9
|
+
# **Scopes**: `discounts:read` `discounts:write`
|
|
10
|
+
#
|
|
11
|
+
# @param organization_id [String, Array<String>, nil] Filter by organization ID.
|
|
12
|
+
# @param query [String, nil] Filter by name.
|
|
13
|
+
# @param page [Integer] Page number, defaults to 1.
|
|
14
|
+
# @param limit [Integer] Size of a page, defaults to 10. Maximum is 100.
|
|
15
|
+
# @param sorting [Array<String>, nil] Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign `-` before the criteria name to sort by descending order.
|
|
16
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
17
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
18
|
+
# @return [Models::ListResourceDiscount]
|
|
19
|
+
def list(organization_id: nil, query: nil, page: 1, limit: 10, sorting: ["-created_at"])
|
|
20
|
+
data = client.request(
|
|
21
|
+
http_method: "GET",
|
|
22
|
+
path: "/v1/discounts/",
|
|
23
|
+
path_params: {},
|
|
24
|
+
query: { "organization_id" => organization_id, "query" => query, "page" => page, "limit" => limit, "sorting" => sorting },
|
|
25
|
+
response_type: :json,
|
|
26
|
+
errors: { 422 => Errors::HTTPValidationError }
|
|
27
|
+
)
|
|
28
|
+
Models::ListResourceDiscount.from_json(data)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Enumerate every item of `list`, fetching pages on demand.
|
|
32
|
+
#
|
|
33
|
+
# @yieldparam item [Object]
|
|
34
|
+
# @return [Pago::Paginator] when called without a block.
|
|
35
|
+
def list_each(organization_id: nil, query: nil, limit: 10, sorting: ["-created_at"], &block)
|
|
36
|
+
paginator = ::Pago::Paginator.new do |page_number|
|
|
37
|
+
list(organization_id: organization_id, query: query, page: page_number, limit: limit, sorting: sorting)
|
|
38
|
+
end
|
|
39
|
+
block ? paginator.each(&block) : paginator
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Create a discount.
|
|
43
|
+
#
|
|
44
|
+
# **Scopes**: `discounts:write`
|
|
45
|
+
#
|
|
46
|
+
# @param body [Hash, Object] the request body.
|
|
47
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
48
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
49
|
+
# @return [Object]
|
|
50
|
+
def create(body: {})
|
|
51
|
+
data = client.request(
|
|
52
|
+
http_method: "POST",
|
|
53
|
+
path: "/v1/discounts/",
|
|
54
|
+
path_params: {},
|
|
55
|
+
query: {},
|
|
56
|
+
body: body,
|
|
57
|
+
response_type: :json,
|
|
58
|
+
errors: { 422 => Errors::HTTPValidationError }
|
|
59
|
+
)
|
|
60
|
+
Unions::Discount.from_json(data)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Get a discount by ID.
|
|
64
|
+
#
|
|
65
|
+
# **Scopes**: `discounts:read` `discounts:write`
|
|
66
|
+
#
|
|
67
|
+
# @param id [String] The discount ID.
|
|
68
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
69
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
70
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
71
|
+
# @return [Object]
|
|
72
|
+
def get(id)
|
|
73
|
+
data = client.request(
|
|
74
|
+
http_method: "GET",
|
|
75
|
+
path: "/v1/discounts/{id}",
|
|
76
|
+
path_params: { "id" => id },
|
|
77
|
+
query: {},
|
|
78
|
+
response_type: :json,
|
|
79
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
80
|
+
)
|
|
81
|
+
Unions::Discount.from_json(data)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Delete a discount.
|
|
85
|
+
#
|
|
86
|
+
# **Scopes**: `discounts:write`
|
|
87
|
+
#
|
|
88
|
+
# @param id [String] The discount ID.
|
|
89
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
90
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
91
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
92
|
+
# @return [nil]
|
|
93
|
+
def delete(id)
|
|
94
|
+
client.request(
|
|
95
|
+
http_method: "DELETE",
|
|
96
|
+
path: "/v1/discounts/{id}",
|
|
97
|
+
path_params: { "id" => id },
|
|
98
|
+
query: {},
|
|
99
|
+
response_type: :none,
|
|
100
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
101
|
+
)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Update a discount.
|
|
105
|
+
#
|
|
106
|
+
# **Scopes**: `discounts:write`
|
|
107
|
+
#
|
|
108
|
+
# @param id [String] The discount ID.
|
|
109
|
+
# @param body [Hash, Models::DiscountUpdate] the request body.
|
|
110
|
+
# @raise [Errors::ResourceNotFound] on HTTP 404.
|
|
111
|
+
# @raise [Errors::HTTPValidationError] on HTTP 422.
|
|
112
|
+
# @raise [Pago::NetworkError] when the request never reached the API.
|
|
113
|
+
# @return [Object]
|
|
114
|
+
def update(id, body: {})
|
|
115
|
+
data = client.request(
|
|
116
|
+
http_method: "PATCH",
|
|
117
|
+
path: "/v1/discounts/{id}",
|
|
118
|
+
path_params: { "id" => id },
|
|
119
|
+
query: {},
|
|
120
|
+
body: body,
|
|
121
|
+
response_type: :json,
|
|
122
|
+
errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError }
|
|
123
|
+
)
|
|
124
|
+
Unions::Discount.from_json(data)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|