starkinfra 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/creditnote/creditnote.rb +583 -0
  3. data/lib/creditnote/log.rb +126 -0
  4. data/lib/event/attempt.rb +126 -0
  5. data/lib/event/event.rb +125 -7
  6. data/lib/issuingauthorization/issuingauthorization.rb +141 -0
  7. data/lib/issuingbalance/issuingbalance.rb +55 -0
  8. data/lib/issuingbin/issuingbin.rb +89 -0
  9. data/lib/issuingcard/issuingcard.rb +261 -0
  10. data/lib/issuingcard/log.rb +123 -0
  11. data/lib/issuingholder/issuingholder.rb +206 -0
  12. data/lib/issuingholder/log.rb +123 -0
  13. data/lib/issuinginvoice/issuinginvoice.rb +152 -0
  14. data/lib/issuinginvoice/log.rb +120 -0
  15. data/lib/issuingpurchase/issuingpurchase.rb +209 -0
  16. data/lib/issuingpurchase/log.rb +131 -0
  17. data/lib/issuingrule/issuingrule.rb +79 -0
  18. data/lib/issuingtransaction/issuingtransaction.rb +136 -0
  19. data/lib/issuingwithdrawal/issuingwithdrawal.rb +153 -0
  20. data/lib/pixbalance/pixbalance.rb +15 -15
  21. data/lib/pixchargeback/log.rb +129 -0
  22. data/lib/pixchargeback/pixchargeback.rb +225 -0
  23. data/lib/pixclaim/log.rb +135 -0
  24. data/lib/pixclaim/pixclaim.rb +226 -0
  25. data/lib/pixdirector/pixdirector.rb +76 -0
  26. data/lib/pixdomain/certificate.rb +30 -0
  27. data/lib/pixdomain/pixdomain.rb +58 -0
  28. data/lib/pixinfraction/log.rb +129 -0
  29. data/lib/pixinfraction/pixinfraction.rb +212 -0
  30. data/lib/pixkey/log.rb +128 -0
  31. data/lib/pixkey/pixkey.rb +240 -0
  32. data/lib/pixrequest/log.rb +16 -16
  33. data/lib/pixrequest/pixrequest.rb +66 -67
  34. data/lib/pixreversal/log.rb +13 -12
  35. data/lib/pixreversal/pixreversal.rb +74 -72
  36. data/lib/pixstatement/pixstatement.rb +24 -25
  37. data/lib/starkinfra.rb +32 -3
  38. data/lib/user/organization.rb +54 -0
  39. data/lib/user/project.rb +37 -0
  40. data/lib/user/user.rb +20 -0
  41. data/lib/utils/api.rb +10 -2
  42. data/lib/utils/bacenid.rb +19 -0
  43. data/lib/utils/checks.rb +2 -3
  44. data/lib/utils/endtoendid.rb +11 -0
  45. data/lib/utils/parse.rb +13 -13
  46. data/lib/utils/request.rb +2 -2
  47. data/lib/utils/rest.rb +6 -5
  48. data/lib/utils/returnid.rb +11 -0
  49. data/lib/webhook/webhook.rb +124 -0
  50. metadata +45 -24
@@ -14,42 +14,45 @@ module StarkInfra
14
14
  #
15
15
  # ## Parameters (required):
16
16
  # - amount [integer]: amount in cents to be transferred. ex: 11234 (= R$ 112.34)
