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,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('darf_payment')
7
+
8
+ module StarkBank
9
+ class DarfPayment
10
+ # # DarfPayment::Log object
11
+ #
12
+ # Every time a DarfPayment entity is updated, a corresponding DarfPayment::Log
13
+ # is generated for the entity. This log is never generated by the
14
+ # user, but it can be retrieved to check additional information
15
+ # on the DarfPayment.
16
+ #
17
+ # ## Attributes:
18
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
19
+ # - payment [DarfPayment]: DarfPayment entity to which the log refers to.
20
+ # - errors [list of strings]: list of errors linked to this DarfPayment event
21
+ # - type [string]: type of the DarfPayment event which triggered the log creation. ex: 'processing' or 'success'
22
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
23
+ class Log < StarkBank::Utils::Resource
24
+ attr_reader :id, :created, :type, :errors, :payment
25
+ def initialize(id:, created:, type:, errors:, payment:)
26
+ super(id)
27
+ @type = type
28
+ @errors = errors
29
+ @payment = payment
30
+ @created = StarkBank::Utils::Checks.check_datetime(created)
31
+ end
32
+
33
+ # # Retrieve a specific Log
34
+ #
35
+ # Receive a single Log object previously created by the Stark Bank API by passing its id
36
+ #
37
+ # ## Parameters (required):
38
+ # - id [string]: object unique id. ex: '5656565656565656'
39
+ #
40
+ # ## Parameters (optional):
41
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
42
+ #
43
+ # ## Return:
44
+ # - Log object with updated attributes
45
+ def self.get(id, user: nil)
46
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
47
+ end
48
+
49
+ # # Retrieve Logs
50
+ #
51
+ # Receive a generator of Log objects previously created in the Stark Bank API
52
+ #
53
+ # ## Parameters (optional):
54
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
+ # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
57
+ # - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
58
+ # - payment_ids [list of strings, default nil]: list of TaxPayment ids to filter logs. ex: ['5656565656565656', '4545454545454545']
59
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if Starkbank.user was set before function call
60
+ #
61
+ # ## Return:
62
+ # - list of Log objects with updated attributes
63
+ def self.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
64
+ after = StarkBank::Utils::Checks.check_date(after)
65
+ before = StarkBank::Utils::Checks.check_date(before)
66
+ StarkBank::Utils::Rest.get_stream(
67
+ limit: limit,
68
+ after: after,
69
+ before: before,
70
+ types: types,
71
+ payment_ids: payment_ids,
72
+ user: user,
73
+ **resource
74
+ )
75
+ end
76
+
77
+ # # Retrieve paged Logs
78
+ #
79
+ # Receive a list of up to 100 Log objects previously created in the Stark Bank API and the cursor to the next page.
80
+ # Use this function instead of query if you want to manually page your requests.
81
+ #
82
+ # ## Parameters (optional):
83
+ # - cursor [string, default nil]: cursor returned on the previous page function call
84
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
85
+ # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
86
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
87
+ # - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
88
+ # - payment_ids [list of strings, default nil]: list of TaxPayment ids to filter logs. ex: ['5656565656565656', '4545454545454545']
89
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if Starkbank.user was set before function call
90
+ #
91
+ # ## Return:
92
+ # - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
93
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
94
+ after = StarkBank::Utils::Checks.check_date(after)
95
+ before = StarkBank::Utils::Checks.check_date(before)
96
+ return StarkBank::Utils::Rest.get_page(
97
+ cursor: cursor,
98
+ limit: limit,
99
+ after: after,
100
+ before: before,
101
+ types: types,
102
+ payment_ids: payment_ids,
103
+ user: user,
104
+ **resource
105
+ )
106
+ end
107
+
108
+ def self.resource
109
+ darf_payment_maker = StarkBank::DarfPayment.resource[:resource_maker]
110
+ {
111
+ resource_name: 'DarfPaymentLog',
112
+ resource_maker: proc { |json|
113
+ Log.new(
114
+ id: json['id'],
115
+ created: json['created'],
116
+ type: json['type'],
117
+ errors: json['errors'],
118
+ payment: StarkBank::Utils::API.from_api_json(darf_payment_maker, json['payment'])
119
+ )
120
+ }
121
+ }
122
+ end
123
+ end
124
+ end
125
+ end
@@ -16,6 +16,7 @@ module StarkBank
16
16
  # - bank_code [string]: payer bank code in Brazil. ex: '20018183' or '341'
