starkbank 2.4.0 → 2.5.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/balance/balance.rb +1 -1
  3. data/lib/boleto/boleto.rb +49 -10
  4. data/lib/boleto/log.rb +35 -4
  5. data/lib/boleto_holmes/boleto_holmes.rb +39 -4
  6. data/lib/boleto_holmes/log.rb +35 -4
  7. data/lib/boleto_payment/boleto_payment.rb +38 -5
  8. data/lib/boleto_payment/log.rb +35 -4
  9. data/lib/brcode_payment/brcode_payment.rb +52 -13
  10. data/lib/brcode_payment/log.rb +35 -4
  11. data/lib/brcode_preview/brcode_preview.rb +2 -2
  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 +45 -7
  15. data/lib/deposit/log.rb +35 -4
  16. data/lib/dict_key/dict_key.rb +44 -8
  17. data/lib/error.rb +13 -5
  18. data/lib/event/attempt.rb +125 -0
  19. data/lib/event/event.rb +40 -4
  20. data/lib/institution/institution.rb +67 -0
  21. data/lib/invoice/invoice.rb +66 -9
  22. data/lib/invoice/log.rb +51 -4
  23. data/lib/invoice/payment.rb +57 -0
  24. data/lib/payment_request/payment_request.rb +47 -7
  25. data/lib/starkbank.rb +7 -0
  26. data/lib/tax_payment/log.rb +125 -0
  27. data/lib/tax_payment/tax_payment.rb +203 -0
  28. data/lib/transaction/transaction.rb +37 -4
  29. data/lib/transfer/log.rb +35 -4
  30. data/lib/transfer/transfer.rb +47 -8
  31. data/lib/user/organization.rb +1 -1
  32. data/lib/user/project.rb +1 -1
  33. data/lib/utility_payment/log.rb +35 -4
  34. data/lib/utility_payment/utility_payment.rb +38 -5
  35. data/lib/utils/api.rb +1 -0
  36. data/lib/utils/request.rb +1 -1
  37. data/lib/utils/resource.rb +2 -21
  38. data/lib/utils/rest.rb +28 -12
  39. data/lib/utils/sub_resource.rb +28 -0
  40. data/lib/utils/url.rb +3 -1
  41. data/lib/webhook/webhook.rb +23 -2
  42. data/lib/workspace/workspace.rb +57 -8
  43. metadata +15 -7
@@ -26,6 +26,8 @@ module StarkBank
26
26
  # - tags [list of strings, default nil]: list of strings for tagging
27
27
  #
28
28
  # ## Attributes (return-only):
29
+ # - pdf [string, default nil]: public Invoice PDF URL. ex: 'https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8'
30
+ # - link [string, default nil]: public Invoice webpage URL. ex: 'https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8'
29
31
  # - id [string, default nil]: unique id returned when Invoice is created. ex: '5656565656565656'
30
32
  # - nominal_amount [integer, default nil]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
31
33
  # - fine_amount [integer, default nil]: Invoice fine value calculated over nominal_amount. ex: 20000
@@ -37,11 +39,11 @@ module StarkBank
37
39
  # - created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
38
40
  # - updated [DateTime, default nil]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
39
41
  class Invoice < StarkBank::Utils::Resource
40
- attr_reader :amount, :tax_id, :name, :due, :expiration, :fine, :interest, :discounts, :tags, :descriptions, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :id, :brcode, :fee, :status, :created, :updated
42
+ attr_reader :amount, :tax_id, :name, :due, :expiration, :fine, :interest, :discounts, :tags, :pdf, :link, :descriptions, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :id, :brcode, :fee, :status, :transaction_ids, :created, :updated
41
43
  def initialize(
42
44
  amount:, tax_id:, name:, due: nil, expiration: nil, fine: nil, interest: nil, discounts: nil,
43
- tags: nil, descriptions: nil, nominal_amount: nil, fine_amount: nil, interest_amount: nil,
44
- discount_amount: nil, id: nil, brcode: nil, fee: nil, status: nil, created: nil, updated: nil
45
+ tags: nil, pdf: nil, link: nil, descriptions: nil, nominal_amount: nil, fine_amount: nil, interest_amount: nil,
46
+ discount_amount: nil, id: nil, brcode: nil, fee: nil, status: nil, transaction_ids: nil, created: nil, updated: nil
45
47
  )
46
48
  super(id)
47
49
  @amount = amount
@@ -53,6 +55,8 @@ module StarkBank
53
55
  @interest = interest
54
56
  @discounts = discounts
55
57
  @tags = tags
58
+ @pdf = pdf
59
+ @link = link
56
60
  @descriptions = descriptions
57
61
  @nominal_amount = nominal_amount
