starkinfra 0.5.2 → 0.7.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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcode_preview/brcode_preview.rb +25 -4
  3. data/lib/brcode_preview/subscription.rb +102 -0
  4. data/lib/business_account_request/business_account_request.rb +276 -0
  5. data/lib/business_account_request/log.rb +124 -0
  6. data/lib/business_attachment/business_attachment.rb +189 -0
  7. data/lib/{individual_document → business_attachment}/log.rb +35 -32
  8. data/lib/business_identity/business_identity.rb +228 -0
  9. data/lib/business_identity/log.rb +127 -0
  10. data/lib/credit_holmes/credit_holmes.rb +2 -1
  11. data/lib/credit_holmes/log.rb +125 -0
  12. data/lib/credit_note/credit_note.rb +51 -8
  13. data/lib/credit_note/rule.rb +55 -0
  14. data/lib/credit_note/transfer.rb +1 -1
  15. data/lib/credit_preview/credit_note_preview.rb +10 -2
  16. data/lib/credit_preview/credit_preview.rb +2 -1
  17. data/lib/credit_signer/credit_signer.rb +27 -2
  18. data/lib/dynamic_brcode/dynamic_brcode.rb +5 -2
  19. data/lib/event/event.rb +10 -2
  20. data/lib/individual_account_attachment/individual_account_attachment.rb +178 -0
  21. data/lib/individual_account_attachment/log.rb +124 -0
  22. data/lib/individual_account_request/individual_account_request.rb +271 -0
  23. data/lib/individual_account_request/log.rb +124 -0
  24. data/lib/individual_identity/individual_identity.rb +4 -7
  25. data/lib/issuing_balance/issuing_balance.rb +8 -2
  26. data/lib/issuing_billing_invoice/issuing_billing_invoice.rb +155 -0
  27. data/lib/issuing_billing_transaction/issuing_billing_transaction.rb +142 -0
  28. data/lib/issuing_card/issuing_card.rb +10 -6
  29. data/lib/issuing_design/issuing_design.rb +9 -0
  30. data/lib/issuing_embossing_request/issuing_embossing_request.rb +3 -2
  31. data/lib/issuing_holder/issuing_holder.rb +6 -5
  32. data/lib/issuing_product/issuing_product.rb +6 -3
  33. data/lib/issuing_purchase/issuing_purchase.rb +41 -8
  34. data/lib/issuing_restock/issuing_restock.rb +3 -2
  35. data/lib/issuing_rule/issuing_rule.rb +45 -3
  36. data/lib/issuing_stock/issuing_stock.rb +5 -2
  37. data/lib/issuing_stock_rule/issuing_stock_rule.rb +214 -0
  38. data/lib/issuing_token/issuing_token.rb +309 -0
  39. data/lib/issuing_token/log.rb +127 -0
  40. data/lib/issuing_token_activation/issuing_token_activation.rb +62 -0
  41. data/lib/issuing_token_design/issuing_token_design.rb +118 -0
  42. data/lib/issuing_token_request/issuing_token_request.rb +63 -0
  43. data/lib/issuing_withdrawal/issuing_withdrawal.rb +2 -2
  44. data/lib/ledger/ledger.rb +175 -0
  45. data/lib/ledger/log.rb +122 -0
  46. data/lib/ledger/rule.rb +55 -0
  47. data/lib/ledger_transaction/ledger_transaction.rb +179 -0
  48. data/lib/merchant_category/merchant_category.rb +6 -3
  49. data/lib/pix_balance/pix_balance.rb +1 -1
  50. data/lib/pix_chargeback/pix_chargeback.rb +34 -7
  51. data/lib/pix_claim/pix_claim.rb +14 -6
  52. data/lib/pix_director/pix_director.rb +1 -1
  53. data/lib/pix_dispute/log.rb +127 -0
  54. data/lib/pix_dispute/pix_dispute.rb +210 -0
  55. data/lib/pix_dispute/transaction.rb +91 -0
  56. data/lib/pix_fraud/log.rb +128 -0
  57. data/lib/pix_fraud/pix_fraud.rb +180 -0
  58. data/lib/pix_infraction/pix_infraction.rb +37 -7
  59. data/lib/pix_internal_transaction_report/log.rb +129 -0
  60. data/lib/pix_internal_transaction_report/pix_internal_transaction_report.rb +200 -0
  61. data/lib/pix_key/pix_key.rb +1 -1
  62. data/lib/pix_key_holmes/log.rb +129 -0
  63. data/lib/{individual_document/individual_document.rb → pix_key_holmes/pix_key_holmes.rb} +48 -56
  64. data/lib/pix_pull_request/log.rb +127 -0
  65. data/lib/pix_pull_request/pix_pull_request.rb +268 -0
  66. data/lib/pix_pull_subscription/log.rb +127 -0
  67. data/lib/pix_pull_subscription/pix_pull_subscription.rb +307 -0
  68. data/lib/pix_request/pix_request.rb +19 -6
  69. data/lib/pix_reversal/pix_reversal.rb +14 -8
  70. data/lib/pix_statement/pix_statement.rb +11 -5
  71. data/lib/pix_user/pix_user.rb +52 -0
  72. data/lib/pix_user/statistics.rb +64 -0
  73. data/lib/starkinfra.rb +45 -4
  74. data/lib/static_brcode/static_brcode.rb +8 -4
  75. data/lib/utils/bacen_id.rb +27 -0
  76. data/lib/utils/end_to_end_id.rb +20 -0
  77. data/lib/utils/pix_subscription_bacen_id.rb +21 -0
  78. data/lib/utils/return_id.rb +21 -0
  79. data/lib/webhook/webhook.rb +3 -3
  80. metadata +48 -11
