starkinfra 0.0.2 → 0.0.3

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 +561 -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 +260 -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 +81 -0
  18. data/lib/issuingtransaction/issuingtransaction.rb +136 -0
  19. data/lib/issuingwithdrawal/issuingwithdrawal.rb +153 -0
  20. data/lib/pixbalance/pixbalance.rb +13 -13
  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 +225 -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 +239 -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 +72 -71
  36. data/lib/pixstatement/pixstatement.rb +22 -23
  37. data/lib/starkinfra.rb +32 -2
  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 +1 -1
  47. data/lib/utils/rest.rb +7 -5
  48. data/lib/utils/returnid.rb +11 -0
  49. data/lib/webhook/webhook.rb +124 -0
  50. metadata +45 -24
@@ -5,33 +5,30 @@ 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
33
  attr_reader :amount, :external_id, :end_to_end_id, :reason, :tags, :id, :return_id, :bank_code, :fee, :status, :flow, :created, :updated
37
34
  def initialize(
@@ -49,68 +46,68 @@ module StarkInfra
49
46
  @return_id = return_id
50
47
  @bank_code = bank_code
51
48
  @fee = fee
52
- @staus = status
49
+ @status = status
53
50
  @flow = flow
54
51
  @created = created
55
52
  @updated = updated
56
53
  end
57
54
 
58
- # # Create PixRversals
55
+ # # Create PixReversals
59
56
  #
60
- # Send a list of PixRversal objects for creation in the Stark Infra API
57
+ # Send a list of PixReversal objects for creation in the Stark Infra API
61
58
  #
62
59
  # ## Parameters (required):
63
- # - reversals [list of PixRversal objects]: list of PixRversal objects to be created in the API
60
+ # - reversals [list of PixReversal objects]: list of PixReversal objects to be created in the API
64
61
  #
65
62
  # ## Parameters (optional):
66
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
63
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
67
64
  #
68
65
  # ## Return:
69
- # - list of PixRversal objects with updated attributes
66
+ # - list of PixReversal objects with updated attributes
70
67
  def self.create(reversals, user: nil)
71
68
  StarkInfra::Utils::Rest.post(entities: reversals, user: user, **resource)
72
69
  end
73
70
 
74
- # # Retrieve a specific PixRversal
71
+ # # Retrieve a specific PixReversal
75
72
  #
76
- # Receive a single PixRversal object previously created in the Stark Bank API by passing its id
73
+ # Receive a single PixReversal object previously created in the Stark Infra API by passing its id
77
74
  #
78
75
  # ## Parameters (required):
79
76
  # - id [string]: object unique id. ex: '5656565656565656'
80
77
  #
81
78
  # ## Parameters (optional):
82
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
79
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
83
80
  #
84
81
  # ## Return:
85
- # - PixRversal object with updated attributes
82
+ # - PixReversal object with updated attributes
86
83
  def self.get(id, user: nil)
87
84
  StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
88
85
  end
89
86
 
90
- # # Retrieve PixRversals
87
+ # # Retrieve PixReversals
91
88
  #
92
- # Receive a generator of PixRversal objects previously created in the Stark Infra API
89
+ # Receive a generator of PixReversal objects previously created in the Stark Infra API
93
90
  #
94
91
  # ## Parameters (optional):
95
- # - fields [list of strings, default None]: parameters to be retrieved from PixRequest objects. ex: ["amount", "id"]
96
92
  # - 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)
93
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
94
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
99
95
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
100
96
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
101
97
  # - 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
98
+ # - return_ids [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ['D20018183202202030109X3OoBHG74wo', 'D20018183202202030109X3OoBHG72rd'].
99
+ # - 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']
100
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
105
101
  #
106
102
  # ## 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)
103
+ # - generator of PixReversal objects with updated attributes
104
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, return_ids: nil, external_ids: nil, user: nil)
105
+ after = StarkInfra::Utils::Checks.check_date(after)
106
+ before = StarkInfra::Utils::Checks.check_date(before)
109
107
  StarkInfra::Utils::Rest.get_stream(
110
- fields: fields,
111
108
  limit: limit,
112
- after: StarkInfra::Utils::Checks.check_date(after),
113
- before: StarkInfra::Utils::Checks.check_date(before),
109
+ after: after,
110
+ before: before,
114
111
  status: status,
115
112
  tags: tags,
116
113
  ids: ids,
@@ -121,29 +118,28 @@ module StarkInfra
121
118
  )