58
62
  @fine_amount = fine_amount
@@ -61,6 +65,7 @@ module StarkBank
61
65
  @brcode = brcode
62
66
  @fee = fee
63
67
  @status = status
68
+ @transaction_ids = transaction_ids
64
69
  @updated = StarkBank::Utils::Checks.check_datetime(updated)
65
70
  @created = StarkBank::Utils::Checks.check_datetime(created)
66
71
  end
@@ -110,7 +115,7 @@ module StarkBank
110
115
  # ## Return:
111
116
  # - Invoice pdf file
112
117
  def self.pdf(id, user: nil)
113
- StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
118
+ StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
114
119
  end
115
120
 
116
121
  # # Retrieve a specific Invoice QR Code file
@@ -126,7 +131,7 @@ module StarkBank
126
131
  # ## Return:
127
132
  # - Invoice QR Code png blob
128
133
  def self.qrcode(id, user: nil)
129
- StarkBank::Utils::Rest.get_qrcode(id: id, user: user, **resource)
134
+ StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'qrcode', **resource)
130
135
  end
131
136
 
132
137
  # # Retrieve Invoices
@@ -135,19 +140,52 @@ module StarkBank
135
140
  #
136
141
  # ## Parameters (optional):
137
142
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
138
- # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
139
- # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
143
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
144
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
140
145
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
141
146
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
142
147
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
143
- # - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
148
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
144
149
  #
145
150
  # ## Return:
146
151
  # - generator of Invoice objects with updated attributes
147
152
  def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
148
153
  after = StarkBank::Utils::Checks.check_date(after)
149
154
  before = StarkBank::Utils::Checks.check_date(before)
150
- StarkBank::Utils::Rest.get_list(
155
+ StarkBank::Utils::Rest.get_stream(
156
+ limit: limit,
157
+ after: after,
158
+ before: before,
159
+ status: status,
160
+ tags: tags,
161
+ ids: ids,
162
+ user: user,
163
+ **resource
164
+ )
165
+ end
166
+
167
+ # # Retrieve paged Invoices
168
+ #
169
+ # Receive a list of up to 100 Invoice objects previously created in the Stark Bank API and the cursor to the next page.
170
+ # Use this function instead of query if you want to manually page your requests.
171
+ #
172
+ # ## Parameters (optional):
173
+ # - cursor [string, default nil]: cursor returned on the previous page function call
174
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
175
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
176
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
177
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
178
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
179
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
180
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
181
+ #
182
+ # ## Return:
183
+ # - list of Invoice objects with updated attributes and cursor to retrieve the next page of Invoice objects
184
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
185
+ after = StarkBank::Utils::Checks.check_date(after)
186
+ before = StarkBank::Utils::Checks.check_date(before)
187
+ return StarkBank::Utils::Rest.get_page(
188
+ cursor: cursor,
151
189
  limit: limit,
152
190
  after: after,
153
191
  before: before,
@@ -178,6 +216,22 @@ module StarkBank
178
216
  StarkBank::Utils::Rest.patch_id(id: id, status: status, amount: amount, due: due, expiration: expiration, user: user, **resource)
179
217
  end
180
218
 
219
+ # # Retrieve a specific Invoice payment information
220
+ #
221
+ # Receive the Invoice::Payment sub-resource associated with a paid Invoice.
222
+ #
223
+ # ## Parameters (required):
224
+ # - id [string]: Invoice unique id. ex: '5656565656565656'
225
+ #
226
+ # ## Parameters (optional):
227
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
228
+ #
229
+ # ## Return:
230
+ # - Invoice::Payment sub-resource
231
+ def self.payment(id, user: nil)
232
+ StarkBank::Utils::Rest.get_sub_resource(id: id, user: user, **resource, **StarkBank::Invoice::Payment.resource)
233
+ end
234
+
181
235
  def self.resource
182
236
  {
183
237
  resource_name: 'Invoice',
@@ -193,6 +247,8 @@ module StarkBank
193
247
  interest: json['interest'],
194
248
  discounts: json['discounts'],
195
249
  tags: json['tags'],
250
+ pdf: json['pdf'],
251
+ link: json['link'],
196
252
  descriptions: json['descriptions'],
197
253
  nominal_amount: json['nominal_amount'],
198
254
  fine_amount: json['fine_amount'],
@@ -201,6 +257,7 @@ module StarkBank
201
257
  brcode: json['brcode'],
202
258
  fee: json['fee'],
203
259
  status: json['status'],
260
+ transaction_ids: json['transaction_ids'],
204
261
  updated: json['updated'],
205
262
  created: json['created'],
206
263
  )
data/lib/invoice/log.rb CHANGED
@@ -52,18 +52,18 @@ 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
  # - invoice_ids [list of strings, default nil]: list of Invoice ids to filter logs. ex: ['5656565656565656', '4545454545454545']
59
- # - user [Organization/Project object]: Organization or 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, invoice_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
67
  limit: limit,
68
68
  after: after,
69
69
  before: before,
@@ -74,6 +74,53 @@ module StarkBank
74
74
  )
75
75
  end
76
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 'registered'
88
+ # - boleto_ids [list of strings, default nil]: list of Boleto 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, invoice_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
+ invoice_ids: invoice_ids,
103
+ user: user,
104
+ **resource
105
+ )
106
+ end
107
+
108
+ # # Retrieve a specific Invoice::Log pdf file
109
+ #
110
+ # Receive a single Invoice::Log pdf file generated in the Stark Bank API by passing its id.
111
+ #
112
+ # ## Parameters (required):
113
+ # - id [string]: object unique id. ex: '5656565656565656'
114
+ #
115
+ # ## Parameters (optional):
116
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
117
+ #
118
+ # ## Return:
119
+ # - Invoice::Log pdf file
120
+ def self.pdf(id, user: nil)
121
+ StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
122
+ end
123
+
77
124
  def self.resource