@@ -9,8 +9,8 @@ module StarkInfra
9
9
  # The IssuingWithdrawal objects created in your Workspace return cash from your Issuing balance to your Banking balance.
10
10
  #
11
11
  # ## Parameters (required):
12
- # - amount [integer]: IssuingWithdrawal value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34)
13
- # - external_id [string] IssuingWithdrawal external ID. ex: '12345'
12
+ # - amount [integer]: IssuingWithdrawal value in cents. ex: 1234 (= R$ 12.34)
13
+ # - external_id [string]: unique identifier for this withdrawal, used to prevent duplicates on retries. ex: '12345'
14
14
  # - description [string]: IssuingWithdrawal description. ex: 'sending money back'
15
15
  #
16
16
  # ## Parameters (optional):
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+
6
+ module StarkInfra
7
+ # # Ledger object
8
+ #
9
+ # Ledgers are used to track the balance of a given amount by inserting LedgerTransactions to them.
10
+ # They can represent a bank account, a digital wallet, an inventory product, etc.
11
+ #
12
+ # ## Parameters (required):
13
+ # - external_id [string]: string that must be unique among all your Ledgers. ex: 'my-internal-id-123456'
14
+ #
15
+ # ## Parameters (optional):
16
+ # - rules [list of Ledger::Rule objects, default []]: list of Rule objects linked to the Ledger. Rules are used to limit the balance of the Ledger. ex: [Ledger::Rule.new(key: 'minimumBalance', value: 0)]
17
+ # - tags [list of strings, default []]: list of strings for reference when searching for Ledgers. ex: ['account/123', 'savings']
18
+ # - metadata [dictionary, default {}]: dictionary object used to store additional information about the Ledger object. ex: { 'accountId': '123', 'accountType': 'savings' }
19
+ #
20
+ # ## Attributes (return-only):
21
+ # - id [string]: unique id returned when the Ledger is created. ex: '5656565656565656'
22
+ # - created [DateTime]: creation datetime for the Ledger. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
23
+ # - updated [DateTime]: latest update datetime for the Ledger. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
24
+ class Ledger < StarkCore::Utils::Resource
25
+ attr_reader :external_id, :rules, :tags, :metadata, :id, :created, :updated
26
+ def initialize(external_id:, id: nil, rules: nil, tags: nil, metadata: nil, created: nil, updated: nil)
27
+ super(id)
28
+ @external_id = external_id
29
+ @rules = StarkInfra::Ledger::Rule.parse_rules(rules)
30
+ @tags = tags
31
+ @metadata = metadata
32
+ @created = StarkCore::Utils::Checks.check_datetime(created)
33
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
34
+ end
35
+
36
+ # # Create Ledgers
37
+ #
38
+ # Send a list of Ledger objects for creation at the Stark Infra API
39
+ #
40
+ # ## Parameters (required):
41
+ # - ledgers [list of Ledger objects]: list of Ledger objects to be created in the Stark Infra API. You can send up to 100 Ledger objects in a single request.
42
+ #
43
+ # ## Parameters (optional):
44
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
45
+ #
46
+ # ## Return:
47
+ # - list of Ledger objects with updated attributes
48
+ def self.create(ledgers, user: nil)
49
+ StarkInfra::Utils::Rest.post(entities: ledgers, user: user, **resource)
50
+ end
51
+
52
+ # # Retrieve a specific Ledger
53
+ #
54
+ # Receive a single Ledger object previously created in the Stark Infra API by its id
55
+ #
56
+ # ## Parameters (required):
57
+ # - id [string]: object unique id. ex: '5656565656565656'
58
+ #
59
+ # ## Parameters (optional):
60
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
61
+ #
62
+ # ## Return:
63
+ # - Ledger object with updated attributes
64
+ def self.get(id, user: nil)
65
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
66
+ end
67
+
68
+ # # Retrieve Ledgers
69
+ #
70
+ # Receive a generator of Ledger objects previously created in the Stark Infra API
71
+ #
72
+ # ## Parameters (optional):
73
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
74
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
75
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
76
+ # - ids [list of strings, default nil]: list of Ledger ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
77
+ # - external_ids [list of strings, default nil]: list of Ledger external ids to filter retrieved objects. ex: ['my-internal-id-123456', 'my-internal-id-654321']
78
+ # - tags [list of strings, default nil]: list of tags to filter retrieved objects. ex: ['account/123', 'savings']
79
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
80
+ #
81
+ # ## Return:
82
+ # - generator of Ledger objects with updated attributes
83
+ def self.query(limit: nil, after: nil, before: nil, ids: nil, external_ids: nil, tags: nil, user: nil)
84
+ after = StarkCore::Utils::Checks.check_date(after)
85
+ before = StarkCore::Utils::Checks.check_date(before)
86
+ StarkInfra::Utils::Rest.get_stream(
87
+ limit: limit,
88
+ after: after,
89
+ before: before,
90
+ ids: ids,
91
+ external_ids: external_ids,
92
+ tags: tags,
93
+ user: user,
94
+ **resource
95
+ )
96
+ end
97
+
98
+ # # Retrieve paged Ledgers
99
+ #
100
+ # Receive a list of up to 100 Ledger objects previously created in the Stark Infra API and the cursor to the next page.
101
+ # Use this function instead of query if you want to manually page your requests.
102
+ #
103
+ # ## Parameters (optional):
104
+ # - cursor [string, default nil]: cursor returned on the previous page function call
105
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
106
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
107
+ # - before [Date 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 Ledger ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
109
+ # - external_ids [list of strings, default nil]: list of Ledger external ids to filter retrieved objects. ex: ['my-internal-id-123456', 'my-internal-id-654321']
110
+ # - tags [list of strings, default nil]: list of tags to filter retrieved objects. ex: ['account/123', 'savings']
111
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
112
+ #
113
+ # ## Return:
114
+ # - list of Ledger objects with updated attributes
115
+ # - cursor to retrieve the next page of Ledger objects
116
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, ids: nil, external_ids: nil, tags: nil, user: nil)
117
+ after = StarkCore::Utils::Checks.check_date(after)
118
+ before = StarkCore::Utils::Checks.check_date(before)
119
+ StarkInfra::Utils::Rest.get_page(
120
+ cursor: cursor,
121
+ limit: limit,
122
+ after: after,
123
+ before: before,
124
+ ids: ids,
125
+ external_ids: external_ids,
126
+ tags: tags,
127
+ user: user,
128
+ **resource
129
+ )
130
+ end
131
+
132
+ # # Update Ledger
133
+ #
134
+ # Update a Ledger by passing id.
135
+ #
136
+ # ## Parameters (required):
137
+ # - id [string]: Ledger id. ex: '5656565656565656'
138
+ #
139
+ # ## Parameters (optional):
140
+ # - rules [list of Ledger::Rule objects, default nil]: list of Rule objects linked to the Ledger. Rules are used to limit the balance of the Ledger. ex: [Ledger::Rule.new(key: 'minimumBalance', value: 0)]
141
+ # - tags [list of strings, default nil]: list of strings for reference when searching for Ledgers. ex: ['account/123', 'savings']
142
+ # - metadata [dictionary, default nil]: dictionary object used to store additional information about the Ledger object. ex: { 'accountId': '123', 'accountType': 'savings' }
143
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
144
+ #
145
+ # ## Return:
146
+ # - target Ledger object with updated attributes
147
+ def self.update(id, rules: nil, tags: nil, metadata: nil, user: nil)
148
+ StarkInfra::Utils::Rest.patch_id(
149
+ id: id,
150
+ rules: rules,
151
+ tags: tags,
152
+ metadata: metadata,
153
+ user: user,
154
+ **resource
155
+ )
156
+ end
157
+
158
+ def self.resource
159
+ {
160
+ resource_name: 'Ledger',
161
+ resource_maker: proc { |json|
162
+ Ledger.new(
163
+ id: json['id'],
164
+ external_id: json['external_id'],
165
+ rules: json['rules'],
166
+ tags: json['tags'],
167
+ metadata: json['metadata'],
168
+ created: json['created'],
169
+ updated: json['updated']
170
+ )
171
+ }
172
+ }
173
+ end
174
+ end
175
+ end
data/lib/ledger/log.rb ADDED
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+ require_relative('ledger')
6
+
7
+ module StarkInfra
8
+ class Ledger
9
+ # # Ledger::Log object
10
+ #
11
+ # Every time a Ledger entity is updated, a corresponding Ledger::Log
12
+ # is generated for the entity. This log is never generated by the
13
+ # user, but it can be retrieved to check additional information
14
+ # on the Ledger.
15
+ #
16
+ # ## Attributes (return-only):
17
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
+ # - type [string]: type of the Ledger event which triggered the log creation. ex: 'created', 'updated'
20
+ # - ledger [Ledger]: Ledger entity to which the log refers to.
21
+ class Log < StarkCore::Utils::Resource
22
+ attr_reader :id, :created, :type, :ledger
23
+ def initialize(id:, created:, type:, ledger:)
24
+ super(id)
25
+ @type = type
26
+ @ledger = ledger
27
+ @created = StarkCore::Utils::Checks.check_datetime(created)
28
+ end
29
+
30
+ # # Retrieve a specific Ledger::Log
31
+ #
32
+ # Receive a single Ledger::Log object previously created by the Stark Infra API by its id
33
+ #
34
+ # ## Parameters (required):
35
+ # - id [string]: object unique id. ex: '5656565656565656'
36
+ #
37
+ # ## Parameters (optional):
38
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
39
+ #
40
+ # ## Return:
41
+ # - Ledger::Log object with updated attributes
42
+ def self.get(id, user: nil)
43
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
44
+ end
45
+
46
+ # # Retrieve Ledger::Logs
47
+ #
48
+ # Receive a generator of Ledger::Log objects previously created in the Stark Infra API
49
+ #
50
+ # ## Parameters (optional):
51
+ # - ids [list of strings, default nil]: list of LedgerLog ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
52
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
53
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
54
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
55
+ # - ledger_id [string, default nil]: filter logs by Ledger id. ex: '5656565656565656'
56
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
57
+ #
58
+ # ## Return:
59
+ # - generator of Ledger::Log objects with updated attributes
60
+ def self.query(ids: nil, limit: nil, after: nil, before: nil, ledger_id: nil, user: nil)
61
+ after = StarkCore::Utils::Checks.check_date(after)
62
+ before = StarkCore::Utils::Checks.check_date(before)
63
+ StarkInfra::Utils::Rest.get_stream(
64
+ ids: ids,
65
+ limit: limit,
66
+ after: after,
67
+ before: before,
68
+ ledger_id: ledger_id,
69
+ user: user,
70
+ **resource
71
+ )
72
+ end
73
+
74
+ # # Retrieve paged Ledger::Logs
75
+ #
76
+ # Receive a list of up to 100 Ledger::Log objects previously created in the Stark Infra API and the cursor to the next page.
77
+ # Use this function instead of query if you want to manually page your requests.
78
+ #
79
+ # ## Parameters (optional):
80
+ # - ids [list of strings, default nil]: list of LedgerLog ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
81
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
82
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
83
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
84
+ # - ledger_id [string, default nil]: filter logs by Ledger id. ex: '5656565656565656'
85
+ # - cursor [string, default nil]: cursor returned on the previous page function call
86
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
87
+ #
88
+ # ## Return:
89
+ # - list of Ledger::Log objects with updated attributes
90
+ # - cursor to retrieve the next page of Ledger::Log objects
91
+ def self.page(ids: nil, limit: nil, after: nil, before: nil, ledger_id: nil, cursor: nil, user: nil)
92
+ after = StarkCore::Utils::Checks.check_date(after)
93
+ before = StarkCore::Utils::Checks.check_date(before)
94
+ StarkInfra::Utils::Rest.get_page(
95
+ cursor: cursor,
96
+ ids: ids,
97
+ limit: limit,
98
+ after: after,
99
+ before: before,
100
+ ledger_id: ledger_id,
101
+ user: user,
102
+ **resource
103
+ )
104
+ end
105
+
106
+ def self.resource
107
+ request_maker = StarkInfra::Ledger.resource[:resource_maker]
108
+ {
109
+ resource_name: 'LedgerLog',
110
+ resource_maker: proc { |json|
111
+ Log.new(
112
+ id: json['id'],
113
+ created: json['created'],
114
+ type: json['type'],
115
+ ledger: StarkCore::Utils::API.from_api_json(request_maker, json['ledger'])
116
+ )
117
+ }
118
+ }
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,55 @@
1
+ require_relative('../utils/rest')
2
+
3
+ module StarkInfra
4
+ class Ledger
5
+ # # Ledger::Rule object
6
+ #
7
+ # The Ledger::Rule object modifies the behavior of Ledger objects when passed as an argument upon their creation or update.
8
+ #
9
+ # ## Parameters (required):
10
+ # - key [string]: Rule to be customized, describes what Ledger behavior will be altered. ex: 'minimumBalance', 'maximumBalance'
11
+ # - value [integer]: Value of the rule. ex: 1000
12
+ class Rule < StarkCore::Utils::SubResource
13
+ attr_reader :key, :value
14
+ def initialize(key:, value:)
15
+ @key = key
16
+ @value = value
17
+ end
18
+
19
+ # # Parse Ledger::Rules
20
+ #
21
+ # Converts a list of hashes (or Rule objects) received from the API into a list of Ledger::Rule objects.
22
+ #
23
+ # ## Parameters (required):
24
+ # - rules [list of hashes or Ledger::Rule objects]: list to be parsed.
25
+ #
26
+ # ## Return:
27
+ # - list of parsed Ledger::Rule objects
28
+ def self.parse_rules(rules)
29
+ resource_maker = StarkInfra::Ledger::Rule.resource[:resource_maker]
30
+ return rules if rules.nil?
31
+
32
+ parsed_rules = []
33
+ rules.each do |rule|
34
+ unless rule.is_a? Rule
35
+ rule = StarkCore::Utils::API.from_api_json(resource_maker, rule)
36
+ end
37
+ parsed_rules << rule
38
+ end
39
+ return parsed_rules
40
+ end
41
+
42
+ def self.resource
43
+ {
44
+ resource_name: 'Rule',
45
+ resource_maker: proc { |json|
46
+ Rule.new(
47
+ key: json['key'],
48
+ value: json['value']
49
+ )
50
+ }
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+ require_relative('../ledger/rule')
6
+
7
+ module StarkInfra
8
+ # # LedgerTransaction object
9
+ #
10
+ # LedgerTransactions are used to track the balance of a given amount by inserting LedgerTransactions to them.
11
+ # They can represent a bank account, a digital wallet, an inventory product, etc.
12
+ #
13
+ # ## Parameters (required):
14
+ # - amount [integer]: amount of the transaction. ex: 11234
15
+ # - ledger_id [string]: id of the Ledger containing the transaction. ex: '5656565656565656'
16
+ # - external_id [string]: string that must be unique among all your LedgerTransactions in a single Ledger. ex: 'my-internal-id-123456'
17
+ # - source [string]: source of the LedgerTransaction. ex: 'bank-transfer/123'
18
+ #
19
+ # ## Parameters (optional):
20
+ # - fee [integer]: fee applied to the LedgerTransaction. ex: 100
21
+ # - rules [list of Ledger::Rule objects, default []]: list of Rule objects linked to the LedgerTransaction. Rules are used to overwrite the Ledger's rules for this transaction. ex: [Ledger::Rule.new(key: 'minimumBalance', value: 0)]
22
+ # - metadata [dictionary, default {}]: dictionary object used to store additional information about the LedgerTransaction object. ex: { 'orderId': '123', 'orderType': 'purchase' }
23
+ # - tags [list of strings, default []]: list of strings for reference when searching for LedgerTransactions. ex: ['transfer/123', 'savings']
24
+ # - created [DateTime or string, default nil]: datetime to backdate the transaction, used to import existing transaction history. Cannot be in the future; when creating multiple transactions in one request, their created values must be in chronological order. Defaults to the current datetime when omitted.
25
+ #
26
+ # ## Attributes (return-only):
27
+ # - id [string]: unique id returned when the LedgerTransaction is created. ex: '5656565656565656'
28
+ # - balance [integer]: Ledger's balance after the transaction. ex: 11234
29
+ class LedgerTransaction < StarkCore::Utils::Resource
30
+ attr_reader :amount, :ledger_id, :external_id, :source, :id, :balance, :fee, :rules, :metadata, :tags, :created
31
+ def initialize(
32
+ amount:, ledger_id:, external_id:, source:, id: nil, balance: nil, fee: nil, rules: nil,
33
+ metadata: nil, tags: nil, created: nil
34
+ )
35
+ super(id)
36
+ @amount = amount
37
+ @ledger_id = ledger_id
38
+ @external_id = external_id
39
+ @source = source
40
+ @balance = balance
41
+ @fee = fee
42
+ @rules = StarkInfra::Ledger::Rule.parse_rules(rules)
43
+ @metadata = metadata
44
+ @tags = tags
45
+ @created = StarkCore::Utils::Checks.check_datetime(created)
46
+ end
47
+
48
+ # # Create LedgerTransactions
49
+ #
50
+ # Send a list of LedgerTransaction objects for creation at the Stark Infra API
51
+ #
52
+ # ## Parameters (required):
53
+ # - transactions [list of LedgerTransaction objects]: list of LedgerTransaction objects to be created in the Stark Infra API. You can send up to 500 objects in a single request, targeting different ledgers if needed; each is applied to its Ledger in the order sent, and the resulting balance is returned for each one.
54
+ #
55
+ # ## Parameters (optional):
56
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
57
+ #
58
+ # ## Return:
59
+ # - list of LedgerTransaction objects with updated attributes
60
+ def self.create(transactions, user: nil)
61
+ StarkInfra::Utils::Rest.post(entities: transactions, user: user, **resource)
62
+ end
63
+
64
+ # # Retrieve a specific LedgerTransaction
65
+ #
66
+ # Receive a single LedgerTransaction object previously created in the Stark Infra API by its id
67
+ #
68
+ # ## Parameters (required):
69
+ # - id [string]: object unique id. ex: '5656565656565656'
70
+ #
71
+ # ## Parameters (optional):
72
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
73
+ #
74
+ # ## Return:
75
+ # - LedgerTransaction object with updated attributes
76
+ def self.get(id, user: nil)
77
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
78
+ end
79
+
80
+ # # Retrieve LedgerTransactions
81
+ #
82
+ # Receive a generator of LedgerTransaction objects previously created in the Stark Infra API
83
+ #
84
+ # ## Parameters (conditionally-required):
85
+ # - ledger_id [string, default nil]: id of the Ledger containing the transaction. Either ledger_id or ids must be provided. If both are sent, the query will be filtered by both. ex: '5656565656565656'
86
+ # - ids [list of strings, default nil]: list of LedgerTransaction ids to filter retrieved objects. Either ledger_id or ids must be provided. If both are sent, the query will be filtered by both. ex: ['5656565656565656', '4545454545454545']
87
+ #
88
+ # ## Parameters (optional):
89
+ # - flow [string, default nil]: direction of the transaction. ex: 'in' or 'out'
90
+ # - tags [list of strings, default nil]: list of tags to filter retrieved objects. ex: ['transfer/123', 'savings']
91
+ # - external_ids [list of strings, default nil]: list of LedgerTransaction external ids to filter retrieved objects. ex: ['my-internal-id-123456', 'my-internal-id-654321']
92
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
93
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
94
+ # - limit [integer, default 100, maximum 1000]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
95
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
96
+ #
97
+ # ## Return:
98
+ # - generator of LedgerTransaction objects with updated attributes
99
+ def self.query(ledger_id: nil, flow: nil, tags: nil, external_ids: nil, after: nil, before: nil,
100
+ ids: nil, limit: nil, user: nil)
101
+ after = StarkCore::Utils::Checks.check_date(after)
102
+ before = StarkCore::Utils::Checks.check_date(before)
103
+ StarkInfra::Utils::Rest.get_stream(
104
+ ledger_id: ledger_id,
105
+ flow: flow,
106
+ tags: tags,
107
+ external_ids: external_ids,
108
+ after: after,
109
+ before: before,
110
+ ids: ids,
111
+ limit: limit,
112
+ user: user,
113
+ **resource
114
+ )
115
+ end
116
+
117
+ # # Retrieve paged LedgerTransactions
118
+ #
119
+ # Receive a list of LedgerTransaction objects previously created in the Stark Infra API and the cursor to the next page.
120
+ # Use this function instead of query if you want to manually page your requests.
121
+ #
122
+ # ## Parameters (conditionally-required):
123
+ # - ledger_id [string, default nil]: id of the Ledger containing the transaction. Either ledger_id or ids must be provided. If both are sent, the query will be filtered by both. ex: '5656565656565656'
124
+ # - ids [list of strings, default nil]: list of LedgerTransaction ids to filter retrieved objects. Either ledger_id or ids must be provided. If both are sent, the query will be filtered by both. ex: ['5656565656565656', '4545454545454545']
125
+ #
126
+ # ## Parameters (optional):
127
+ # - flow [string, default nil]: direction of the transaction. ex: 'in' or 'out'
128
+ # - tags [list of strings, default nil]: list of tags to filter retrieved objects. ex: ['transfer/123', 'savings']
129
+ # - external_ids [list of strings, default nil]: list of LedgerTransaction external ids to filter retrieved objects. ex: ['my-internal-id-123456', 'my-internal-id-654321']
130
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
131
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
132
+ # - limit [integer, default 100, maximum 1000]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
133
+ # - cursor [string, default nil]: cursor returned on the previous page function call
134
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
135
+ #
136
+ # ## Return:
137
+ # - list of LedgerTransaction objects with updated attributes
138
+ # - cursor to retrieve the next page of LedgerTransaction objects
139
+ def self.page(ledger_id: nil, flow: nil, tags: nil, external_ids: nil, after: nil, before: nil,
140
+ ids: nil, limit: nil, cursor: nil, user: nil)
141
+ after = StarkCore::Utils::Checks.check_date(after)
142
+ before = StarkCore::Utils::Checks.check_date(before)
143
+ StarkInfra::Utils::Rest.get_page(
144
+ ledger_id: ledger_id,
145
+ flow: flow,
146
+ tags: tags,
147
+ external_ids: external_ids,
148
+ after: after,
149
+ before: before,
150
+ ids: ids,
151
+ limit: limit,
152
+ cursor: cursor,
153
+ user: user,
154
+ **resource
155
+ )
156
+ end
157
+
158
+ def self.resource
159
+ {
160
+ resource_name: 'LedgerTransaction',
161
+ resource_maker: proc { |json|
162
+ LedgerTransaction.new(
163
+ id: json['id'],
164
+ amount: json['amount'],
165
+ ledger_id: json['ledger_id'],
166
+ external_id: json['external_id'],
167
+ source: json['source'],
168
+ balance: json['balance'],
169
+ fee: json['fee'],
170
+ rules: json['rules'],
171
+ metadata: json['metadata'],
172
+ tags: json['tags'],
173
+ created: json['created']
174
+ )
175
+ }
176
+ }
177
+ end
178
+ end
179
+ end
@@ -19,13 +19,15 @@ module StarkInfra
19
19
  # Attributes (return-only):
20
20
  # - name [string]: category's name. ex: 'Veterinary services', 'Fast food restaurants'
21
21
  # - number [string]: category's number. ex: '742', '5814'
22
+ # - group [string]: category's group. ex: 'pets', 'food'
22
23
  class MerchantCategory < StarkCore::Utils::SubResource
23
- attr_reader :code, :type, :name, :number
24
- def initialize(code:, type:, name: nil, number: nil)
24
+ attr_reader :code, :type, :name, :number, :group
25
+ def initialize(code:, type:, name: nil, number: nil, group: nil)
25
26
  @code = code
26
27
  @type = type
27
28
  @name = name
28
29
  @number = number
30
+ @group = group
29
31
  end
30
32
 
31
33
  # # Retrieve MerchantCategories
@@ -54,7 +56,8 @@ module StarkInfra
54
56
  code: json['code'],
55
57
  type: json['type'],
56
58
  name: json['name'],
57
- number: json['number']
59
+ number: json['number'],
60
+ group: json['group']
58
61
  )
59
62
  }
60
63
  }
@@ -12,7 +12,7 @@ module StarkInfra
12
12
  # can be retrieved to see the available information.
13
13
  #
14
14
  # ## Attributes (return-only):
15
- # - id [string]: unique id returned when Balance is created. ex: '5656565656565656'
15
+ # - id [string]: identifier of the balance. Holds the participant bank code for direct participants, or the workspace id for indirect participants.
16
16
  # - amount [integer]: current balance amount of the workspace in cents. ex: 200 (= R$ 2.00)
17
17
  # - currency [string]: currency of the current workspace. Expect others to be added eventually. ex: 'BRL'
18
18
  # - updated [DateTime]: latest update datetime for the balance. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)