17
- # - external_id [string]: url safe string that must be unique among all your PixRequests. Duplicated external ids will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: "my-internal-id-123456"
18
- # - sender_name [string]: sender full name. ex: "Anthony Edward Stark"
19
- # - sender_tax_id [string]: sender tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80"
20
- # - sender_branch_code [string]: sender bank account branch code. Use '-' in case there is a verifier digit. ex: "1357-9"
21
- # - sender_account_number [string]: sender bank account number. Use '-' before the verifier digit. ex: "876543-2"
22
- # - sender_account_type [string, default "checking"]: sender bank account type. ex: "checking", "savings", "salary" or "payment"
23
- # - receiver_name [string]: receiver full name. ex: "Anthony Edward Stark"
24
- # - receiver_tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80"
25
- # - receiver_bank_code [string]: code of the receiver bank institution in Brazil. ex: "20018183" or "341"
26
- # - receiver_account_number [string]: receiver bank account number. Use '-' before the verifier digit. ex: "876543-2"
27
- # - receiver_branch_code [string]: receiver bank account branch code. Use '-' in case there is a verifier digit. ex: "1357-9"
28
- # - receiver_account_type [string]: receiver bank account type. ex: "checking", "savings", "salary" or "payment"
29
- # - end_to_end_id [string]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq"
17
+ # - external_id [string]: url safe string that must be unique among all your PixRequests. Duplicated external ids will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: 'my-internal-id-123456'
18
+ # - sender_name [string]: sender full name. ex: 'Anthony Edward Stark'
19
+ # - sender_tax_id [string]: sender tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
20
+ # - sender_branch_code [string]: sender bank account branch code. Use '-' in case there is a verifier digit. ex: '1357-9'
21
+ # - sender_account_number [string]: sender bank account number. Use '-' before the verifier digit. ex: '876543-2'
22
+ # - sender_account_type [string, default 'checking']: sender bank account type. ex: 'checking', 'savings', 'salary' or 'payment'
23
+ # - receiver_name [string]: receiver full name. ex: 'Anthony Edward Stark'
24
+ # - receiver_tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
25
+ # - receiver_bank_code [string]: code of the receiver bank institution in Brazil. ex: '20018183' or '341'
26
+ # - receiver_account_number [string]: receiver bank account number. Use '-' before the verifier digit. ex: '876543-2'
27
+ # - receiver_branch_code [string]: receiver bank account branch code. Use '-' in case there is a verifier digit. ex: '1357-9'
28
+ # - receiver_account_type [string]: receiver bank account type. ex: 'checking', 'savings', 'salary' or 'payment'
29
+ # - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
30
30
  #
31
31
  # ## Parameters (optional):
32
32
  # - receiver_key_id [string, default nil]: Receiver's dict key. Example: tax id (CPF/CNPJ).
33
- # - description [string, default nil]: optional description to override default description to be shown in the bank statement. ex: "Payment for service #1234"
34
- # - reconciliation_id [string, default nil]: Reconciliation ID linked to this payment. ex: "b77f5236-7ab9-4487-9f95-66ee6eaf1781"
35
- # - initiator_tax_id [string, default nil]: Payment initiator's tax id (CPF/CNPJ). ex: "01234567890" or "20.018.183/0001-80"
33
+ # - description [string, default nil]: optional description to override default description to be shown in the bank statement. ex: 'Payment for service #1234'
34
+ # - reconciliation_id [string, default nil]: Reconciliation ID linked to this payment. ex: 'b77f5236-7ab9-4487-9f95-66ee6eaf1781'
35
+ # - initiator_tax_id [string, default nil]: Payment initiator's tax id (CPF/CNPJ). ex: '01234567890' or '20.018.183/0001-80'
36
36
  # - cash_amount [integer, default nil]: Amount to be withdrawal from the cashier in cents. ex: 1000 (= R$ 10.00)
37
- # - cashier_bank_code [string, default nil]: Cashier's bank code. ex: "00000000"
37
+ # - cashier_bank_code [string, default nil]: Cashier's bank code. ex: '00000000'
38
38
  # - cashier_type [string, default nil]: Cashier's type. ex: [merchant, other, participant]
39
- # - tags [list of strings, default nil]: list of strings for reference when searching for PixRequests. ex: ["employees", "monthly"]
40
- # - method [string]: execution method of creation of the PIX. ex: "manual", "payerQrcode", "dynamicQrcode".
39
+ # - tags [list of strings, default nil]: list of strings for reference when searching for PixRequests. ex: ['employees', 'monthly']
40
+ # - method [string, default nil]: execution method of creation of the PIX. ex: 'manual', 'payerQrcode', 'dynamicQrcode'.
41
41
  #