17
17
  # - branch_code [string]: payer bank account branch. ex: '1357-9's
18
18
  # - account_number [string]: payer bank account number. ex: '876543-2'
19
+ # - account_type [string]: payer bank account type. ex: 'checking'
19
20
  # - amount [integer]: Deposit value in cents. ex: 1234 (= R$ 12.34)
20
21
  # - type [string]: Type of settlement that originated the deposit. ex: 'pix' or 'ted'
21
22
  # - status [string]: current Deposit status. ex: 'created'
@@ -25,10 +26,10 @@ module StarkBank
25
26
  # - created [datetime.datetime]: creation datetime for the Deposit. ex: datetime.datetime(2020, 12, 10, 10, 30, 0, 0)
26
27
  # - updated [datetime.datetime]: latest update datetime for the Deposit. ex: datetime.datetime(2020, 12, 10, 10, 30, 0, 0)
27
28
  class Deposit < StarkBank::Utils::Resource
28
- attr_reader :id, :name, :tax_id, :bank_code, :branch_code, :account_number, :amount, :type, :status, :tags, :fee, :transaction_ids, :created, :updated
29
+ attr_reader :id, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :amount, :type, :status, :tags, :fee, :transaction_ids, :created, :updated
29
30
  def initialize(
30
- id:, name:, tax_id:, bank_code:, branch_code:, account_number:, amount:, type:, status:, tags:, fee:,
31
- transaction_ids:, created:, updated:
31
+ id:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, amount:, type:,
32
+ status:, tags:, fee:, transaction_ids:, created:, updated:
32
33
  )
33
34
  super(id)
34
35
  @name = name
@@ -36,6 +37,7 @@ module StarkBank
36
37
  @bank_code = bank_code
37
38
  @branch_code = branch_code
38
39
  @account_number = account_number
40
+ @account_type = account_type
39
41
  @amount = amount
40
42
  @type = type
41
43
  @status = status
@@ -54,7 +56,7 @@ module StarkBank
54
56
  # - id [string]: object unique id. ex: '5656565656565656'
55
57
  #
56
58
  # ## Parameters (optional):
57
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
59
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
58
60
  #
59
61
  # ## Return:
60
62
  # - Deposit object with updated attributes
@@ -68,20 +70,55 @@ module StarkBank
68
70
  #
69
71
  # ## Parameters (optional):
70
72
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
71
- # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
72
- # - 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)
73
75
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
74
76
  # - sort [string, default '-created']: sort order considered in response. Valid options are 'created' or '-created'.
75
77
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
76
78
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
77
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
79
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
78
80
  #
79
81
  # ## Return:
80
82
  # - generator of Deposit objects with updated attributes
81
83
  def self.query(limit: nil, after: nil, before: nil, status: nil, sort: nil, tags: nil, ids: nil, user: nil)
82
84
  after = StarkBank::Utils::Checks.check_date(after)
83
85
  before = StarkBank::Utils::Checks.check_date(before)