122
119
  end
123
120
 
124
- # # Retrieve paged PixRversals
121
+ # # Retrieve paged PixReversals
125
122
  #
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.
123
+ # Receive a list of up to 100 PixReversal objects previously created in the Stark Infra API and the cursor to the next page.
124
+ # Use this function instead of query if you want to manually page your reversals.
128
125
  #
129
126
  # ## Parameters (optional):
130
127
  # - 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)
128
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
129
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
130
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
135
131
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
136
132
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
137
133
  # - 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
134
+ # - return_ids [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ['D20018183202202030109X3OoBHG74wo', 'D20018183202202030109X3OoBHG72rd'].
135
+ # - 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']
136
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
141
137
  #
142
138
  # ## 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,
139
+ # - list of PixReversal objects with updated attributes
140
+ # - cursor to retrieve the next page of PixReversal objects
141
+ 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)
142
+ StarkInfra::Utils::Rest.get_page(
147
143
  cursor: cursor,
148
144
  limit: limit,
149
145
  after: StarkInfra::Utils::Checks.check_date(after),
@@ -158,24 +154,29 @@ module StarkInfra
158
154
  )
159
155
  end
160
156
 
157
+ # # Create single verified PixReversal object from a content string
158
+ #
159
+ # Create a single PixReversal object from a content string received from a handler listening at a subscribed user endpoint.
160
+ # If the provided digital signature does not check out with the StarkInfra public key, a
161
+ # StarkInfra.Error.InvalidSignatureError will be raised.
162
+ #
163
+ # ## Parameters (required):
164
+ # - content [string]: response content from reversal received at user endpoint (not parsed)
165
+ # - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
166
+ #
167
+ # ## Parameters (optional):
168
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
169
+ #
170
+ # ## Return:
171
+ # - Parsed PixReversal object
161
172
  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
173
+ StarkInfra::Utils::Parse.parse_and_verify(
174
+ content: content,
175
+ signature: signature,
176
+ user: user,
177
+ resource: resource
178
+ )
179
+ end
179
180
 
180
181
  def self.resource
181
182
  {
@@ -194,7 +195,7 @@ module StarkInfra
194
195
  status: json['status'],
195
196
  flow: json['flow'],
196
197
  created: json['created'],
197
- updated: json['updated'],
198
+ updated: json['updated']
198
199
  )
199
200
  }
200
201
  }
@@ -12,17 +12,16 @@ module StarkInfra
12
12
  # accessed by the user. This feature is only available for direct participants.
13
13
  #
14
14
  # ## Parameters (required):
15
- # - after [Date, DateTime, Time or string]: transactions that happened at this date are stored in the PixStatement, must be the same as before. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
16
- # - before [Date, DateTime, Time or string]: transactions that happened at this date are stored in the PixStatement, must be the same as after. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
17
- # - type [string]: types of entities to include in statement. Options: ["interchange", "interchangeTotal", "transaction"]
15
+ # - after [Date or string]: transactions that happened at this date are stored in the PixStatement, must be the same as before. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
16
+ # - before [Date or string]: transactions that happened at this date are stored in the PixStatement, must be the same as after. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
17
+ # - type [string]: type of entities to include in statement. Options: 'interchange', 'interchangeTotal', 'transaction'
18
18
  #
19
19
  # ## Attributes (return-only):
20
- # - id [string, default nil]: unique id returned when the PixStatement is created. ex: "5656565656565656"
21
- # - status [string, default nil]: current PixStatement status. ex: "success" or "failed"
22
- # - transaction_count [integer]: number of transactions that happened during the day that the PixStatement was requested. ex 11
23
- # - created [Datetime, default nil]: creation datetime for the PixStatement. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
24
- # - updated [Datetime, default nil]: latest update datetime for the PixStatement. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
25
-
20
+ # - id [string]: unique id returned when the PixStatement is created. ex: '5656565656565656'
21
+ # - status [string]: current PixStatement status. ex: 'success' or 'failed'
22
+ # - transaction_count [integer]: number of transactions that happened during the day that the PixStatement was requested. ex: 11
23
+ # - created [DateTime]: creation datetime for the PixStatement. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
24
+ # - updated [DateTime]: latest update datetime for the PixStatement. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
26
25
  class PixStatement < StarkInfra::Utils::Resource