42
42
  # ## Attributes (return-only):
43
- # - id [string, default nil]: unique id returned when the PixRequest is created. ex: "5656565656565656"
44
- # - fee [integer, default nil]: fee charged when PixRequest is paid. ex: 200 (= R$ 2.00)
45
- # - status [string]: current PixRequest status. ex: "registered" or "paid"
46
- # - flow [string]: direction of money flow. ex: "in" or "out"
47
- # - sender_bank_code [string]: code of the sender bank institution in Brazil. If an ISPB (8 digits) is informed. ex: "20018183" or "341"
48
- # - created [Datetime, default nil]: creation datetime for the PixRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
49
- # - updated [Datetime, default nil]: latest update datetime for the PixRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
50
-
43
+ # - id [string]: unique id returned when the PixRequest is created. ex: '5656565656565656'
44
+ # - fee [integer]: fee charged when PixRequest is paid. ex: 200 (= R$ 2.00)
45
+ # - status [string]: current PixRequest status. ex: 'registered' or 'paid'
46
+ # - flow [string]: direction of money flow. ex: 'in' or 'out'
47
+ # - sender_bank_code [string]: code of the sender bank institution in Brazil. ex: '20018183'
48
+ # - created [DateTime]: creation datetime for the PixRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
49
+ # - updated [DateTime]: latest update datetime for the PixRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
51
50
  class PixRequest < StarkInfra::Utils::Resource
52
- attr_reader :amount, :external_id, :sender_name, :sender_tax_id, :sender_branch_code, :sender_account_number, :sender_account_type, :receiver_name, :receiver_tax_id, :receiver_bank_code, :receiver_account_number, :receiver_branch_code, :receiver_account_type, :end_to_end_id, :receiver_key_id, :sender_bank_code, :status, :reconciliation_id, :description, :flow, :initiator_tax_id, :cash_amount, :cashier_bank_code, :cashier_type, :tags, :created, :updated, :fee, :id
51
+ attr_reader :amount, :external_id, :sender_name, :sender_tax_id, :sender_branch_code, :sender_account_number,
52
+ :sender_account_type, :receiver_name, :receiver_tax_id, :receiver_bank_code, :receiver_account_number,
53
+ :receiver_branch_code, :receiver_account_type, :end_to_end_id, :receiver_key_id, :sender_bank_code,
54
+ :status, :reconciliation_id, :description, :flow, :initiator_tax_id, :cash_amount, :cashier_bank_code,
55
+ :cashier_type, :tags, :created, :updated, :fee, :id
53
56
  def initialize(
54
57
  amount:, external_id:, sender_name:, sender_tax_id:, sender_branch_code:, sender_account_number:,
55
58
  sender_account_type:, receiver_name:, receiver_tax_id:, receiver_bank_code:, receiver_account_number:,
@@ -97,7 +100,7 @@ module StarkInfra
97
100
  # - requests [list of PixRequest objects]: list of PixRequest objects to be created in the API
98
101
  #
99
102
  # ## Parameters (optional):
100
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
103
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
101
104
  #
102
105
  # ## Return:
103
106
  # - list of PixRequest objects with updated attributes
@@ -113,7 +116,7 @@ module StarkInfra
113
116
  # - id [string]: object unique id. ex: '5656565656565656'
114
117
  #
115
118
  # ## Parameters (optional):
116
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
119
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
117
120
  #
118
121
  # ## Return:
119
122
  # - PixRequest object with updated attributes
@@ -127,23 +130,21 @@ module StarkInfra
127
130
  #
128
131
  # ## Parameters (optional):
129
132
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
130
- # - fields [list of strings, default None]: parameters to be retrieved from PixRequest objects. ex: ["amount", "id"]
131
- # - after [Date, DateTime, Time or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
132
- # - before [Date, DateTime, Time or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
133
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
134
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
133
135
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
134
136
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
135
137
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
136
- # - end_to_end_ids [list of strings, default None]: central bank's unique transaction IDs. ex: ["E79457883202101262140HHX553UPqeq", "E79457883202101262140HHX553UPxzx"]
137
- # - external_ids [list of strings, default None]: url safe strings that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"]
138
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
138
+ # - end_to_end_ids [list of strings, default nil]: central bank's unique transaction IDs. ex: ['E79457883202101262140HHX553UPqeq', 'E79457883202101262140HHX553UPxzx']
139
+ # - external_ids [list of strings, default nil]: url safe strings that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ['my-internal-id-123456', 'my-internal-id-654321']
140
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
139
141
  #
140
142
  # ## Return:
141
143
  # - generator of PixRequest objects with updated attributes
142
- def self.query(fields: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, end_to_end_ids: nil, external_ids: nil, user: nil)
144
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, end_to_end_ids: nil, external_ids: nil, user: nil)
143
145
  after = StarkInfra::Utils::Checks.check_date(after)
