perata-sdk 0.1.1 → 0.3.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.
@@ -3,13 +3,152 @@
3
3
  # Code generated by sdk/generator. DO NOT EDIT.
4
4
 
5
5
  module Perata
6
+ # The API's benefits.
7
+ class BenefitsService
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ # Criar um benefício custom, license_key, feature_flag ou meter_credit; downloads e os benefícios do Discord e do GitHub se configuram no painel.
13
+ #
14
+ # @param params [BenefitsCreateParams, Hash]
15
+ # @return [Benefit]
16
+ def create(params, idempotency_key: nil, api_key: nil)
17
+ data = @client.request("POST", "/api/v1/benefits", body: BenefitsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
18
+ Benefit.from_hash(data)
19
+ end
20
+
21
+ # Excluir um benefício: ele sai de todos os produtos e é revogado de quem o tem. The API answers 204, so there is nothing to return.
22
+ #
23
+ # @return [nil]
24
+ def delete(benefit, idempotency_key: nil, api_key: nil)
25
+ @client.request("DELETE", "/api/v1/benefits/#{Perata.segment(benefit)}", idempotency_key: idempotency_key, api_key: api_key)
26
+ nil
27
+ end
28
+
29
+ # Ler um benefício.
30
+ #
31
+ # @return [Benefit]
32
+ def get(benefit, api_key: nil)
33
+ data = @client.request("GET", "/api/v1/benefits/#{Perata.segment(benefit)}", api_key: api_key)
34
+ Benefit.from_hash(data)
35
+ end
36
+
37
+ # Listar benefícios, opcionalmente de um tipo (type). One page; +list_iter+ walks every page.
38
+ #
39
+ # @return [Page<Benefit>]
40
+ def list(page: nil, limit: nil, type: nil, api_key: nil)
41
+ query = { "page" => page, "limit" => limit, "type" => type }
42
+ data = @client.request("GET", "/api/v1/benefits", query: query, api_key: api_key)
43
+ Page.from_hash(data) { |item| Benefit.from_hash(item) }
44
+ end
45
+
46
+ # Walks every page of benefits:list from +page+, item by item.
47
+ #
48
+ # @return [Enumerator<Benefit>]
49
+ def list_iter(page: nil, limit: nil, type: nil, api_key: nil, &block)
50
+ items = Page.iterate(page) do |at|
51
+ list(page: at, limit: limit, type: type, api_key: api_key)
52
+ end
53
+ block ? items.each(&block) : items
54
+ end
55
+
56
+ # Listar as concessões de um benefício, opcionalmente de um cliente (customer_id) ou só as vigentes (is_granted). One page; +list_grants_iter+ walks every page.
57
+ #
58
+ # @return [Page<BenefitGrant>]
59
+ def list_grants(benefit, page: nil, limit: nil, customer_id: nil, is_granted: nil, api_key: nil)
60
+ query = { "page" => page, "limit" => limit, "customer_id" => customer_id, "is_granted" => is_granted }
61
+ data = @client.request("GET", "/api/v1/benefits/#{Perata.segment(benefit)}/grants", query: query, api_key: api_key)
62
+ Page.from_hash(data) { |item| BenefitGrant.from_hash(item) }
63
+ end
64
+
65
+ # Walks every page of benefits:list_grants from +page+, item by item.
66
+ #
67
+ # @return [Enumerator<BenefitGrant>]
68
+ def list_grants_iter(benefit, page: nil, limit: nil, customer_id: nil, is_granted: nil, api_key: nil, &block)
69
+ items = Page.iterate(page) do |at|
70
+ list_grants(benefit, page: at, limit: limit, customer_id: customer_id, is_granted: is_granted, api_key: api_key)
71
+ end
72
+ block ? items.each(&block) : items
73
+ end
74
+
75
+ # Atualizar o nome, a visibilidade, as propriedades e os metadados de um benefício; o tipo e a descrição dada na criação não mudam, e o que a concessão já entregou fica como foi entregue.
76
+ #
77
+ # @param params [BenefitsUpdateParams, Hash]
78
+ # @return [Benefit]
79
+ def update(benefit, params, idempotency_key: nil, api_key: nil)
80
+ data = @client.request("PATCH", "/api/v1/benefits/#{Perata.segment(benefit)}", body: BenefitsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
81
+ Benefit.from_hash(data)
82
+ end
83
+ end
84
+
85
+ # The API's checkout-links.
86
+ class CheckoutLinksService
87
+ def initialize(client)
88
+ @client = client
89
+ end
90
+
91
+ # Criar um link de checkout: uma oferta durável de um ou mais produtos, com desconto, quantidade e páginas de retorno.
92
+ #
93
+ # @param params [CheckoutLinksCreateParams, Hash]
94
+ # @return [CheckoutLink]
95
+ def create(params, idempotency_key: nil, api_key: nil)
96
+ data = @client.request("POST", "/api/v1/checkout-links", body: CheckoutLinksCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
97
+ CheckoutLink.from_hash(data)
98
+ end
99
+
100
+ # Excluir um link de checkout: ele deixa de abrir checkouts; os que já abriu continuam. The API answers 204, so there is nothing to return.
101
+ #
102
+ # @return [nil]
103
+ def delete(checkout_link, idempotency_key: nil, api_key: nil)
104
+ @client.request("DELETE", "/api/v1/checkout-links/#{Perata.segment(checkout_link)}", idempotency_key: idempotency_key, api_key: api_key)
105
+ nil
106
+ end
107
+
108
+ # Ler um link de checkout.
109
+ #
110
+ # @return [CheckoutLink]
111
+ def get(checkout_link, api_key: nil)
112
+ data = @client.request("GET", "/api/v1/checkout-links/#{Perata.segment(checkout_link)}", api_key: api_key)
113
+ CheckoutLink.from_hash(data)
114
+ end
115
+
116
+ # Listar links de checkout. One page; +list_iter+ walks every page.
117
+ #
118
+ # @return [Page<CheckoutLink>]
119
+ def list(page: nil, limit: nil, api_key: nil)
120
+ query = { "page" => page, "limit" => limit }
121
+ data = @client.request("GET", "/api/v1/checkout-links", query: query, api_key: api_key)
122
+ Page.from_hash(data) { |item| CheckoutLink.from_hash(item) }
123
+ end
124
+
125
+ # Walks every page of checkout-links:list from +page+, item by item.
126
+ #
127
+ # @return [Enumerator<CheckoutLink>]
128
+ def list_iter(page: nil, limit: nil, api_key: nil, &block)
129
+ items = Page.iterate(page) do |at|
130
+ list(page: at, limit: limit, api_key: api_key)
131
+ end
132
+ block ? items.each(&block) : items
133
+ end
134
+
135
+ # Atualizar o rótulo, as páginas de retorno, os produtos e os metadados de um link; a quantidade e o desconto ficam como foram publicados.
136
+ #
137
+ # @param params [CheckoutLinksUpdateParams, Hash]
138
+ # @return [CheckoutLink]
139
+ def update(checkout_link, params, idempotency_key: nil, api_key: nil)
140
+ data = @client.request("PATCH", "/api/v1/checkout-links/#{Perata.segment(checkout_link)}", body: CheckoutLinksUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
141
+ CheckoutLink.from_hash(data)
142
+ end
143
+ end
144
+
6
145
  # The API's checkouts.
7
146
  class CheckoutsService
8
147
  def initialize(client)
9
148
  @client = client
10
149
  end
11
150
 
12
- # Create a checkout address for one product and price.
151
+ # Criar o endereço de um checkout para um produto e um preço.
13
152
  #
14
153
  # @param params [CheckoutsCreateParams, Hash]
15
154
  # @return [Checkout]
@@ -17,6 +156,39 @@ module Perata
17
156
  data = @client.request("POST", "/api/v1/checkouts", body: CheckoutsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
18
157
  Checkout.from_hash(data)
19
158
  end
159
+
160
+ # Ler um checkout: o endereço, o estado e as páginas de retorno.
161
+ #
162
+ # @return [Checkout]
163
+ def get(checkout, api_key: nil)
164
+ data = @client.request("GET", "/api/v1/checkouts/#{Perata.segment(checkout)}", api_key: api_key)
165
+ Checkout.from_hash(data)
166
+ end
167
+
168
+ # Atualizar o rótulo e as páginas de retorno de um checkout ativo.
169
+ #
170
+ # @param params [CheckoutsUpdateParams, Hash]
171
+ # @return [Checkout]
172
+ def update(checkout, params, idempotency_key: nil, api_key: nil)
173
+ data = @client.request("PATCH", "/api/v1/checkouts/#{Perata.segment(checkout)}", body: CheckoutsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
174
+ Checkout.from_hash(data)
175
+ end
176
+ end
177
+
178
+ # The API's customer-sessions.
179
+ class CustomerSessionsService
180
+ def initialize(client)
181
+ @client = client
182
+ end
183
+
184
+ # Entrar com um cliente no portal do cliente: o endereço o abre já autenticado.
185
+ #
186
+ # @param params [CustomerSessionsCreateParams, Hash]
187
+ # @return [CustomerSession]
188
+ def create(params, idempotency_key: nil, api_key: nil)
189
+ data = @client.request("POST", "/api/v1/customer-sessions", body: CustomerSessionsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
190
+ CustomerSession.from_hash(data)
191
+ end
20
192
  end
21
193
 
22
194
  # The API's customers.
@@ -25,7 +197,7 @@ module Perata
25
197
  @client = client
26
198
  end
27
199
 
28
- # Create a customer.
200
+ # Criar um cliente.
29
201
  #
30
202
  # @param params [CustomersCreateParams, Hash]
31
203
  # @return [Customer]
@@ -34,7 +206,15 @@ module Perata
34
206
  Customer.from_hash(data)
35
207
  end
36
208
 
37
- # Read a customer.
209
+ # Excluir um cliente: as assinaturas terminam na hora, os benefícios são revogados e o ID externo é liberado; pedidos e pagamentos continuam. The API answers 204, so there is nothing to return.
210
+ #
211
+ # @return [nil]
212
+ def delete(customer, idempotency_key: nil, api_key: nil)
213
+ @client.request("DELETE", "/api/v1/customers/#{Perata.segment(customer)}", idempotency_key: idempotency_key, api_key: api_key)
214
+ nil
215
+ end
216
+
217
+ # Ler um cliente.
38
218
  #
39
219
  # @return [Customer]
40
220
  def get(customer, api_key: nil)
@@ -42,7 +222,23 @@ module Perata
42
222
  Customer.from_hash(data)
43
223
  end
44
224
 
45
- # List customers. One page; +list_iter+ walks every page.
225
+ # Ler um cliente pelo ID dele no sistema do lojista (external_id).
226
+ #
227
+ # @return [Customer]
228
+ def get_external(external_id, api_key: nil)
229
+ data = @client.request("GET", "/api/v1/external-customers/#{Perata.segment(external_id)}", api_key: api_key)
230
+ Customer.from_hash(data)
231
+ end
232
+
233
+ # Ler o estado de um cliente: assinaturas ativas e benefícios vigentes, inclusive os feature flags.
234
+ #
235
+ # @return [CustomerState]
236
+ def get_state(customer, api_key: nil)
237
+ data = @client.request("GET", "/api/v1/customers/#{Perata.segment(customer)}/state", api_key: api_key)
238
+ CustomerState.from_hash(data)
239
+ end
240
+
241
+ # Listar clientes. One page; +list_iter+ walks every page.
46
242
  #
47
243
  # @return [Page<Customer>]
48
244
  def list(page: nil, limit: nil, api_key: nil)
@@ -60,6 +256,178 @@ module Perata
60
256
  end
61
257
  block ? items.each(&block) : items
62
258
  end
259
+
260
+ # Atualizar o nome, o e-mail ou o ID externo de um cliente; o ID externo não muda depois de definido.
261
+ #
262
+ # @param params [CustomersUpdateParams, Hash]
263
+ # @return [Customer]
264
+ def update(customer, params, idempotency_key: nil, api_key: nil)
265
+ data = @client.request("PATCH", "/api/v1/customers/#{Perata.segment(customer)}", body: CustomersUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
266
+ Customer.from_hash(data)
267
+ end
268
+
269
+ # Atualizar um cliente pelo ID dele no sistema do lojista (external_id).
270
+ #
271
+ # @param params [CustomersUpdateExternalParams, Hash]
272
+ # @return [Customer]
273
+ def update_external(external_id, params, idempotency_key: nil, api_key: nil)
274
+ data = @client.request("PATCH", "/api/v1/external-customers/#{Perata.segment(external_id)}", body: CustomersUpdateExternalParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
275
+ Customer.from_hash(data)
276
+ end
277
+ end
278
+
279
+ # The API's discounts.
280
+ class DiscountsService
281
+ def initialize(client)
282
+ @client = client
283
+ end
284
+
285
+ # Criar um desconto percentual (basis_points) ou fixo em reais (amount_cents).
286
+ #
287
+ # @param params [DiscountsCreateParams, Hash]
288
+ # @return [Discount]
289
+ def create(params, idempotency_key: nil, api_key: nil)
290
+ data = @client.request("POST", "/api/v1/discounts", body: DiscountsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
291
+ Discount.from_hash(data)
292
+ end
293
+
294
+ # Excluir um desconto: sai das listas e dos checkouts e o código fica livre; o que ele já descontou continua nos registros. The API answers 204, so there is nothing to return.
295
+ #
296
+ # @return [nil]
297
+ def delete(discount, idempotency_key: nil, api_key: nil)
298
+ @client.request("DELETE", "/api/v1/discounts/#{Perata.segment(discount)}", idempotency_key: idempotency_key, api_key: api_key)
299
+ nil
300
+ end
301
+
302
+ # Ler um desconto.
303
+ #
304
+ # @return [Discount]
305
+ def get(discount, api_key: nil)
306
+ data = @client.request("GET", "/api/v1/discounts/#{Perata.segment(discount)}", api_key: api_key)
307
+ Discount.from_hash(data)
308
+ end
309
+
310
+ # Listar descontos. One page; +list_iter+ walks every page.
311
+ #
312
+ # @return [Page<Discount>]
313
+ def list(page: nil, limit: nil, api_key: nil)
314
+ query = { "page" => page, "limit" => limit }
315
+ data = @client.request("GET", "/api/v1/discounts", query: query, api_key: api_key)
316
+ Page.from_hash(data) { |item| Discount.from_hash(item) }
317
+ end
318
+
319
+ # Walks every page of discounts:list from +page+, item by item.
320
+ #
321
+ # @return [Enumerator<Discount>]
322
+ def list_iter(page: nil, limit: nil, api_key: nil, &block)
323
+ items = Page.iterate(page) do |at|
324
+ list(page: at, limit: limit, api_key: api_key)
325
+ end
326
+ block ? items.each(&block) : items
327
+ end
328
+
329
+ # Atualizar um desconto; o tipo e a duração não mudam, e depois do primeiro uso o valor e os meses também não.
330
+ #
331
+ # @param params [DiscountsUpdateParams, Hash]
332
+ # @return [Discount]
333
+ def update(discount, params, idempotency_key: nil, api_key: nil)
334
+ data = @client.request("PATCH", "/api/v1/discounts/#{Perata.segment(discount)}", body: DiscountsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
335
+ Discount.from_hash(data)
336
+ end
337
+ end
338
+
339
+ # The API's disputes.
340
+ class DisputesService
341
+ def initialize(client)
342
+ @client = client
343
+ end
344
+
345
+ # Ler uma disputa.
346
+ #
347
+ # @return [Dispute]
348
+ def get(dispute, api_key: nil)
349
+ data = @client.request("GET", "/api/v1/disputes/#{Perata.segment(dispute)}", api_key: api_key)
350
+ Dispute.from_hash(data)
351
+ end
352
+
353
+ # Listar disputas, opcionalmente de um status (status). One page; +list_iter+ walks every page.
354
+ #
355
+ # @return [Page<Dispute>]
356
+ def list(page: nil, limit: nil, status: nil, api_key: nil)
357
+ query = { "page" => page, "limit" => limit, "status" => status }
358
+ data = @client.request("GET", "/api/v1/disputes", query: query, api_key: api_key)
359
+ Page.from_hash(data) { |item| Dispute.from_hash(item) }
360
+ end
361
+
362
+ # Walks every page of disputes:list from +page+, item by item.
363
+ #
364
+ # @return [Enumerator<Dispute>]
365
+ def list_iter(page: nil, limit: nil, status: nil, api_key: nil, &block)
366
+ items = Page.iterate(page) do |at|
367
+ list(page: at, limit: limit, status: status, api_key: api_key)
368
+ end
369
+ block ? items.each(&block) : items
370
+ end
371
+ end
372
+
373
+ # The API's events.
374
+ class EventsService
375
+ def initialize(client)
376
+ @client = client
377
+ end
378
+
379
+ # Listar os eventos de consumo que as origens enviaram, do mais novo ao mais antigo. One page; +list_iter+ walks every page.
380
+ #
381
+ # @return [Page<Event>]
382
+ def list(page: nil, limit: nil, customer_id: nil, start: nil, end_: nil, api_key: nil)
383
+ query = { "page" => page, "limit" => limit, "customer_id" => customer_id, "start" => start, "end" => end_ }
384
+ data = @client.request("GET", "/api/v1/events", query: query, api_key: api_key)
385
+ Page.from_hash(data) { |item| Event.from_hash(item) }
386
+ end
387
+
388
+ # Walks every page of events:list from +page+, item by item.
389
+ #
390
+ # @return [Enumerator<Event>]
391
+ def list_iter(page: nil, limit: nil, customer_id: nil, start: nil, end_: nil, api_key: nil, &block)
392
+ items = Page.iterate(page) do |at|
393
+ list(page: at, limit: limit, customer_id: customer_id, start: start, end_: end_, api_key: api_key)
394
+ end
395
+ block ? items.each(&block) : items
396
+ end
397
+ end
398
+
399
+ # The API's meters.
400
+ class MetersService
401
+ def initialize(client)
402
+ @client = client
403
+ end
404
+
405
+ # Ler um medidor: o filtro dos eventos que ele conta, a agregação e a unidade.
406
+ #
407
+ # @return [Meter]
408
+ def get(meter, api_key: nil)
409
+ data = @client.request("GET", "/api/v1/meters/#{Perata.segment(meter)}", api_key: api_key)
410
+ Meter.from_hash(data)
411
+ end
412
+
413
+ # Listar medidores; os arquivados só com is_archived=true. One page; +list_iter+ walks every page.
414
+ #
415
+ # @return [Page<Meter>]
416
+ def list(page: nil, limit: nil, is_archived: nil, api_key: nil)
417
+ query = { "page" => page, "limit" => limit, "is_archived" => is_archived }
418
+ data = @client.request("GET", "/api/v1/meters", query: query, api_key: api_key)
419
+ Page.from_hash(data) { |item| Meter.from_hash(item) }
420
+ end
421
+
422
+ # Walks every page of meters:list from +page+, item by item.
423
+ #
424
+ # @return [Enumerator<Meter>]
425
+ def list_iter(page: nil, limit: nil, is_archived: nil, api_key: nil, &block)
426
+ items = Page.iterate(page) do |at|
427
+ list(page: at, limit: limit, is_archived: is_archived, api_key: api_key)
428
+ end
429
+ block ? items.each(&block) : items
430
+ end
63
431
  end
64
432
 
65
433
  # The API's orders.
@@ -68,7 +436,31 @@ module Perata
68
436
  @client = client
69
437
  end
70
438
 
71
- # List orders: paid checkouts. One page; +list_iter+ walks every page.
439
+ # Ler um pedido: um checkout pago.
440
+ #
441
+ # @return [Order]
442
+ def get(order, api_key: nil)
443
+ data = @client.request("GET", "/api/v1/orders/#{Perata.segment(order)}", api_key: api_key)
444
+ Order.from_hash(data)
445
+ end
446
+
447
+ # Ler a fatura de um pedido, o documento comercial que o lojista gerou; sem ela, 404.
448
+ #
449
+ # @return [OrderInvoice]
450
+ def get_invoice(order, api_key: nil)
451
+ data = @client.request("GET", "/api/v1/orders/#{Perata.segment(order)}/invoice", api_key: api_key)
452
+ OrderInvoice.from_hash(data)
453
+ end
454
+
455
+ # Ler o recibo de um pedido: o que foi pago, quando e como.
456
+ #
457
+ # @return [OrderReceipt]
458
+ def get_receipt(order, api_key: nil)
459
+ data = @client.request("GET", "/api/v1/orders/#{Perata.segment(order)}/receipt", api_key: api_key)
460
+ OrderReceipt.from_hash(data)
461
+ end
462
+
463
+ # Listar pedidos: checkouts pagos. One page; +list_iter+ walks every page.
72
464
  #
73
465
  # @return [Page<Order>]
74
466
  def list(page: nil, limit: nil, api_key: nil)
@@ -94,7 +486,7 @@ module Perata
94
486
  @client = client
95
487
  end
96
488
 
97
- # Stop charging a stored card; refused while an active subscription charges it.
489
+ # Parar de cobrar um cartão guardado; recusado enquanto uma assinatura ativa o cobra.
98
490
  #
99
491
  # @return [PaymentMethodDetached]
100
492
  def detach(payment_method, idempotency_key: nil, api_key: nil)
@@ -102,7 +494,7 @@ module Perata
102
494
  PaymentMethodDetached.from_hash(data)
103
495
  end
104
496
 
105
- # List a customer's stored cards: brand, last four digits and expiry. One page; +list_iter+ walks every page.
497
+ # Listar os cartões guardados de um cliente: bandeira, quatro últimos dígitos e validade. One page; +list_iter+ walks every page.
106
498
  #
107
499
  # @return [Page<PaymentMethod>]
108
500
  def list(customer, page: nil, limit: nil, api_key: nil)
@@ -128,7 +520,7 @@ module Perata
128
520
  @client = client
129
521
  end
130
522
 
131
- # Read a payment.
523
+ # Ler um pagamento.
132
524
  #
133
525
  # @return [Payment]
134
526
  def get(payment, api_key: nil)
@@ -136,7 +528,7 @@ module Perata
136
528
  Payment.from_hash(data)
137
529
  end
138
530
 
139
- # List payments. One page; +list_iter+ walks every page.
531
+ # Listar pagamentos. One page; +list_iter+ walks every page.
140
532
  #
141
533
  # @return [Page<Payment>]
142
534
  def list(page: nil, limit: nil, api_key: nil)
@@ -162,7 +554,7 @@ module Perata
162
554
  @client = client
163
555
  end
164
556
 
165
- # Create a BRL price, one-time or recurring.
557
+ # Criar um preço em reais, avulso ou recorrente.
166
558
  #
167
559
  # @param params [PricesCreateParams, Hash]
168
560
  # @return [Price]
@@ -171,7 +563,7 @@ module Perata
171
563
  Price.from_hash(data)
172
564
  end
173
565
 
174
- # List prices, optionally of one product (product_id). One page; +list_iter+ walks every page.
566
+ # Listar preços, opcionalmente de um produto (product_id). One page; +list_iter+ walks every page.
175
567
  #
176
568
  # @return [Page<Price>]
177
569
  def list(page: nil, limit: nil, product_id: nil, api_key: nil)
@@ -197,7 +589,15 @@ module Perata
197
589
  @client = client
198
590
  end
199
591
 
200
- # Create a product.
592
+ # Arquivar um produto: sai das vendas novas e o que já foi vendido continua apontando para ele.
593
+ #
594
+ # @return [Product]
595
+ def archive(product, idempotency_key: nil, api_key: nil)
596
+ data = @client.request("POST", "/api/v1/products/#{Perata.segment(product)}/archive", idempotency_key: idempotency_key, api_key: api_key)
597
+ Product.from_hash(data)
598
+ end
599
+
600
+ # Criar um produto.
201
601
  #
202
602
  # @param params [ProductsCreateParams, Hash]
203
603
  # @return [Product]
@@ -206,7 +606,7 @@ module Perata
206
606
  Product.from_hash(data)
207
607
  end
208
608
 
209
- # Read a product.
609
+ # Ler um produto.
210
610
  #
211
611
  # @return [Product]
212
612
  def get(product, api_key: nil)
@@ -214,7 +614,7 @@ module Perata
214
614
  Product.from_hash(data)
215
615
  end
216
616
 
217
- # List products. One page; +list_iter+ walks every page.
617
+ # Listar produtos. One page; +list_iter+ walks every page.
218
618
  #
219
619
  # @return [Page<Product>]
220
620
  def list(page: nil, limit: nil, api_key: nil)
@@ -232,6 +632,15 @@ module Perata
232
632
  end
233
633
  block ? items.each(&block) : items
234
634
  end
635
+
636
+ # Atualizar o nome ou a descrição de um produto ativo.
637
+ #
638
+ # @param params [ProductsUpdateParams, Hash]
639
+ # @return [Product]
640
+ def update(product, params, idempotency_key: nil, api_key: nil)
641
+ data = @client.request("PATCH", "/api/v1/products/#{Perata.segment(product)}", body: ProductsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
642
+ Product.from_hash(data)
643
+ end
235
644
  end
236
645
 
237
646
  # The API's refunds.
@@ -240,7 +649,7 @@ module Perata
240
649
  @client = client
241
650
  end
242
651
 
243
- # Refund part or all of a payment.
652
+ # Reembolsar parte ou todo um pagamento.
244
653
  #
245
654
  # @param params [RefundsCreateParams, Hash]
246
655
  # @return [Refund]
@@ -248,6 +657,25 @@ module Perata
248
657
  data = @client.request("POST", "/api/v1/refunds", body: RefundsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
249
658
  Refund.from_hash(data)
250
659
  end
660
+
661
+ # Listar reembolsos, opcionalmente de um pagamento (payment_id). One page; +list_iter+ walks every page.
662
+ #
663
+ # @return [Page<Refund>]
664
+ def list(page: nil, limit: nil, payment_id: nil, api_key: nil)
665
+ query = { "page" => page, "limit" => limit, "payment_id" => payment_id }
666
+ data = @client.request("GET", "/api/v1/refunds", query: query, api_key: api_key)
667
+ Page.from_hash(data) { |item| Refund.from_hash(item) }
668
+ end
669
+
670
+ # Walks every page of refunds:list from +page+, item by item.
671
+ #
672
+ # @return [Enumerator<Refund>]
673
+ def list_iter(page: nil, limit: nil, payment_id: nil, api_key: nil, &block)
674
+ items = Page.iterate(page) do |at|
675
+ list(page: at, limit: limit, payment_id: payment_id, api_key: api_key)
676
+ end
677
+ block ? items.each(&block) : items
678
+ end
251
679
  end
252
680
 
253
681
  # The API's subscriptions.
@@ -256,7 +684,7 @@ module Perata
256
684
  @client = client
257
685
  end
258
686
 
259
- # Cancel a subscription, by default at the end of its period.
687
+ # Cancelar uma assinatura, por padrão no fim do período.
260
688
  #
261
689
  # @param params [SubscriptionsCancelParams, Hash]
262
690
  # @return [Subscription]
@@ -265,7 +693,7 @@ module Perata
265
693
  Subscription.from_hash(data)
266
694
  end
267
695
 
268
- # Read a subscription.
696
+ # Ler uma assinatura.
269
697
  #
270
698
  # @return [Subscription]
271
699
  def get(subscription, api_key: nil)
@@ -273,7 +701,7 @@ module Perata
273
701
  Subscription.from_hash(data)
274
702
  end
275
703
 
276
- # List subscriptions, optionally of one customer (customer_id). One page; +list_iter+ walks every page.
704
+ # Listar assinaturas, opcionalmente de um cliente (customer_id). One page; +list_iter+ walks every page.
277
705
  #
278
706
  # @return [Page<Subscription>]
279
707
  def list(page: nil, limit: nil, customer_id: nil, api_key: nil)
@@ -291,5 +719,93 @@ module Perata
291
719
  end
292
720
  block ? items.each(&block) : items
293
721
  end
722
+
723
+ # Trocar o plano de uma assinatura: outro preço e, se quiser, outra quantidade, com a forma de ratear a diferença (proration_behavior).
724
+ #
725
+ # @param params [SubscriptionsUpdateParams, Hash]
726
+ # @return [Subscription]
727
+ def update(subscription, params, idempotency_key: nil, api_key: nil)
728
+ data = @client.request("PATCH", "/api/v1/subscriptions/#{Perata.segment(subscription)}", body: SubscriptionsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
729
+ Subscription.from_hash(data)
730
+ end
731
+ end
732
+
733
+ # The API's webhooks.
734
+ class WebhooksService
735
+ def initialize(client)
736
+ @client = client
737
+ end
738
+
739
+ # Criar um endpoint de webhook; o segredo que assina as mensagens vem só nesta resposta.
740
+ #
741
+ # @param params [WebhooksCreateEndpointParams, Hash]
742
+ # @return [WebhookEndpointCreated]
743
+ def create_endpoint(params, idempotency_key: nil, api_key: nil)
744
+ data = @client.request("POST", "/api/v1/webhooks/endpoints", body: WebhooksCreateEndpointParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
745
+ WebhookEndpointCreated.from_hash(data)
746
+ end
747
+
748
+ # Excluir um endpoint de webhook; as entregas que ainda esperavam por ele falham. The API answers 204, so there is nothing to return.
749
+ #
750
+ # @return [nil]
751
+ def delete_endpoint(endpoint, idempotency_key: nil, api_key: nil)
752
+ @client.request("DELETE", "/api/v1/webhooks/endpoints/#{Perata.segment(endpoint)}", idempotency_key: idempotency_key, api_key: api_key)
753
+ nil
754
+ end
755
+
756
+ # Ler um endpoint de webhook.
757
+ #
758
+ # @return [WebhookEndpoint]
759
+ def get_endpoint(endpoint, api_key: nil)
760
+ data = @client.request("GET", "/api/v1/webhooks/endpoints/#{Perata.segment(endpoint)}", api_key: api_key)
761
+ WebhookEndpoint.from_hash(data)
762
+ end
763
+
764
+ # Listar as últimas 100 entregas de eventos aos endpoints, opcionalmente de um endpoint (endpoint_id) ou de uma situação (status). One page; +list_deliveries_iter+ walks every page.
765
+ #
766
+ # @return [Page<WebhookDelivery>]
767
+ def list_deliveries(page: nil, limit: nil, endpoint_id: nil, status: nil, api_key: nil)
768
+ query = { "page" => page, "limit" => limit, "endpoint_id" => endpoint_id, "status" => status }
769
+ data = @client.request("GET", "/api/v1/webhooks/deliveries", query: query, api_key: api_key)
770
+ Page.from_hash(data) { |item| WebhookDelivery.from_hash(item) }
771
+ end
772
+
773
+ # Walks every page of webhooks:list_deliveries from +page+, item by item.
774
+ #
775
+ # @return [Enumerator<WebhookDelivery>]
776
+ def list_deliveries_iter(page: nil, limit: nil, endpoint_id: nil, status: nil, api_key: nil, &block)
777
+ items = Page.iterate(page) do |at|
778
+ list_deliveries(page: at, limit: limit, endpoint_id: endpoint_id, status: status, api_key: api_key)
779
+ end
780
+ block ? items.each(&block) : items
781
+ end
782
+
783
+ # Listar os endpoints de webhook do lojista. One page; +list_endpoints_iter+ walks every page.
784
+ #
785
+ # @return [Page<WebhookEndpoint>]
786
+ def list_endpoints(page: nil, limit: nil, api_key: nil)
787
+ query = { "page" => page, "limit" => limit }
788
+ data = @client.request("GET", "/api/v1/webhooks/endpoints", query: query, api_key: api_key)
789
+ Page.from_hash(data) { |item| WebhookEndpoint.from_hash(item) }
790
+ end
791
+
792
+ # Walks every page of webhooks:list_endpoints from +page+, item by item.
793
+ #
794
+ # @return [Enumerator<WebhookEndpoint>]
795
+ def list_endpoints_iter(page: nil, limit: nil, api_key: nil, &block)
796
+ items = Page.iterate(page) do |at|
797
+ list_endpoints(page: at, limit: limit, api_key: api_key)
798
+ end
799
+ block ? items.each(&block) : items
800
+ end
801
+
802
+ # Atualizar o endereço, o formato, os eventos ou a descrição de um endpoint, ou ligar e desligar o envio (enabled); o segredo não muda.
803
+ #
804
+ # @param params [WebhooksUpdateEndpointParams, Hash]
805
+ # @return [WebhookEndpoint]
806
+ def update_endpoint(endpoint, params, idempotency_key: nil, api_key: nil)
807
+ data = @client.request("PATCH", "/api/v1/webhooks/endpoints/#{Perata.segment(endpoint)}", body: WebhooksUpdateEndpointParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
808
+ WebhookEndpoint.from_hash(data)
809
+ end
294
810
  end
295
811
  end