27
26
  attr_reader :after, :before, :type, :id, :status, :transaction_count, :created, :updated
28
27
  def initialize(after:, before:, type:, id: nil, status: nil, transaction_count: nil, created: nil, updated: nil)
@@ -40,11 +39,11 @@ module StarkInfra
40
39
  #
41
40
  # Create a PixStatements linked to your workspace in the Stark Infra API
42
41
  #
43
- # ## Parameters (requiered):
42
+ # ## Parameters (required):
44
43
  # - statement [PixStatement object]: PixStatement object to be created in the API.
45
44
  #
46
45
  # ## Parameters (optional):
47
- # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
46
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
48
47
  #
49
48
  # ## Return:
50
49
  # - PixStatement object with updated attributes.
@@ -52,18 +51,18 @@ module StarkInfra
52
51
  StarkInfra::Utils::Rest.post_single(entity: statement, user: user, **resource)
53
52
  end
54
53
 
55
- # # Retrieve a specific PixStatment object
54
+ # # Retrieve a specific PixStatement object
56
55
  #
57
- # Receive a single PixStatment object previously created in the Stark Infra API by passing its id
56
+ # Receive a single PixStatement object previously created in the Stark Infra API by passing its id
58
57
  #
59
58
  # ## Parameters (required):
60
59
  # - id [string]: object unique id. ex: '5656565656565656'
61
60
  #
62
61
  # ## Parameters (optional):
63
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
62
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
64
63
  #
65
64
  # ## Return:
66
- # - PixStatment object with updated attributes
65
+ # - PixStatement object with updated attributes
67
66
  def self.get(id, user: nil)
68
67
  StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
69
68
  end
@@ -75,7 +74,7 @@ module StarkInfra
75
74
  # ## Parameters (optional):
76
75
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
77
76
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
78
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
77
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
79
78
  #
80
79
  # ## Return:
81
80
  # - generator of PixStatement objects with updated attributes
@@ -91,19 +90,19 @@ module StarkInfra
91
90
  # # Retrieve paged PixStatements
92
91
  #
93
92
  # Receive a list of up to 100 PixStatements objects previously created in the Stark infra API and the cursor to the next page.
94
- # Use this function instead of query if you want to manually page your requests.
93
+ # Use this function instead of query if you want to manually page your statements.
95
94
  #
96
95
  # ## Parameters (optional):
97
96
  # - cursor [string, default nil]: cursor returned on the previous page function call
98
- # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
97
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
99
98
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
100
- # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
99
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
101
100
  #
102
101
  # ## Return:
103
102
  # - list of PixStatement objects with updated attributes
104
- # - Cursor to retrieve the next page of PixStatement objects
103
+ # - cursor to retrieve the next page of PixStatement objects
105
104
  def self.page(cursor: nil, limit: nil, ids: nil, user: nil)