144
146
  before = StarkInfra::Utils::Checks.check_date(before)
145
147
  StarkInfra::Utils::Rest.get_stream(
146
- fields: fields,
147
148
  limit: limit,
148
149
  after: after,
149
150
  before: before,
@@ -164,26 +165,24 @@ module StarkInfra
164
165
  #
165
166
  # ## Parameters (optional):
166
167
  # - cursor [string, default nil]: cursor returned on the previous page function call
167
- # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
168
- # - fields [list of strings, default None]: parameters to be retrieved from PixRequest objects. ex: ["amount", "id"]
169
- # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
170
- # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
168
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
169
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
170
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
171
171
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
172
172
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
173
173
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
174
- # - end_to_end_ids [list of strings, default None]: central bank's unique transaction IDs. ex: ["E79457883202101262140HHX553UPqeq", "E79457883202101262140HHX553UPxzx"]
175
- # - external_ids [list of strings, default None]: url safe strings that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"]
176
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
174
+ # - end_to_end_ids [list of strings, default nil]: central bank's unique transaction IDs. ex: ['E79457883202101262140HHX553UPqeq', 'E79457883202101262140HHX553UPxzx']
175
+ # - external_ids [list of strings, default nil]: url safe strings that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ['my-internal-id-123456', 'my-internal-id-654321']
176
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
177
177
  #
178
178
  # ## Return:
179
179
  # - list of PixRequest objects with updated attributes
180
- # - Cursor to retrieve the next page of PixRequest objects
181
- def self.page(cursor: nil, fields: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, end_to_end_ids: nil, external_ids: nil, user: nil)
180
+ # - cursor to retrieve the next page of PixRequest objects
181
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, end_to_end_ids: nil, external_ids: nil, user: nil)
182
182
  after = StarkInfra::Utils::Checks.check_date(after)
183
183
  before = StarkInfra::Utils::Checks.check_date(before)
