starkbank 2.2.1 → 2.6.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/balance/balance.rb +2 -2
  3. data/lib/boleto/boleto.rb +53 -14
  4. data/lib/boleto/log.rb +36 -5
  5. data/lib/boleto_holmes/boleto_holmes.rb +41 -6
  6. data/lib/boleto_holmes/log.rb +36 -5
  7. data/lib/boleto_payment/boleto_payment.rb +42 -9
  8. data/lib/boleto_payment/log.rb +36 -5
  9. data/lib/brcode_payment/brcode_payment.rb +56 -17
  10. data/lib/brcode_payment/log.rb +36 -5
  11. data/lib/brcode_preview/brcode_preview.rb +5 -3
  12. data/lib/darf_payment/darf_payment.rb +218 -0
  13. data/lib/darf_payment/log.rb +125 -0
  14. data/lib/deposit/deposit.rb +46 -8
  15. data/lib/deposit/log.rb +36 -5
  16. data/lib/dict_key/dict_key.rb +45 -9
  17. data/lib/error.rb +13 -5
  18. data/lib/event/attempt.rb +125 -0
  19. data/lib/event/event.rb +44 -8
  20. data/lib/institution/institution.rb +67 -0
  21. data/lib/invoice/invoice.rb +81 -15
  22. data/lib/invoice/log.rb +52 -5
  23. data/lib/invoice/payment.rb +57 -0
  24. data/lib/payment_preview/boleto_preview.rb +75 -0
  25. data/lib/payment_preview/brcode_preview.rb +75 -0
  26. data/lib/payment_preview/payment_preview.rb +67 -0
  27. data/lib/payment_preview/tax_preview.rb +45 -0
  28. data/lib/payment_preview/utility_preview.rb +45 -0
  29. data/lib/payment_request/payment_request.rb +53 -11
  30. data/lib/starkbank.rb +14 -0
  31. data/lib/tax_payment/log.rb +125 -0
  32. data/lib/tax_payment/tax_payment.rb +203 -0
  33. data/lib/transaction/transaction.rb +39 -6
  34. data/lib/transfer/log.rb +36 -5
  35. data/lib/transfer/transfer.rb +59 -14
  36. data/lib/user/organization.rb +54 -0
  37. data/lib/user/project.rb +11 -6
  38. data/lib/user/user.rb +0 -4
  39. data/lib/utility_payment/log.rb +36 -5
  40. data/lib/utility_payment/utility_payment.rb +42 -9
  41. data/lib/utils/api.rb +1 -0
  42. data/lib/utils/request.rb +1 -1
  43. data/lib/utils/resource.rb +2 -21
  44. data/lib/utils/rest.rb +29 -14
  45. data/lib/utils/sub_resource.rb +28 -0
  46. data/lib/utils/url.rb +3 -1
  47. data/lib/webhook/webhook.rb +30 -9
  48. data/lib/workspace/workspace.rb +141 -0
  49. metadata +22 -7
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('invoice')
5
+
6
+ module StarkBank
7
+ class Invoice
8
+ # # Payment object
9
+ #
10
+ # When an Invoice is paid, its InvoicePayment sub-resource will become available.
11
+ # It carries all the available information about the invoice payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - amount [long]: amount in cents that was paid. ex: 1234 (= R$ 12.34)
15
+ # - name [string]: payer full name. ex: 'Anthony Edward Stark'
16
+ # - tax_id [string]: payer tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
17
+ # - bank_code [string]: code of the payer bank institution in Brazil. ex: '20018183'
18
+ # - branch_code [string]: payer bank account branch. ex: '1357-9'
19
+ # - account_number [string]: payer bank account number. ex: '876543-2'
20
+ # - account_type [string]: payer bank account type. ex: 'checking', 'savings', 'salary' or 'payment'
21
+ # - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
22
+ # - method [string]: payment method that was used. ex: 'pix'
23
+ class Payment < StarkBank::Utils::SubResource
24
+ attr_reader :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :amount, :end_to_end_id, :method
25
+ def initialize(name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, amount:, end_to_end_id:, method:)
26
+ @name = name
27
+ @tax_id = tax_id
28
+ @bank_code = bank_code
29
+ @branch_code = branch_code
30
+ @account_number = account_number
31
+ @account_type = account_type
32
+ @amount = amount
33
+ @end_to_end_id = end_to_end_id
34
+ @method = method
35
+ end
36
+
37
+ def self.resource
38
+ {
39
+ sub_resource_name: 'Payment',
40
+ sub_resource_maker: proc { |json|
41
+ Payment.new(
42
+ name: json['name'],
43
+ tax_id: json['tax_id'],
44
+ bank_code: json['bank_code'],
45
+ branch_code: json['branch_code'],
46
+ account_number: json['account_number'],
47
+ account_type: json['account_type'],
48
+ amount: json['amount'],
49
+ end_to_end_id: json['end_to_end_id'],
50
+ method: json['method']
51
+ )
52
+ }
53
+ }
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class PaymentPreview
9
+ # # BoletoPreview object
10
+ #
11
+ # A BoletoPreview is used to get information from a Boleto payment you received before confirming the payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - status [string]: current boleto status. ex: 'active', 'expired' or 'inactive'
15
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
16
+ # - discount_amount [int]: discount amount to be paid. ex: 23456 (= R$ 234.56)
17
+ # - fine_amount [int]: fine amount to be paid. ex: 23456 (= R$ 234.56)
18
+ # - interest_amount [int]: interest amount to be paid. ex: 23456 (= R$ 234.56)
19
+ # - due [DateTime or string]: Boleto due date. ex: '2020-04-30'
20
+ # - expiration [DateTime or string]: Boleto expiration date. ex: '2020-04-30'
21
+ # - name [string]: beneficiary full name. ex: 'Anthony Edward Stark'
22
+ # - tax_id [string]: beneficiary tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
23
+ # - receiver_name [string]: receiver (Sacador Avalista) full name. ex: 'Anthony Edward Stark'
24
+ # - receiver_tax_id [string]: receiver (Sacador Avalista) tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
25
+ # - payer_name [string]: payer full name. ex: 'Anthony Edward Stark'
26
+ # - payer_tax_id [string]: payer tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
27
+ # - line [string]: Number sequence that identifies the payment. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062'
28
+ # - bar_code [string]: Bar code number that identifies the payment. ex: '34195819600000000621090063571277307144464000'
29
+ class BoletoPreview < StarkBank::Utils::SubResource
30
+ attr_reader :status, :amount, :discount_amount, :fine_amount, :interest_amount, :due, :expiration, :name, :tax_id, :receiver_name, :receiver_tax_id, :payer_name, :payer_tax_id, :line, :bar_code
31
+ def initialize(status:, amount:, discount_amount:, fine_amount:, interest_amount:, due:, expiration:, name:, tax_id:, receiver_name:, receiver_tax_id:, payer_name:, payer_tax_id:, line:, bar_code:)
32
+ @status = status
33
+ @amount = amount
34
+ @discount_amount = discount_amount
35
+ @fine_amount = fine_amount
36
+ @interest_amount = interest_amount
37
+ @due = StarkBank::Utils::Checks.check_datetime(due)
38
+ @expiration = StarkBank::Utils::Checks.check_datetime(expiration)
39
+ @name = name
40
+ @tax_id = tax_id
41
+ @receiver_name = receiver_name
42
+ @receiver_tax_id = receiver_tax_id
43
+ @payer_name = payer_name
44
+ @payer_tax_id = payer_tax_id
45
+ @line = line
46
+ @bar_code = bar_code
47
+ end
48
+
49
+ def self.resource
50
+ {
51
+ resource_name: 'BoletoPreview',
52
+ resource_maker: proc { |json|
53
+ BoletoPreview.new(
54
+ status: json['status'],
55
+ amount: json['amount'],
56
+ discount_amount: json['discount_amount'],
57
+ fine_amount: json['fine_amount'],
58
+ interest_amount: json['interest_amount'],
59
+ due: json['due'],
60
+ expiration: json['expiration'],
61
+ name: json['name'],
62
+ tax_id: json['tax_id'],
63
+ receiver_name: json['receiver_name'],
64
+ receiver_tax_id: json['receiver_tax_id'],
65
+ payer_name: json['payer_name'],
66
+ payer_tax_id: json['payer_tax_id'],
67
+ line: json['line'],
68
+ bar_code: json['bar_code'],
69
+ )
70
+ }
71
+ }
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class PaymentPreview
9
+ # # BrcodePreview object
10
+ #
11
+ # A BrcodePreview is used to get information from a BR Code you received before confirming the payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - status [string]: Payment status. ex: 'active', 'paid', 'canceled' or 'unknown'
15
+ # - name [string]: Payment receiver name. ex: 'Tony Stark'
16
+ # - tax_id [string]: Payment receiver tax ID. ex: '012.345.678-90'
17
+ # - bank_code [string]: Payment receiver bank code. ex: '20018183'
18
+ # - branch_code [string]: Payment receiver branch code. ex: '0001'
19
+ # - account_number [string]: Payment receiver account number. ex: '1234567'
20
+ # - account_type [string]: Payment receiver account type. ex: 'checking'
21
+ # - allow_change [bool]: If True, the payment is able to receive amounts that are different from the nominal one. ex: True or False
22
+ # - amount [integer]: Value in cents that this payment is expecting to receive. If 0, any value is accepted. ex: 123 (= R$1,23)
23
+ # - nominal_amount [integer]: Original value in cents that this payment was expecting to receive without the discounts, fines, etc.. If 0, any value is accepted. ex: 123 (= R$1,23)
24
+ # - interest_amount [integer]: Current interest value in cents that this payment is charging. If 0, any value is accepted. ex: 123 (= R$1,23)
25
+ # - fine_amount [integer]: Current fine value in cents that this payment is charging. ex: 123 (= R$1,23)
26
+ # - reduction_amount [integer]: Current value reduction value in cents that this payment is expecting. ex: 123 (= R$1,23)
27
+ # - discount_amount [integer]: Current discount value in cents that this payment is expecting. ex: 123 (= R$1,23)
28
+ # - reconciliation_id [string]: Reconciliation ID linked to this payment. ex: 'txId', 'payment-123'
29
+ class BrcodePreview < StarkBank::Utils::SubResource
30
+ attr_reader :status, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :allow_change, :amount, :nominal_amount, :interest_amount, :fine_amount, :reduction_amount, :discount_amount, :reconciliation_id
31
+ def initialize(status:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, allow_change:, amount:, nominal_amount:, interest_amount:, fine_amount:, reduction_amount:, discount_amount:, reconciliation_id:)
32
+ @status = status
33
+ @name = name
34
+ @tax_id = tax_id
35
+ @bank_code = bank_code
36
+ @branch_code = branch_code
37
+ @account_number = account_number
38
+ @account_type = account_type
39
+ @allow_change = allow_change
40
+ @amount = amount
41
+ @nominal_amount = nominal_amount
42
+ @interest_amount = interest_amount
43
+ @fine_amount = fine_amount
44
+ @reduction_amount = reduction_amount
45
+ @discount_amount = discount_amount
46
+ @reconciliation_id = reconciliation_id
47
+ end
48
+
49
+ def self.resource
50
+ {
51
+ resource_name: 'BrcodePreview',
52
+ resource_maker: proc { |json|
53
+ BrcodePreview.new(
54
+ status: json['status'],
55
+ name: json['name'],
56
+ tax_id: json['tax_id'],
57
+ bank_code: json['bank_code'],
58
+ branch_code: json['branch_code'],
59
+ account_number: json['account_number'],
60
+ account_type: json['account_type'],
61
+ allow_change: json['allow_change'],
62
+ amount: json['amount'],
63
+ nominal_amount: json['nominal_amount'],
64
+ interest_amount: json['interest_amount'],
65
+ fine_amount: json['fine_amount'],
66
+ reduction_amount: json['reduction_amount'],
67
+ discount_amount: json['discount_amount'],
68
+ reconciliation_id: json['reconciliation_id']
69
+ )
70
+ }
71
+ }
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ # # PaymentPreview object
9
+ #
10
+ # A PaymentPreview is used to get information from a payment code before confirming the payment.
11
+ # This resource can be used to preview BR Codes and bar codes of boleto, tax and utility payments
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - id [string]: Main identification of the payment. This should be the BR Code for Pix payments and lines or bar codes for payment slips. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062', '00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A'
15
+ # - scheduled [DateTime or string]: intended payment date. Right now, this parameter only has effect on BrcodePreviews. ex: '2020-04-30'
16
+ # - type [string]: Payment type. ex: 'brcode-payment', 'boleto-payment', 'utility-payment' or 'tax-payment'
17
+ # - payment [BrcodePreview, BoletoPreview, UtilityPreview or TaxPreview]: Information preview of the informed payment.
18
+ class PaymentPreview < StarkBank::Utils::Resource
19
+ attr_reader :id, :scheduled, :type, :payment
20
+ def initialize(id: nil, scheduled: nil, type: nil, payment: nil)
21
+ super(id)
22
+ @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
23
+ @type = type
24
+ @payment = payment
25
+ return if type.nil?
26
+
27
+ resource = {
28
+ 'brcode-payment': StarkBank::PaymentPreview::BrcodePreview.resource,
29
+ 'boleto-payment': StarkBank::PaymentPreview::BoletoPreview.resource,
30
+ 'tax-payment': StarkBank::PaymentPreview::TaxPreview.resource,
31
+ 'utility-payment': StarkBank::PaymentPreview::UtilityPreview.resource
32
+ }[type.to_sym]
33
+
34
+ @payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
35
+ end
36
+
37
+ # # Create PaymentPreviews
38
+ #
39
+ # Send a list of PaymentPreviews objects for processing in the Stark Bank API
40
+ #
41
+ # ## Parameters (required):
42
+ # - previews [list of PaymentPreviews objects]: list of PaymentPreviews objects to be created in the API
43
+ #
44
+ # ## Parameters (optional):
45
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
46
+ #
47
+ # ## Return:
48
+ # - list of PaymentPreviews objects with updated attributes
49
+ def self.create(previews, user: nil)
50
+ StarkBank::Utils::Rest.post(entities: previews, user: user, **resource)
51
+ end
52
+
53
+ def self.resource
54
+ {
55
+ resource_name: 'PaymentPreview',
56
+ resource_maker: proc { |json|
57
+ PaymentPreview.new(
58
+ id: json['id'],
59
+ scheduled: json['scheduled'],
60
+ type: json['type'],
61
+ payment: json['payment']
62
+ )
63
+ }
64
+ }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class PaymentPreview
9
+ # # TaxPreview object
10
+ #
11
+ # A TaxPreview is used to get information from a Tax Payment you received before confirming the payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
15
+ # - name [string]: beneficiary full name. ex: "Iron Throne"
16
+ # - description [string]: tax payment description. ex: "ISS Payment - Iron Throne"
17
+ # - line [string]: Number sequence that identifies the payment. ex: "85660000006 6 67940064007 5 41190025511 7 00010601813 8"
18
+ # - bar_code [string]: Bar code number that identifies the payment. ex: "85660000006679400640074119002551100010601813"
19
+ class TaxPreview < StarkBank::Utils::SubResource
20
+ attr_reader :amount, :name, :description, :line, :bar_code
21
+ def initialize(amount:, name:, description:, line:, bar_code:)
22
+ @amount = amount
23
+ @name = name
24
+ @description = description
25
+ @line = line
26
+ @bar_code = bar_code
27
+ end
28
+
29
+ def self.resource
30
+ {
31
+ resource_name: 'TaxPreview',
32
+ resource_maker: proc { |json|
33
+ TaxPreview.new(
34
+ amount: json['amount'],
35
+ name: json['name'],
36
+ description: json['description'],
37
+ line: json['line'],
38
+ bar_code: json['bar_code']
39
+ )
40
+ }
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class PaymentPreview
9
+ # # UtilityPreview object
10
+ #
11
+ # A UtilityPreview is used to get information from a Utility Payment you received before confirming the payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
15
+ # - name [string]: beneficiary full name. ex: "Light Company"
16
+ # - description [string]: utility payment description. ex: "Utility Payment - Light Company"
17
+ # - line [string]: Number sequence that identifies the payment. ex: "82660000002 8 44361143007 7 41190025511 7 00010601813 8"
18
+ # - bar_code [string]: Bar code number that identifies the payment. ex: "82660000002443611430074119002551100010601813"
19
+ class UtilityPreview < StarkBank::Utils::SubResource
20
+ attr_reader :amount, :name, :description, :line, :bar_code
21
+ def initialize(amount:, name:, description:, line:, bar_code:)
22
+ @amount = amount
23
+ @name = name
24
+ @description = description
25
+ @line = line
26
+ @bar_code = bar_code
27
+ end
28
+
29
+ def self.resource
30
+ {
31
+ resource_name: 'UtilityPreview',
32
+ resource_maker: proc { |json|
33
+ UtilityPreview.new(
34
+ amount: json['amount'],
35
+ name: json['name'],
36
+ description: json['description'],
37
+ line: json['line'],
38
+ bar_code: json['bar_code']
39
+ )
40
+ }
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -7,17 +7,17 @@ require_relative('../utils/checks')
7
7
  module StarkBank
8
8
  # # PaymentRequest object
9
9
  # A PaymentRequest is an indirect request to access a specific cash-out service
10
- # (such as Transfer, BoletoPayments, etc.) which goes through the cost center
10
+ # (such as Transfer, BrcodePayments, etc.) which goes through the cost center
11
11
  # approval flow on our website. To emit a PaymentRequest, you must direct it to
12
12
  # a specific cost center by its ID, which can be retrieved on our website at the
13
13
  # cost center page.
14
14
  #
15
15
  # ## Parameters (required):
16
16
  # - center_id [String]: target cost center ID. ex: '5656565656565656'
17
- # - payment [Transfer, BoletoPayment, UtilityPayment, Transaction or dictionary]: payment entity that should be approved and executed.
17
+ # - payment [Transfer, BrcodePayment, BoletoPayment, UtilityPayment, Transaction or dictionary]: payment entity that should be approved and executed.
18
18
  #
19
19
  # ## Parameters (optional):
20
- # - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'boleto-payment'
20
+ # - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'brcode-payment'
21
21
  # - due [Date, DateTime, Time or string]: Payment target date in ISO format. ex: 2020-12-31
22
22
  # - tags [list of strings]: list of strings for tagging
23
23
  #
@@ -53,7 +53,7 @@ module StarkBank
53
53
  #
54
54
  # ## Parameters
55
55
  # - payment_requests [list of PaymentRequest objects]: list of PaymentRequest objects to be created in the API
56
- # - user [Project object]: Project object. Not necessary if StarkBank.User.Default was set before function call
56
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
57
57
  #
58
58
  # ## Return
59
59
  # - list of PaymentRequest objects with updated attributes
@@ -70,21 +70,57 @@ module StarkBank
70
70
  # - center_id [string]: target cost center ID. ex: '5656565656565656'
71
71
  # ## Parameters (optional):
72
72
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
73
- # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
74
- # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
73
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
74
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
75
75
  # - status [string, default '-created']: sort order considered in response. Valid options are '-created' or '-due'.
76
- # - type [string, default nil]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'boleto-payment'
76
+ # - type [string, default nil]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'brcode-payment'
77
77
  # - sort [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
78
78
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
79
79
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
80
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
80
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
81
81
  #
82
82
  # ## Return:
83
83
  # - generator of PaymentRequest objects with updated attributes
84
84
  def self.query(center_id:, limit: nil, after: nil, before: nil, status: nil, type: nil, sort: nil, tags: nil, ids: nil, user: nil)
85
85
  after = StarkBank::Utils::Checks.check_date(after)
86
86
  before = StarkBank::Utils::Checks.check_date(before)
87
- StarkBank::Utils::Rest.get_list(
87
+ StarkBank::Utils::Rest.get_stream(
88
+ center_id: center_id,
89
+ limit: limit,
90
+ after: after,
91
+ before: before,
92
+ status: status,
93
+ type: type,
94
+ sort: sort,
95
+ tags: tags,
96
+ ids: ids,
97
+ user: user,
98
+ **resource
99
+ )
100
+ end
101
+
102
+ # # Retrieve paged PaymentRequests
103
+ #
104
+ # Receive a list of up to 100 PaymentRequest objects previously created in the Stark Bank API and the cursor to the next page.
105
+ # Use this function instead of query if you want to manually page your requests.
106
+ #
107
+ # ## Parameters (optional):
108
+ # - cursor [string, default nil]: cursor returned on the previous page function call
109
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
110
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
111
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
112
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
113
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
114
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
115
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
116
+ #
117
+ # ## Return:
118
+ # - list of PaymentRequest objects with updated attributes and cursor to retrieve the next page of PaymentRequest objects
119
+ def self.page(cursor: nil, center_id:, limit: nil, after: nil, before: nil, status: nil, type: nil, sort: nil, tags: nil, ids: nil, user: nil)
120
+ after = StarkBank::Utils::Checks.check_date(after)
121
+ before = StarkBank::Utils::Checks.check_date(before)
122
+ return StarkBank::Utils::Rest.get_page(
123
+ cursor: cursor,
88
124
  center_id: center_id,
89
125
  limit: limit,
90
126
  after: after,
@@ -102,16 +138,22 @@ module StarkBank
102
138
  def parse_payment(payment:, type:)
103
139
  return [payment, 'transfer'] if payment.is_a?(StarkBank::Transfer)
104
140
  return [payment, 'transaction'] if payment.is_a?(StarkBank::Transaction)
141
+ return [payment, 'brcode-payment'] if payment.is_a?(StarkBank::BrcodePayment)
105
142
  return [payment, 'boleto-payment'] if payment.is_a?(StarkBank::BoletoPayment)
106
143
  return [payment, 'utility-payment'] if payment.is_a?(StarkBank::UtilityPayment)
144
+ return [payment, 'tax-payment'] if payment.is_a?(StarkBank::TaxPayment)
145
+ return [payment, 'darf-payment'] if payment.is_a?(StarkBank::DarfPayment)
107
146
 
108
- raise(Exception('Payment must either be a Transfer, a Transaction, a BoletoPayment, a UtilityPayment or a hash.')) unless payment.is_a?(Hash)
147
+ raise(Exception('Payment must either be a Transfer, a Transaction, a BrcodePayment, BoletoPayment, a UtilityPayment, a TaxPayment, a DarfPayment or a hash.')) unless payment.is_a?(Hash)
109
148
 
110
149
  resource = {
111
150
  'transfer': StarkBank::Transfer.resource,
112
151
  'transaction': StarkBank::Transaction.resource,
152
+ 'brcode-payment': StarkBank::BrcodePayment.resource,
113
153
  'boleto-payment': StarkBank::BoletoPayment.resource,
114
- 'utility-payment': StarkBank::UtilityPayment.resource
154
+ 'utility-payment': StarkBank::UtilityPayment.resource,
155
+ 'tax-payment': StarkBank::TaxPayment.resource,
156
+ 'darf-payment': StarkBank::DarfPayment.resource
115
157
  }[type.to_sym]
116
158
 
117
159
  payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?