106
- return StarkInfra::Utils::Rest.get_page(
105
+ StarkInfra::Utils::Rest.get_page(
107
106
  cursor: cursor,
108
107
  limit: limit,
109
108
  ids: ids,
@@ -117,10 +116,10 @@ module StarkInfra
117
116
  # Retrieve a specific PixStatement by its ID in a .csv file.
118
117
  #
119
118
  # ## Parameters (required):
120
- # - id [string]: object unique id. ex: "5656565656565656"
119
+ # - id [string]: object unique id. ex: '5656565656565656'
121
120
  #
122
121
  # ## Parameters (optional):
123
- # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
122
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
124
123
  #
125
124
  # ## Return:
126
125
  # - PixStatement .csv file
data/lib/starkinfra.rb CHANGED
@@ -1,18 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require('starkbank')
4
3
  require_relative('key')
4
+ require_relative('user/project')
5
+ require_relative('user/organization')
6
+ require_relative('issuingauthorization/issuingauthorization')
7
+ require_relative('issuingbalance/issuingbalance')
8
+ require_relative('issuingbin/issuingbin')
9
+ require_relative('issuingcard/issuingcard')
10
+ require_relative('issuingcard/log')
11
+ require_relative('issuingholder/issuingholder')
12
+ require_relative('issuingholder/log')
13
+ require_relative('issuinginvoice/issuinginvoice')
14
+ require_relative('issuinginvoice/log')
15
+ require_relative('issuingpurchase/issuingpurchase')
16
+ require_relative('issuingpurchase/log')
17
+ require_relative('issuingtransaction/issuingtransaction')
18
+ require_relative('issuingwithdrawal/issuingwithdrawal')
19
+ require_relative('issuingrule/issuingrule')
5
20
  require_relative('pixrequest/pixrequest')
6
21
  require_relative('pixrequest/log')
7
22
  require_relative('pixreversal/pixreversal')
8
23
  require_relative('pixreversal/log')
9
24
  require_relative('pixbalance/pixbalance')
10
25
  require_relative('pixstatement/pixstatement')
26
+ require_relative('pixinfraction/pixinfraction')
27
+ require_relative('pixinfraction/log')
28
+ require_relative('pixchargeback/pixchargeback')
29
+ require_relative('pixchargeback/log')
30
+ require_relative('pixkey/pixkey')
31
+ require_relative('pixkey/log')
32
+ require_relative('pixclaim/pixclaim')
33
+ require_relative('pixclaim/log')
34
+ require_relative('pixdomain/pixdomain')
35
+ require_relative('pixdirector/pixdirector')
36
+ require_relative('webhook/webhook')
11
37
  require_relative('event/event')
38
+ require_relative('event/attempt')
39
+ require_relative('utils/endtoendid')
40
+ require_relative('utils/returnid')
41
+ require_relative('creditnote/creditnote')
42
+ require_relative('creditnote/log')
12
43
 
13
44
  # SDK to facilitate Ruby integrations with Stark Infra
14
45
  module StarkInfra
15
- include StarkBank
16
46
  @user = nil
17
47
  @language = 'en-US'
18
48
  class << self; attr_accessor :user, :language; end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('user')
4
+
5
+ module StarkInfra
6
+ # # Organization object
7
+ # The Organization object is an authentication entity for the SDK that
8
+ # represents your entire Organization, being able to access any Workspace
9
+ # underneath it and even create new Workspaces. Only a legal representative
10
+ # of your organization can register or change the Organization credentials.
11
+ # All requests to the Stark Infra API must be authenticated via an SDK user,
12
+ # which must have been previously created at the Stark Infra website
13
+ # [https://web.sandbox.starkinfra.com] or [https://web.starkinfra.com]
14
+ # before you can use it in this SDK. Organizations may be passed as the user parameter on
15
+ # each request or may be defined as the default user at the start (See README).
16
+ # If you are accessing a specific Workspace using Organization credentials, you should
17
+ # specify the workspace ID when building the Organization object or by request, using
18
+ # the Organization.replace(organization, workspace_id) method, which creates a copy of the organization
19
+ # object with the altered workspace ID. If you are listing or creating new Workspaces, the
20
+ # workspace_id should be nil.
21
+ #
22
+ # ## Parameters (required):
23
+ # - environment [string]: environment where the organization is being used. ex: 'sandbox' or 'production'
24
+ # - id [string]: unique id required to identify organization. ex: '5656565656565656'
25
+ # - private_key [string]: PEM string of the private key linked to the organization. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
26
+ # - workspace_id [string]: unique id of the accessed Workspace, if any. ex: nil or '4848484848484848'
27
+ #
28
+ # ## Attributes (return-only):
29
+ # - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
30
+ class Organization < StarkInfra::User
31
+ attr_reader :workspace_id
32
+ def initialize(id:, environment:, private_key:, workspace_id: nil)
33
+ super(environment, id, private_key)
34
+ @workspace_id = workspace_id
35
+ end
36
+
37
+ def access_id
38
+ if @workspace_id
39
+ "organization/#{@id}/workspace/#{@workspace_id}"
40
+ else
41
+ "organization/#{@id}"
42
+ end
43
+ end
44
+
45
+ def self.replace(organization, workspace_id)
46
+ Organization.new(
47
+ environment: organization.environment,
48
+ id: organization.id,
49
+ private_key: organization.pem,
50
+ workspace_id: workspace_id
51
+ )
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('user')
4
+
5
+ module StarkInfra
6
+ # # Project object
7
+ #
8
+ # The Project object is an authentication entity for the SDK that is permanently
9
+ # linked to a specific Workspace.
10
+ # All requests to the Stark Infra API must be authenticated via an SDK user,
11
+ # which must have been previously created at the Stark Infra website
12
+ # [https://web.sandbox.starkinfra.com] or [https://web.starkinfra.com]
13
+ # before you can use it in this SDK. Projects may be passed as the user parameter on
14
+ # each request or may be defined as the default user at the start (See README).
15
+ #
16
+ # ## Parameters (required):
17
+ # - id [string]: unique id required to identify project. ex: '5656565656565656'
18
+ # - private_key [string]: PEM string of the private key linked to the project. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
19
+ # - environment [string]: environment where the project is being used. ex: 'sandbox' or 'production'
20
+ #
21
+ # ## Attributes (return-only):
22
+ # - name [string, default '']: project name. ex: 'MyProject'
23
+ # - allowed_ips [list of strings]: list containing the strings of the ips allowed to make requests on behalf of this project. ex: ['190.190.0.50']
24
+ # - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
25
+ class Project < StarkInfra::User
26
+ attr_reader :name, :allowed_ips
27
+ def initialize(environment:, id:, private_key:, name: '', allowed_ips: nil)
28
+ super(environment, id, private_key)
29
+ @name = name
30
+ @allowed_ips = allowed_ips
31
+ end
32
+
33
+ def access_id
34
+ "project/#{@id}"
35
+ end
36
+ end
37
+ end
data/lib/user/user.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkbank-ecdsa')
4
+ require_relative('../utils/resource')
5
+
6
+ module StarkInfra
7
+ class User < StarkInfra::Utils::Resource
8
+ attr_reader :pem, :environment
9
+ def initialize(environment, id, private_key)
10
+ require_relative('../utils/checks')
11
+ super(id)
12
+ @pem = StarkInfra::Utils::Checks.check_private_key(private_key)
13
+ @environment = StarkInfra::Utils::Checks.check_environment(environment)
14
+ end
15
+
16
+ def private_key
17
+ EllipticCurve::PrivateKey.fromPem(@pem)
18
+ end
19
+ end
20
+ end
data/lib/utils/api.rb CHANGED
@@ -41,7 +41,15 @@ module StarkInfra
41
41
 
42
42
  list = []
43
43
  value.each do |v|
44
- list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
44
+ if v.is_a?(Hash)
45
+ list << cast_json_to_api_format(v)
46
+ next
47
+ end
48
+ if v.is_a?(SubResource)
49
+ list << api_json(v)
50
+ next
51
+ end
52
+ list << v
45
53
  end
46
54
  list
47
55
  end
@@ -51,7 +59,7 @@ module StarkInfra
51
59
  json.each do |key, value|
52
60
  snakes[StarkInfra::Utils::Case.camel_to_snake(key)] = value
53
61
  end
54
-
62
+
55
63
  resource_maker.call(snakes)
56
64
  end
57
65
 
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: false
2
+
3
+ require('date')
4
+
5
+ module StarkInfra
6
+ module Utils
7
+ module BacenId
8
+ def self._create(bank_code)
9
+ random_source = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'.split('')
10
+ random_string = ''
11
+
12
+ 11.times do
13
+ random_string << random_source[rand(random_source.length)]
14
+ end
15
+ bank_code + DateTime.now.strftime('%Y%m%d%H%M') << random_string
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/utils/checks.rb CHANGED
@@ -2,14 +2,13 @@
2
2
 
3
3
  require('date')
4
4
  require('starkbank-ecdsa')
5
- require('starkbank')
6
5
  require_relative('environment')
7
6
 
8
7
  module StarkInfra
9
8
  module Utils
10
9
  class Checks
11
10
  def self.check_user(user)
12
- return user if user.is_a?(StarkBank::User)
11
+ return user if user.is_a?(StarkInfra::User)
13
12
 
14
13
  user = user.nil? ? StarkInfra.user : user
15
14
  raise(ArgumentError, 'A user is required to access our API. Check our README: https://github.com/starkinfra/sdk-ruby/') if user.nil?
@@ -90,7 +89,7 @@ module StarkInfra
90
89
  end
91
90
 
92
91
  begin
93
- return [DateTime.strptime(data, '%Y-%m-%d'), 'date']
92
+ [DateTime.strptime(data, '%Y-%m-%d'), 'date']
94
93
  rescue ArgumentError
95
94
  raise(ArgumentError, 'invalid datetime string ' + data)
96
95
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: false
2
+
3
+ require_relative('bacenid')
4
+
5
+ module StarkInfra
6
+ module EndToEndId
7
+ def self.create(bank_code)
8
+ 'E' << StarkInfra::Utils::BacenId._create(bank_code)
9
+ end
10
+ end
11
+ end