84
- StarkBank::Utils::Rest.get_list(
86
+ StarkBank::Utils::Rest.get_stream(
87
+ limit: limit,
88
+ after: after,
89
+ before: before,
90
+ status: status,
91
+ sort: sort,
92
+ tags: tags,
93
+ ids: ids,
94
+ user: user,
95
+ **resource
96
+ )
97
+ end
98
+
99
+ # # Retrieve paged Deposits
100
+ #
101
+ # Receive a list of up to 100 Deposit objects previously created in the Stark Bank API and the cursor to the next page.
102
+ # Use this function instead of query if you want to manually page your requests.
103
+ #
104
+ # ## Parameters (optional):
105
+ # - cursor [string, default nil]: cursor returned on the previous page function call
106
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
107
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
108
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
109
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
110
+ # - sort [string, default '-created']: sort order considered in response. Valid options are 'created' or '-created'.
111
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
112
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
113
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
114
+ #
115
+ # ## Return:
116
+ # - list of Deposit objects with updated attributes and cursor to retrieve the next page of Deposit objects
117
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, sort: nil, tags: nil, ids: nil, user: nil)
118
+ after = StarkBank::Utils::Checks.check_date(after)
119
+ before = StarkBank::Utils::Checks.check_date(before)
120
+ return StarkBank::Utils::Rest.get_page(
121
+ cursor: cursor,
85
122
  limit: limit,
86
123
  after: after,
87
124
  before: before,
@@ -105,6 +142,7 @@ module StarkBank
105
142
  bank_code: json['bank_code'],
106
143
  branch_code: json['branch_code'],
107
144
  account_number: json['account_number'],
145
+ account_type: json['account_type'],
108
146
  amount: json['amount'],
109
147
  type: json['type'],
110
148
  status: json['status'],
data/lib/deposit/log.rb CHANGED
@@ -38,7 +38,7 @@ module StarkBank
38
38
  # - id [string]: object unique id. ex: '5656565656565656'
39
39
  #
40
40
  # ## Parameters (optional):
41
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
41
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
42
42
  #
43
43
  # ## Return:
44
44
  # - Log object with updated attributes
@@ -52,18 +52,49 @@ module StarkBank
52
52
  #
53
53
  # ## Parameters (optional):
54
54
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
- # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
- # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
55
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
57
57
  # - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
58
58
  # - deposit_ids [list of strings, default nil]: list of Deposit ids to filter logs. ex: ['5656565656565656', '4545454545454545']
59
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
59
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
60
60
  #
61
61
  # ## Return:
62
62
  # - list of Log objects with updated attributes
63
63
  def self.query(limit: nil, after: nil, before: nil, types: nil, deposit_ids: nil, user: nil)
64
64
  after = StarkBank::Utils::Checks.check_date(after)
65
65
  before = StarkBank::Utils::Checks.check_date(before)
66
- StarkBank::Utils::Rest.get_list(
66
+ StarkBank::Utils::Rest.get_stream(
67
+ limit: limit,
68
+ after: after,
69
+ before: before,
70
+ types: types,
71
+ deposit_ids: deposit_ids,
72
+ user: user,
73
+ **resource
74
+ )
75
+ end
76
+
77
+ # # Retrieve paged Logs
78
+ #
79
+ # Receive a list of up to 100 Log objects previously created in the Stark Bank API and the cursor to the next page.
80
+ # Use this function instead of query if you want to manually page your requests.
81
+ #
82
+ # ## Parameters (optional):
83
+ # - cursor [string, default nil]: cursor returned on the previous page function call
84
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
85
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
86
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
87
+ # - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
88
+ # - deposit_ids [list of strings, default nil]: list of Deposit ids to filter logs. ex: ['5656565656565656', '4545454545454545']
89
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
90
+ #
91
+ # ## Return:
92
+ # - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
93
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, deposit_ids: nil, user: nil)
94
+ after = StarkBank::Utils::Checks.check_date(after)
95
+ before = StarkBank::Utils::Checks.check_date(before)
96
+ return StarkBank::Utils::Rest.get_page(
97
+ cursor: cursor,
67
98
  limit: limit,
68
99
  after: after,
69
100
  before: before,
@@ -17,25 +17,27 @@ module StarkBank
17
17
  # - name [string, default nil]: account owner full name. ex: 'Tony Stark'
18
18
  # - tax_id [string, default nil]: key owner tax ID (CNPJ or masked CPF). ex: '***.345.678-**' or '20.018.183/0001-80'
19
19
  # - owner_type [string, default nil]: DICT key owner type. ex 'naturalPerson' or 'legalPerson'
20
+ # - bank_name [string, default nil]: bank name associated with the DICT key. ex: 'Stark Bank'
20
21
  # - ispb [string, default nil]: bank ISPB associated with the DICT key. ex: '20018183'
21
22
  # - branch_code [string, default nil]: bank account branch code associated with the DICT key. ex: '9585'
22
23
  # - account_number [string, default nil]: bank account number associated with the DICT key. ex: '9828282578010513'
23
- # - account_type [string, default nil]: bank account type associated with the DICT key. ex: 'checking', 'saving' e 'salary'
24
+ # - account_type [string, default nil]: bank account type associated with the DICT key. ex: 'checking', 'saving', 'salary' or 'payment'
24
25
  # - status [string, default nil]: current DICT key status. ex: 'created', 'registered', 'canceled' or 'failed'
25
26
  # - account_created [DateTime or string, default nil]: creation datetime of the bank account associated with the DICT key. ex: '2020-11-05T14:55:08.812665+00:00'
26
27
  # - owned [DateTime or string, default nil]: datetime since when the current owner hold this DICT key. ex : '2020-11-05T14:55:08.812665+00:00'
27
28
  # - created [DateTime or string, default nil]: creation datetime for the DICT key. ex: '2020-03-10 10:30:00.000'
28
29
  class DictKey < StarkBank::Utils::Resource
29
- attr_reader :id, :type, :name, :tax_id, :owner_type, :ispb, :branch_code, :account_number, :account_type, :status, :account_created, :owned, :created
30
+ attr_reader :id, :type, :name, :tax_id, :owner_type, :bank_name, :ispb, :branch_code, :account_number, :account_type, :status, :account_created, :owned, :created
30
31
  def initialize(
31
- id:, type:, name:, tax_id:, owner_type:, ispb:, branch_code:, account_number:, account_type:,
32
- status:, account_created:, owned:, created:
32
+ id:, type:, name:, tax_id:, owner_type:, bank_name:, ispb:, branch_code:, account_number:,
33
+ account_type:, status:, account_created:, owned:, created:
33
34
  )
34
35
  super(id)
35
36
  @type = type
36
37
  @name = name
37
38
  @tax_id = tax_id
38
39
  @owner_type = owner_type
40
+ @bank_name = bank_name
39
41
  @ispb = ispb
40
42
  @branch_code = branch_code
41
43
  @account_number = account_number
@@ -54,7 +56,7 @@ module StarkBank
54
56
  # - id [string]: DictKey object unique id and PIX key itself. ex: 'tony@starkbank.com', '722.461.430-04', '20.018.183/0001-80', '+5511988887777', 'b6295ee1-f054-47d1-9e90-ee57b74f60d9'
55
57
  #
56
58
  # ## Parameters (optional):
57
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
59
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
58
60
  #
59
61
  # ## Return:
60
62
  # - DictKey object with updated attributes
@@ -69,18 +71,51 @@ module StarkBank
69
71
  # ## Parameters (optional):
70
72
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
71
73
  # - type [string, default nil]: DictKey type. ex: 'cpf', 'cnpj', 'phone', 'email' or 'evp'
72
- # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
73
- # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
74
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
75
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
74
76
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
75
77
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'canceled', 'registered'
76
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
78
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
77
79
  #
78
80
  # ## Return:
79
81
  # - generator of DitcKey objects with updated attributes
80
82
  def self.query(limit: nil, type: nil, after: nil, before: nil, ids: nil, status: nil, user: nil)
81
83
  after = StarkBank::Utils::Checks.check_date(after)
82
84
  before = StarkBank::Utils::Checks.check_date(before)
83
- StarkBank::Utils::Rest.get_list(
85
+ StarkBank::Utils::Rest.get_stream(
86
+ limit: limit,
87
+ type: type,
88
+ after: after,
89
+ before: before,
90
+ ids: ids,
91
+ status: status,
92
+ user: user,
93
+ **resource
94
+ )
95
+ end
96
+
97
+ # # Retrieve paged DictKeys
98
+ #
99
+ # Receive a list of up to 100 DictKey objects previously created in the Stark Bank API and the cursor to the next page.
100
+ # Use this function instead of query if you want to manually page your requests.
101
+ #
102
+ # ## Parameters (optional):
103
+ # - cursor [string, default nil]: cursor returned on the previous page function call
104
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
105
+ # - type [string, default nil]: DictKey type. ex: 'cpf', 'cnpj', 'phone', 'email' or 'evp'
106
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
107
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
108
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
109
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'canceled', 'registered'
110
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
111
+ #
112
+ # ## Return:
113
+ # - list of DictKey objects with updated attributes and cursor to retrieve the next page of DictKey objects
114
+ def self.page(cursor: nil, limit: nil, type: nil, after: nil, before: nil, ids: nil, status: nil, user: nil)
115
+ after = StarkBank::Utils::Checks.check_date(after)
116
+ before = StarkBank::Utils::Checks.check_date(before)
117
+ return StarkBank::Utils::Rest.get_page(
118
+ cursor: cursor,
84
119
  limit: limit,
85
120
  type: type,
86
121
  after: after,
@@ -102,6 +137,7 @@ module StarkBank
102
137
  name: json['name'],
103
138
  tax_id: json['tax_id'],
104
139
  owner_type: json['owner_type'],
140
+ bank_name: json['bank_name'],
105
141
  ispb: json['ispb'],
106
142
  branch_code: json['branch_code'],
107
143
  account_number: json['account_number'],
data/lib/error.rb CHANGED
@@ -4,7 +4,15 @@ require('json')
4
4
 
5
5
  module StarkBank
6
6
  module Error
7
- class Error < StandardError
7
+ class StarkBankError < StandardError
8
+ attr_reader :message
9
+ def initialize(message)
10
+ @message = message
11
+ super(message)
12
+ end
13
+ end
14
+
15
+ class Error < StarkBankError
8
16
  attr_reader :code, :message
9
17
  def initialize(code, message)
10
18
  @code = code
@@ -13,7 +21,7 @@ module StarkBank
13
21
  end
14
22
  end
15
23
 
16
- class InputErrors < StandardError
24
+ class InputErrors < StarkBankError
17
25
  attr_reader :errors
18
26
  def initialize(content)
19
27
  errors = []
@@ -26,19 +34,19 @@ module StarkBank
26
34
  end
27
35
  end
28
36
 
29
- class InternalServerError < StandardError
37
+ class InternalServerError < StarkBankError
30
38
  def initialize(message = 'Houston, we have a problem.')
31
39
  super(message)
32
40
  end
33
41
  end
34
42
 
35
- class UnknownError < StandardError
43
+ class UnknownError < StarkBankError
36
44
  def initialize(message)
37
45
  super("Unknown exception encountered: #{message}")
38
46
  end
39
47
  end
40
48
 
41
- class InvalidSignatureError < StandardError
49
+ class InvalidSignatureError < StarkBankError
42
50
  end
43
51
  end
44
52
  end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('event')
7
+
8
+ module StarkBank
9
+ class Event
10
+ # # Event::Attempt object
11
+ #
12
+ # When an Event delivery fails, an event attempt will be registered.
13
+ # It carries information meant to help you debug event reception issues.
14
+ #
15
+ # ## Attributes:
16
+ # - id [string]: unique id that identifies the delivery attempt. ex: "5656565656565656"
17
+ # - code [string]: delivery error code. ex: badHttpStatus, badConnection, timeout
18
+ # - message [string]: delivery error full description. ex: "HTTP POST request returned status 404"
19
+ # - event_id [string]: ID of the Event whose delivery failed. ex: "4848484848484848"
20
+ # - webhook_id [string]: ID of the Webhook that triggered this event. ex: "5656565656565656"
21
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
+ class Attempt < StarkBank::Utils::Resource
23
+ attr_reader :id, :code, :message, :event_id, :webhook_id, :created
24
+ def initialize(id:, code:, message:, event_id:, webhook_id:, created:)
25
+ super(id)
26
+ @code = code
27
+ @message = message
28
+ @event_id = event_id
29
+ @webhook_id = webhook_id
30
+ @created = StarkBank::Utils::Checks.check_datetime(created)
31
+ end
32
+
33
+ # # Retrieve a specific Event::Attempt
34
+ #
35
+ # Receive a single Event::Attempt object previously created by the Stark Bank API by its id
36
+ #
37
+ # ## Parameters (required):
38
+ # - id [string]: object unique id. ex: '5656565656565656'
39
+ #
40
+ # ## Parameters (optional):
41
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
42
+ #
43
+ # ## Return:
44
+ # - Event::Attempt object with updated attributes
45
+ def self.get(id, user: nil)
46
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
47
+ end
48
+
49
+ # # Retrieve Event::Attempts
50
+ #
51
+ # Receive a generator of Event::Attempt objects previously created in the Stark Bank API
52
+ #
53
+ # ## Parameters (optional):
54
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
57
+ # - event_ids [list of strings, default None]: list of Event ids to filter attempts. ex: ["5656565656565656", "4545454545454545"]
58
+ # - webhook_ids [list of strings, default None]: list of Webhook ids to filter attempts. ex: ["5656565656565656", "4545454545454545"]
59
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
60
+ #
61
+ # ## Return:
62
+ # - generator of Event::Attempt objects with updated attributes
63
+ def self.query(limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
64
+ after = StarkBank::Utils::Checks.check_date(after)
65
+ before = StarkBank::Utils::Checks.check_date(before)
66
+ StarkBank::Utils::Rest.get_stream(
67
+ limit: limit,
68
+ after: after,
69
+ before: before,
70
+ event_ids: event_ids,
71
+ webhook_ids: webhook_ids,
72
+ user: user,
73
+ **resource
74
+ )
75
+ end
76
+
77
+ # # Retrieve paged Attempts
78
+ #
79
+ # Receive a list of up to 100 Attempt objects previously created in the Stark Bank API and the cursor to the next page.
80
+ # Use this function instead of query if you want to manually page your requests.
81
+ #
82
+ # ## Parameters (optional):
83
+ # - cursor [string, default nil]: cursor returned on the previous page function call
84
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
85
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
86
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
87
+ # - event_ids [list of strings, default None]: list of Event ids to filter attempts. ex: ["5656565656565656", "4545454545454545"]
88
+ # - webhook_ids [list of strings, default None]: list of Webhook ids to filter attempts. ex: ["5656565656565656", "4545454545454545"]
89
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
90
+ #
91
+ # ## Return:
92
+ # - list of Attempt objects with updated attributes and cursor to retrieve the next page of Attempt objects
93
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
94
+ after = StarkBank::Utils::Checks.check_date(after)
95
+ before = StarkBank::Utils::Checks.check_date(before)
96
+ return StarkBank::Utils::Rest.get_page(
97
+ cursor: cursor,
98
+ limit: limit,
99
+ after: after,
100
+ before: before,
101
+ event_ids: event_ids,
102
+ webhook_ids: webhook_ids,
103
+ user: user,
104
+ **resource
105
+ )
106
+ end
107
+
108
+ def self.resource
109
+ {
110
+ resource_name: 'EventAttempt',
111
+ resource_maker: proc { |json|
112
+ Attempt.new(
113
+ id: json['id'],
114
+ code: json['code'],
115
+ message: json['message'],
116
+ event_id: json['event_id'],
117
+ webhook_id: json['webhook_id'],
118
+ created: json['created']
119
+ )
120
+ }
121
+ }
122
+ end
123
+ end
124
+ end
125
+ end