184
- return StarkInfra::Utils::Rest.get_page(
184
+ StarkInfra::Utils::Rest.get_page(
185
185
  cursor: cursor,
186
- fields: fields,
187
186
  limit: limit,
188
187
  after: after,
189
188
  before: before,
@@ -197,24 +196,24 @@ module StarkInfra
197
196
  )
198
197
  end
199
198
 
199
+ # # Create single verified PixRequest object from a content string
200
+ #
201
+ # Create a single PixRequest object from a content string received from a handler listening at a subscribed user endpoint.
202
+ # If the provided digital signature does not check out with the StarkInfra public key, a
203
+ # StarkInfra.Error.InvalidSignatureError will be raised.
204
+ #
205
+ # ## Parameters (required):
206
+ # - content [string]: response content from request received at user endpoint (not parsed)
207
+ # - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
208
+ #
209
+ # ## Parameters (optional):
210
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
211
+ #
212
+ # ## Return:
213
+ # - Parsed PixRequest object
200
214
  def self.parse(content:, signature:, user: nil)
201
- # # Create single verified PixRequest object from a content string
202
- #
203
- # Create a single PixRequest object from a content string received from a handler listening at a subscribed user endpoint.
204
- # If the provided digital signature does not check out with the StarkInfra public key, a
205
- # starkinfra.exception.InvalidSignatureException will be raised.
206
- #
207
- # ## Parameters (required):
208
- # - content [string]: response content from request received at user endpoint (not parsed)
209
- # - signature [string]: base-64 digital signature received at response header "Digital-Signature"
210
- #
211
- # ## Parameters (optional):
212
- # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
213
- #
214
- # ## Return:
215
- # - Parsed PixRequest object
216
- return StarkInfra::Utils::Parse.parse_and_verify(content: content, signature: signature, user: user, resource: resource)
217
- end
215
+ StarkInfra::Utils::Parse.parse_and_verify(content: content, signature: signature, user: user, resource: resource)
216
+ end
218
217
 
219
218
  def self.resource
220
219
  {
@@ -250,7 +249,7 @@ module StarkInfra
250
249
  method: json['method'],
251
250
  sender_bank_code: json['sender_bank_code'],
252
251
  created: json['created'],
253
- updated: json['updated'],
252
+ updated: json['updated']
254
253
  )
255
254
  }
256
255
  }
@@ -37,7 +37,7 @@ module StarkInfra
37
37
  # - id [string]: object unique id. ex: '5656565656565656'
38
38
  #
39
39
  # ## Parameters (optional):
40
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
40
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
41
41
  #
42
42
  # ## Return:
43
43
  # - Log object with updated attributes
@@ -51,14 +51,14 @@ module StarkInfra
51
51
  #
52
52
  # ## Parameters (optional):
53
53
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
54
- # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
55
- # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
54
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
55
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
56
56
  # - types [list of strings, default nil]: filter retrieved objects by types. ex: 'success' or 'failed'
57
57
  # - reversal_ids [list of strings, default nil]: list of PixReversal ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
58
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
58
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
59
59
  #
60
60
  # ## Return:
61
- # - list of Log objects with updated attributes
61
+ # - generator of Log objects with updated attributes
62
62
  def self.query(limit: nil, after: nil, before: nil, types: nil, reversal_ids: nil, user: nil)
63
63
  after = StarkInfra::Utils::Checks.check_date(after)
64
64
  before = StarkInfra::Utils::Checks.check_date(before)
@@ -76,23 +76,24 @@ module StarkInfra
76
76
  # # Retrieve paged Logs
77
77
  #
78
78
  # Receive a list of up to 100 Log objects previously created in the Stark Infra API and the cursor to the next page.
79
- # Use this function instead of query if you want to manually page your requests.
79
+ # Use this function instead of query if you want to manually page your reversals.
80
80
  #
81
81
  # ## Parameters (optional):
82
82
  # - cursor [string, default nil]: cursor returned on the previous page function call
83
- # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
84
- # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
85
- # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
83
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
84
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
85
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
86
86
  # - types [list of strings, default nil]: filter retrieved objects by types. ex: 'success' or 'failed'
87
87
  # - reversal_ids [list of strings, default nil]: list of PixReversal ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
88
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
88
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
89
89
  #
90
90
  # ## Return:
91
- # - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
91
+ # - list of Log objects with updated attributes
92
+ # - cursor to retrieve the next page of Log objects
92
93
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, reversal_ids: nil, user: nil)
93
94
  after = StarkInfra::Utils::Checks.check_date(after)
94
95
  before = StarkInfra::Utils::Checks.check_date(before)