78
125
  invoice_maker = StarkBank::Invoice.resource[:resource_maker]
79
126
  {
@@ -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
@@ -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 [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user 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
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 [Organization/Project object]: Organization or 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,
@@ -105,15 +141,19 @@ module StarkBank
105
141
  return [payment, 'brcode-payment'] if payment.is_a?(StarkBank::BrcodePayment)
106
142
  return [payment, 'boleto-payment'] if payment.is_a?(StarkBank::BoletoPayment)
107
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)
108
146
 
109
- raise(Exception('Payment must either be a Transfer, a Transaction, a BrcodePayment, 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)
110
148
 
111
149
  resource = {
112
150
  'transfer': StarkBank::Transfer.resource,
113
151
  'transaction': StarkBank::Transaction.resource,
114
152
  'brcode-payment': StarkBank::BrcodePayment.resource,
115
153
  'boleto-payment': StarkBank::BoletoPayment.resource,
116
- 'utility-payment': StarkBank::UtilityPayment.resource
154
+ 'utility-payment': StarkBank::UtilityPayment.resource,
155
+ 'tax-payment': StarkBank::TaxPayment.resource,
156
+ 'darf-payment': StarkBank::DarfPayment.resource
117
157
  }[type.to_sym]
118
158
 
119
159
  payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
data/lib/starkbank.rb CHANGED
@@ -8,6 +8,7 @@ require_relative('balance/balance')
8
8
  require_relative('transaction/transaction')
9
9
  require_relative('invoice/invoice')
10
10
  require_relative('invoice/log')
11
+ require_relative('invoice/payment')
11
12
  require_relative('dict_key/dict_key')
12
13
  require_relative('deposit/deposit')
13
14
  require_relative('deposit/log')
@@ -24,9 +25,15 @@ require_relative('boleto_payment/boleto_payment')
24
25
  require_relative('boleto_payment/log')
25
26
  require_relative('utility_payment/utility_payment')
26
27
  require_relative('utility_payment/log')
28
+ require_relative('tax_payment/tax_payment')
29
+ require_relative('tax_payment/log')
30
+ require_relative('darf_payment/darf_payment')
31
+ require_relative('darf_payment/log')
27
32
  require_relative('webhook/webhook')
28
33
  require_relative('event/event')
34
+ require_relative('event/attempt')
29
35
  require_relative('payment_request/payment_request')
36
+ require_relative('institution/institution')
30
37
 
31
38
  # SDK to facilitate Ruby integrations with Stark Bank
32
39
  module StarkBank
@@ -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('tax_payment')
7
+
8
+ module StarkBank
9
+ class TaxPayment
10
+ # # TaxPayment::Log object
11
+ #
12
+ # Every time a TaxPayment entity is updated, a corresponding TaxPayment::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 TaxPayment.
16
+ #
17
+ # ## Attributes:
18
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
19
+ # - payment [TaxPayment]: TaxPayment entity to which the log refers to.
20
+ # - errors [list of strings]: list of errors linked to this TaxPayment event
21
+ # - type [string]: type of the TaxPayment event which triggered the log creation. ex: 'canceled' or 'paid'
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
+ tax_payment_maker = StarkBank::TaxPayment.resource[:resource_maker]
110
+ {
111
+ resource_name: 'TaxPaymentLog',
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(tax_payment_maker, json['payment'])
119
+ )
120
+ }
121
+ }
122
+ end
123
+ end
124
+ end
125
+ end