95
- return StarkInfra::Utils::Rest.get_page(
96
+ StarkInfra::Utils::Rest.get_page(
96
97
  cursor: cursor,
97
98
  limit: limit,
98
99
  after: after,
@@ -5,35 +5,33 @@ require_relative('../utils/rest')
5
5
  require_relative('../utils/checks')
6
6
  require_relative('../utils/parse')
7
7
 
8
-
9
8
  module StarkInfra
10
9
  # # PixReversal object
11
10
  #
12
- # When you initialize a PixReversal, the entity will not be automatically
13
- # created in the Stark Infra API. The 'create' function sends the objects
14
- # to the Stark Infra API and returns the list of created objects.
11
+ # When you initialize a PixReversal, the entity will not be automatically created in the Stark Infra API.
12
+ # The 'create' function sends the objects to the Stark Infra API and returns the list of created objects.
15
13
  #
16
14
  # ## Parameters (required):
17
15
  # - amount [integer]: amount in cents to be reversed from PixRequest. ex: 1234 (= R$ 12.34)
18
- # - external_id [string]: url safe string that must be unique among all your PixReversals. Duplicated external ids will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: "my-internal-id-123456"
19
- # - end_to_end_id [string]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq"
20
- # - reason [string]: reason why the PixRequest is being reversed. Options are "bankError", "fraud", "pixWithdrawError", "refund3ByEndCustomer"
16
+ # - external_id [string]: url safe string that must be unique among all your PixReversals. Duplicated external ids will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: 'my-internal-id-123456'
17
+ # - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
18
+ # - reason [string]: reason why the PixRequest is being reversed. Options are 'bankError', 'fraud', 'pixWithdrawError', 'refund3ByEndCustomer'
21
19
  #
22
20
  # ## Parameters (optional):
23
- # - tags [string, default nill]: [list of strings]: list of strings for reference when searching for PixReversals. ex: ["employees", "monthly"]
21
+ # - tags [string, default nil]: [list of strings]: list of strings for reference when searching for PixReversals. ex: ['employees', 'monthly']
24
22
  #
25
23
  # ## Attributes (return-only):
26
- # - id [string, default nil]: unique id returned when the PixReversal is created. ex: "5656565656565656".
27
- # - return_id [string]: central bank's unique reversal transaction ID. ex: "D20018183202202030109X3OoBHG74wo".
28
- # - bank_code [string]: code of the bank institution in Brazil. ex: "20018183" or "341"
24
+ # - id [string]: unique id returned when the PixReversal is created. ex: '5656565656565656'.
25
+ # - return_id [string]: central bank's unique reversal transaction ID. ex: 'D20018183202202030109X3OoBHG74wo'.
26
+ # - bank_code [string]: code of the bank institution in Brazil. ex: '20018183' or '341'
29
27
  # - fee [string]: fee charged by this PixReversal. ex: 200 (= R$ 2.00)
30
- # - status [string]: current PixReversal status. ex: "registered" or "paid"
31
- # - flow [string]: direction of money flow. ex: "in" or "out"
32
- # - created [Datetime, default nil]: creation datetime for the PixReversal. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
- # - updated [Datetime, default nil]: latest update datetime for the PixReversal. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
-
28
+ # - status [string]: current PixReversal status. ex: 'registered' or 'paid'
29
+ # - flow [string]: direction of money flow. ex: 'in' or 'out'
30
+ # - created [DateTime]: creation datetime for the PixReversal. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
31
+ # - updated [DateTime]: latest update datetime for the PixReversal. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
35
32
  class PixReversal < StarkInfra::Utils::Resource;
36
- attr_reader :amount, :external_id, :end_to_end_id, :reason, :tags, :id, :return_id, :bank_code, :fee, :status, :flow, :created, :updated
33
+ attr_reader :amount, :external_id, :end_to_end_id, :reason, :tags, :id, :return_id, :bank_code, :fee,
34
+ :status, :flow, :created, :updated
37
35
  def initialize(
38
36
  amount:, external_id:, end_to_end_id:, reason:, tags: nil, id: nil, return_id: nil, bank_code: nil, fee: nil,
39
37
  status: nil, flow: nil, created: nil, updated: nil
@@ -49,68 +47,68 @@ module StarkInfra
49
47
  @return_id = return_id
50
48
  @bank_code = bank_code
51
49
  @fee = fee
52
- @staus = status
50
+ @status = status
53
51
  @flow = flow
54
52
  @created = created
55
53
  @updated = updated
56
54
  end
57
55
 
58
- # # Create PixRversals
56
+ # # Create PixReversals
59
57
  #
60
- # Send a list of PixRversal objects for creation in the Stark Infra API
58
+ # Send a list of PixReversal objects for creation in the Stark Infra API
61
59
  #
62
60
  # ## Parameters (required):
63
- # - reversals [list of PixRversal objects]: list of PixRversal objects to be created in the API
61
+ # - reversals [list of PixReversal objects]: list of PixReversal objects to be created in the API
64
62
  #
65
63
  # ## Parameters (optional):
66
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
64
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
67
65
  #
68
66
  # ## Return:
69
- # - list of PixRversal objects with updated attributes
67
+ # - list of PixReversal objects with updated attributes
70
68
  def self.create(reversals, user: nil)
71
69
  StarkInfra::Utils::Rest.post(entities: reversals, user: user, **resource)
72
70
  end
73
71
 
74
- # # Retrieve a specific PixRversal
72
+ # # Retrieve a specific PixReversal
75
73
  #
76
- # Receive a single PixRversal object previously created in the Stark Bank API by passing its id
74
+ # Receive a single PixReversal object previously created in the Stark Infra API by passing its id
77
75
  #
78
76
  # ## Parameters (required):
79
77
  # - id [string]: object unique id. ex: '5656565656565656'
80
78
  #
81
79
  # ## Parameters (optional):
82
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
80
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
83
81
  #
84
82
  # ## Return:
85
- # - PixRversal object with updated attributes
83
+ # - PixReversal object with updated attributes
86
84
  def self.get(id, user: nil)
87
85
  StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
88
86
  end
89
87
 
90
- # # Retrieve PixRversals
88
+ # # Retrieve PixReversals
91
89
  #
92
- # Receive a generator of PixRversal objects previously created in the Stark Infra API
90
+ # Receive a generator of PixReversal objects previously created in the Stark Infra API
93
91
  #
94
92
  # ## Parameters (optional):
95
- # - fields [list of strings, default None]: parameters to be retrieved from PixRequest objects. ex: ["amount", "id"]
96
93
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
97
- # - after [Date, DateTime, Time or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
98
- # - before [Date, DateTime, Time or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
94
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
95
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
99
96
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
100
97
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
101
98
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
102
- # - return_ids [list of strings, default None]: central bank's unique reversal transaction ID. ex: ["D20018183202202030109X3OoBHG74wo", "D20018183202202030109X3OoBHG72rd"].
103
- # - external_ids [list of strings, default None]: url safe string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"]
104
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
99
+ # - return_ids [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ['D20018183202202030109X3OoBHG74wo', 'D20018183202202030109X3OoBHG72rd'].
100
+ # - external_ids [list of strings, default nil]: url safe string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ['my-internal-id-123456', 'my-internal-id-654321']
101
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
105
102
  #
106
103
  # ## Return:
107
- # - generator of PixRversal objects with updated attributes
108
- def self.query(fields:nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, return_ids: nil, external_ids: nil, user: nil)
104
+ # - generator of PixReversal objects with updated attributes
105
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, return_ids: nil, external_ids: nil, user: nil)
106
+ after = StarkInfra::Utils::Checks.check_date(after)
107
+ before = StarkInfra::Utils::Checks.check_date(before)
109
108
  StarkInfra::Utils::Rest.get_stream(
110
- fields: fields,
111
109
  limit: limit,
112
- after: StarkInfra::Utils::Checks.check_date(after),
113
- before: StarkInfra::Utils::Checks.check_date(before),
110
+ after: after,
111
+ before: before,
114
112
  status: status,
115
113
  tags: tags,
116
114
  ids: ids,
@@ -121,29 +119,28 @@ module StarkInfra
121
119
  )
122
120
  end
123
121
 
124
- # # Retrieve paged PixRversals
122
+ # # Retrieve paged PixReversals
125
123
  #
126
- # Receive a list of up to 100 PixRversal objects previously created in the Stark Infra API and the cursor to the next page.
127
- # Use this function instead of query if you want to manually page your requests.
124
+ # Receive a list of up to 100 PixReversal objects previously created in the Stark Infra API and the cursor to the next page.
125
+ # Use this function instead of query if you want to manually page your reversals.
128
126
  #
129
127
  # ## Parameters (optional):
130
128
  # - cursor [string, default nil]: cursor returned on the previous page function call
131
- # - fields [list of strings, default None]: parameters to be retrieved from PixRequest objects. ex: ["amount", "id"]
132
- # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
133
- # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
134
- # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
129
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
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)
135
132
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
136
133
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
137
134
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
138
- # - return_ids [list of strings, default None]: central bank's unique reversal transaction ID. ex: ["D20018183202202030109X3OoBHG74wo", "D20018183202202030109X3OoBHG72rd"].
139
- # - external_ids [list of strings, default None]: url safe string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"]
140
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
135
+ # - return_ids [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ['D20018183202202030109X3OoBHG74wo', 'D20018183202202030109X3OoBHG72rd'].
136
+ # - external_ids [list of strings, default nil]: url safe string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ['my-internal-id-123456', 'my-internal-id-654321']
137
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
141
138
  #
142
139
  # ## Return:
143
- # - list of PixRversal objects with updated attributes and cursor to retrieve the next page of PixRversal objects
144
- def self.page(cursor: nil, fields:nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, return_ids: nil, external_ids: nil, user: nil)
145
- return StarkInfra::Utils::Rest.get_page(
146
- fields: fields,
140
+ # - list of PixReversal objects with updated attributes
141
+ # - cursor to retrieve the next page of PixReversal objects
142
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, return_ids: nil, external_ids: nil, user: nil)
143
+ StarkInfra::Utils::Rest.get_page(
147
144
  cursor: cursor,
148
145
  limit: limit,
149
146
  after: StarkInfra::Utils::Checks.check_date(after),
@@ -158,24 +155,29 @@ module StarkInfra
158
155
  )
159
156
  end
160
157
 
158
+ # # Create single verified PixReversal object from a content string
159
+ #
160
+ # Create a single PixReversal object from a content string received from a handler listening at a subscribed user endpoint.
161
+ # If the provided digital signature does not check out with the StarkInfra public key, a
162
+ # StarkInfra.Error.InvalidSignatureError will be raised.
163
+ #
164
+ # ## Parameters (required):
165
+ # - content [string]: response content from reversal received at user endpoint (not parsed)
166
+ # - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
167
+ #
168
+ # ## Parameters (optional):
169
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
170
+ #
171
+ # ## Return:
172
+ # - Parsed PixReversal object
161
173
  def self.parse(content:, signature:, user: nil)
162
- # # Create single verified PixReversal object from a content string
163
- #
164
- # Create a single PixReversal object from a content string received from a handler listening at a subscribed user endpoint.
165
- # If the provided digital signature does not check out with the StarkInfra public key, a
166
- # starkinfra.exception.InvalidSignatureException will be raised.
167
- #
168
- # ## Parameters (required):
169
- # - content [string]: response content from revrsal received at user endpoint (not parsed)
170
- # - signature [string]: base-64 digital signature received at response header "Digital-Signature"
171
- #
172
- # ## Parameters (optional):
173
- # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
174
- #
175
- # ## Return:
176
- # - Parsed PixReversal object
177
- return StarkInfra::Utils::Parse.parse_and_verify(content: content, signature: signature, user: user, resource: resource)
178
- end
174
+ StarkInfra::Utils::Parse.parse_and_verify(
175
+ content: content,
176
+ signature: signature,
177
+ user: user,
178
+ resource: resource
179
+ )
180
+ end
179
181
 
180
182
  def self.resource
181
183
  {
@@ -194,7 +196,7 @@ module StarkInfra
194
196
  status: json['status'],
195
197
  flow: json['flow'],
196
198
  created: json['created'],
197
- updated: json['updated'],
199
+ updated: json['updated']
198
200
  )
199
201
  }
200
202
  }