starkbank 2.2.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/balance/balance.rb +2 -2
  3. data/lib/boleto/boleto.rb +53 -14
  4. data/lib/boleto/log.rb +36 -5
  5. data/lib/boleto_holmes/boleto_holmes.rb +41 -6
  6. data/lib/boleto_holmes/log.rb +36 -5
  7. data/lib/boleto_payment/boleto_payment.rb +42 -9
  8. data/lib/boleto_payment/log.rb +36 -5
  9. data/lib/brcode_payment/brcode_payment.rb +56 -17
  10. data/lib/brcode_payment/log.rb +36 -5
  11. data/lib/brcode_preview/brcode_preview.rb +5 -3
  12. data/lib/darf_payment/darf_payment.rb +218 -0
  13. data/lib/darf_payment/log.rb +125 -0
  14. data/lib/deposit/deposit.rb +46 -8
  15. data/lib/deposit/log.rb +36 -5
  16. data/lib/dict_key/dict_key.rb +45 -9
  17. data/lib/error.rb +13 -5
  18. data/lib/event/attempt.rb +125 -0
  19. data/lib/event/event.rb +44 -8
  20. data/lib/institution/institution.rb +67 -0
  21. data/lib/invoice/invoice.rb +81 -15
  22. data/lib/invoice/log.rb +52 -5
  23. data/lib/invoice/payment.rb +57 -0
  24. data/lib/payment_preview/boleto_preview.rb +75 -0
  25. data/lib/payment_preview/brcode_preview.rb +75 -0
  26. data/lib/payment_preview/payment_preview.rb +67 -0
  27. data/lib/payment_preview/tax_preview.rb +45 -0
  28. data/lib/payment_preview/utility_preview.rb +45 -0
  29. data/lib/payment_request/payment_request.rb +53 -11
  30. data/lib/starkbank.rb +14 -0
  31. data/lib/tax_payment/log.rb +125 -0
  32. data/lib/tax_payment/tax_payment.rb +203 -0
  33. data/lib/transaction/transaction.rb +39 -6
  34. data/lib/transfer/log.rb +36 -5
  35. data/lib/transfer/transfer.rb +59 -14
  36. data/lib/user/organization.rb +54 -0
  37. data/lib/user/project.rb +11 -6
  38. data/lib/user/user.rb +0 -4
  39. data/lib/utility_payment/log.rb +36 -5
  40. data/lib/utility_payment/utility_payment.rb +42 -9
  41. data/lib/utils/api.rb +1 -0
  42. data/lib/utils/request.rb +1 -1
  43. data/lib/utils/resource.rb +2 -21
  44. data/lib/utils/rest.rb +29 -14
  45. data/lib/utils/sub_resource.rb +28 -0
  46. data/lib/utils/url.rb +3 -1
  47. data/lib/webhook/webhook.rb +30 -9
  48. data/lib/workspace/workspace.rb +141 -0
  49. metadata +22 -7
@@ -17,11 +17,14 @@ module StarkBank
17
17
  # - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
18
18
  # - bank_code [string]: code of the receiver bank institution in Brazil. If an ISPB (8 digits) is informed, a PIX transfer will be created, else a TED will be issued. ex: '20018183' or '260'
19
19
  # - branch_code [string]: receiver bank account branch. Use '-' in case there is a verifier digit. ex: '1357-9'
20
- # - account_number [string]: Receiver Bank Account number. Use '-' before the verifier digit. ex: '876543-2'
20
+ # - account_number [string]: receiver bank account number. Use '-' before the verifier digit. ex: '876543-2'
21
21
  #
22
22
  # ## Parameters (optional):
23
- # - tags [list of strings]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
23
+ # - account_type [string, default 'checking']: receiver bank account type. This parameter only has effect on Pix Transfers. ex: 'checking', 'savings', 'salary' or 'payment'
24
+ # - external_id [string, default nil]: url safe string that must be unique among all your transfers. Duplicated external_ids will cause failures. By default, this parameter will block any transfer that repeats amount and receiver information on the same date. ex: 'my-internal-id-123456'
24
25
  # - scheduled [string, default now]: datetime when the transfer will be processed. May be pushed to next business day if necessary. ex: DateTime.new(2020, 3, 11, 8, 13, 12, 11)
26
+ # - description [string, default nil]: optional description to override default description to be shown in the bank statement. ex: 'Payment for service #1234'
27
+ # - tags [list of strings]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
25
28
  #
26
29
  # ## Attributes (return-only):
27
30
  # - id [string, default nil]: unique id returned when Transfer is created. ex: '5656565656565656'
@@ -31,8 +34,8 @@ module StarkBank
31
34
  # - created [DateTime, default nil]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
35
  # - updated [DateTime, default nil]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
36
  class Transfer < StarkBank::Utils::Resource
34
- attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :scheduled, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
35
- def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, scheduled: nil, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
37
+ attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :external_id, :scheduled, :description, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
38
+ def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, description: nil, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
36
39
  super(id)
37
40
  @amount = amount
38
41
  @name = name
@@ -40,7 +43,10 @@ module StarkBank
40
43
  @bank_code = bank_code
41
44
  @branch_code = branch_code
42
45
  @account_number = account_number
46
+ @account_type = account_type
47
+ @external_id = external_id
43
48
  @scheduled = StarkBank::Utils::Checks.check_date_or_datetime(scheduled)
49
+ @description = description
44
50
  @transaction_ids = transaction_ids
45
51
  @fee = fee
46
52
  @tags = tags
@@ -57,7 +63,7 @@ module StarkBank
57
63
  # - transfers [list of Transfer objects]: list of Transfer objects to be created in the API
58
64
  #
59
65
  # ## Parameters (optional):
60
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
66
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
61
67
  #
62
68
  # ## Return:
63
69
  # - list of Transfer objects with updated attributes
@@ -73,7 +79,7 @@ module StarkBank
73
79
  # - id [string]: object unique id. ex: '5656565656565656'
74
80
  #
75
81
  # ## Parameters (optional):
76
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
82
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
77
83
  #
78
84
  # ## Return:
79
85
  # - Transfer object with updated attributes
@@ -89,7 +95,7 @@ module StarkBank
89
95
  # - id [string]: Transfer unique id. ex: '5656565656565656'
90
96
  #
91
97
  # ## Parameters (optional):
92
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
98
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
93
99
  #
94
100
  # ## Return:
95
101
  # - deleted Transfer object
@@ -106,12 +112,12 @@ module StarkBank
106
112
  # - id [string]: object unique id. ex: '5656565656565656'
107
113
  #
108
114
  # ## Parameters (optional):
109
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
115
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
110
116
  #
111
117
  # ## Return:
112
118
  # - Transfer pdf file
113
119
  def self.pdf(id, user: nil)
114
- StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
120
+ StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
115
121
  end
116
122
 
117
123
  # # Retrieve Transfers
@@ -120,21 +126,57 @@ module StarkBank
120
126
  #
121
127
  # ## Parameters (optional):
122
128
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
123
- # - 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)
124
- # - 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)
129
+ # - 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)
130
+ # - 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)
125
131
  # - transactionIds [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
126
132
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
127
- # - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex: "012.345.678-90"
133
+ # - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex: '012.345.678-90'
128
134
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
129
135
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
130
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
136
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
131
137
  #
132
138
  # ## Return:
133
139
  # - generator of Transfer objects with updated attributes
134
140
  def self.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil)
135
141
  after = StarkBank::Utils::Checks.check_date(after)
136
142
  before = StarkBank::Utils::Checks.check_date(before)
137
- StarkBank::Utils::Rest.get_list(
143
+ StarkBank::Utils::Rest.get_stream(
144
+ limit: limit,
145
+ after: after,
146
+ before: before,
147
+ transaction_ids: transaction_ids,
148
+ status: status,
149
+ tax_id: tax_id,
150
+ sort: sort,
151
+ tags: tags,
152
+ ids: ids,
153
+ user: user,
154
+ **resource
155
+ )
156
+ end
157
+
158
+ # # Retrieve paged Transfers
159
+ #
160
+ # Receive a list of up to 100 Transfer objects previously created in the Stark Bank API and the cursor to the next page.
161
+ # Use this function instead of query if you want to manually page your requests.
162
+ #
163
+ # ## Parameters (optional):
164
+ # - cursor [string, default nil]: cursor returned on the previous page function call
165
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
166
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
167
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
168
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
169
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
170
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
171
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
172
+ #
173
+ # ## Return:
174
+ # - list of Transfer objects with updated attributes and cursor to retrieve the next page of Transfer objects
175
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil)
176
+ after = StarkBank::Utils::Checks.check_date(after)
177
+ before = StarkBank::Utils::Checks.check_date(before)
178
+ return StarkBank::Utils::Rest.get_page(
179
+ cursor: cursor,
138
180
  limit: limit,
139
181
  after: after,
140
182
  before: before,
@@ -161,7 +203,10 @@ module StarkBank
161
203
  bank_code: json['bank_code'],
162
204
  branch_code: json['branch_code'],
163
205
  account_number: json['account_number'],
206
+ account_type: json['account_type'],
207
+ external_id: json['external_id'],
164
208
  scheduled: json['scheduled'],
209
+ description: json['description'],
165
210
  transaction_ids: json['transaction_ids'],
166
211
  fee: json['fee'],
167
212
  tags: json['tags'],
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('user')
4
+
5
+ module StarkBank
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 Bank API must be authenticated via an SDK user,
12
+ # which must have been previously created at the Stark Bank website
13
+ # [https://web.sandbox.starkbank.com] or [https://web.starkbank.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 < StarkBank::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
data/lib/user/project.rb CHANGED
@@ -5,20 +5,21 @@ require_relative('user')
5
5
  module StarkBank
6
6
  # # Project object
7
7
  #
8
- # The Project object is the main authentication entity for the SDK.
9
- # All requests to the Stark Bank API must be authenticated via a project,
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 Bank API must be authenticated via an SDK user,
10
11
  # which must have been previously created at the Stark Bank website
11
- # [https://sandbox.web.starkbank.com] or [https://web.starkbank.com]
12
- # before you can use it in this SDK. Projects may be passed as a parameter on
12
+ # [https://web.sandbox.starkbank.com] or [https://web.starkbank.com]
13
+ # before you can use it in this SDK. Projects may be passed as the user parameter on
13
14
  # each request or may be defined as the default user at the start (See README).
14
15
  #
15
16
  # ## Parameters (required):
16
17
  # - id [string]: unique id required to identify project. ex: '5656565656565656'
17
- # - private_key [EllipticCurve.Project()]: PEM string of the private key linked to the project. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
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-----'
18
19
  # - environment [string]: environment where the project is being used. ex: 'sandbox' or 'production'
19
20
  #
20
21
  # ## Attributes (return-only):
21
- # - name [string, default ']: project name. ex: 'MyProject'
22
+ # - name [string, default '']: project name. ex: 'MyProject'
22
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']
23
24
  # - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
24
25
  class Project < StarkBank::User
@@ -28,5 +29,9 @@ module StarkBank
28
29
  @name = name
29
30
  @allowed_ips = allowed_ips
30
31
  end
32
+
33
+ def access_id
34
+ "project/#{@id}"
35
+ end
31
36
  end
32
37
  end
data/lib/user/user.rb CHANGED
@@ -13,10 +13,6 @@ module StarkBank
13
13
  @environment = StarkBank::Utils::Checks.check_environment(environment)
14
14
  end
15
15
 
16
- def access_id
17
- "#{self.class.name.split('::').last.downcase}/#{@id}"
18
- end
19
-
20
16
  def private_key
21
17
  EllipticCurve::PrivateKey.fromPem(@pem)
22
18
  end
@@ -37,7 +37,7 @@ module StarkBank
37
37
  # - id [string]: object unique id. ex: '5656565656565656'
38
38
  #
39
39
  # ## Parameters (optional):
40
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
40
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
41
41
  #
42
42
  # ## Return:
43
43
  # - Log object with updated attributes
@@ -51,24 +51,55 @@ module StarkBank
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, 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)
56
56
  # - types [list of strings, default nil]: filter retrieved objects by event types. ex: 'paid' or 'registered'
57
57
  # - payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
58
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
58
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
59
59
  #
60
60
  # ## Return:
61
61
  # - list of Log objects with updated attributes
62
62
  def self.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
63
63
  after = StarkBank::Utils::Checks.check_date(after)
64
64
  before = StarkBank::Utils::Checks.check_date(before)
65
- StarkBank::Utils::Rest.get_list(
65
+ StarkBank::Utils::Rest.get_stream(
66
+ limit: limit,
67
+ after: after,
68
+ before: before,
69
+ types: types,
70
+ payment_ids: payment_ids,
66
71
  user: user,
72
+ **resource
73
+ )
74
+ end
75
+
76
+ # # Retrieve paged Logs
77
+ #
78
+ # Receive a list of up to 100 Log objects previously created in the Stark Bank API and the cursor to the next page.
79
+ # Use this function instead of query if you want to manually page your requests.
80
+ #
81
+ # ## Parameters (optional):
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)
86
+ # - types [list of strings, default nil]: filter retrieved objects by event types. ex: 'paid' or 'registered'
87
+ # - payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
88
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
89
+ #
90
+ # ## Return:
91
+ # - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
92
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
93
+ after = StarkBank::Utils::Checks.check_date(after)
94
+ before = StarkBank::Utils::Checks.check_date(before)
95
+ return StarkBank::Utils::Rest.get_page(
96
+ cursor: cursor,
67
97
  limit: limit,
68
98
  after: after,
69
99
  before: before,
70
100
  types: types,
71
101
  payment_ids: payment_ids,
102
+ user: user,
72
103
  **resource
73
104
  )
74
105
  end
@@ -51,7 +51,7 @@ module StarkBank
51
51
  # - payments [list of UtilityPayment objects]: list of UtilityPayment objects to be created in the API
52
52
  #
53
53
  # ## Parameters (optional):
54
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
54
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
55
55
  #
56
56
  # ## Return:
57
57
  # - list of UtilityPayment objects with updated attributes
@@ -67,7 +67,7 @@ module StarkBank
67
67
  # - id [string]: object unique id. ex: '5656565656565656'
68
68
  #
69
69
  # ## Parameters (optional):
70
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
70
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
71
71
  #
72
72
  # ## Return:
73
73
  # - UtilityPayment object with updated attributes
@@ -84,12 +84,12 @@ module StarkBank
84
84
  # - id [string]: object unique id. ex: '5656565656565656'
85
85
  #
86
86
  # ## Parameters (optional):
87
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
87
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
88
88
  #
89
89
  # ## Return:
90
90
  # - UtilityPayment pdf file
91
91
  def self.pdf(id, user: nil)
92
- StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
92
+ StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
93
93
  end
94
94
 
95
95
  # # Retrieve UtilityPayments
@@ -98,26 +98,59 @@ module StarkBank
98
98
  #
99
99
  # ## Parameters (optional):
100
100
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
101
- # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
102
- # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
101
+ # - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
102
+ # - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
103
103
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
104
104
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
105
105
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid'
106
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
106
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
107
107
  #
108
108
  # ## Return:
109
109
  # - generator of UtilityPayment objects with updated attributes
110
110
  def self.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil)
111
111
  after = StarkBank::Utils::Checks.check_date(after)
112
112
  before = StarkBank::Utils::Checks.check_date(before)
113
- StarkBank::Utils::Rest.get_list(
113
+ StarkBank::Utils::Rest.get_stream(
114
+ limit: limit,
115
+ after: after,
116
+ before: before,
117
+ tags: tags,
118
+ ids: ids,
119
+ status: status,
114
120
  user: user,
121
+ **resource
122
+ )
123
+ end
124
+
125
+ # # Retrieve paged UtilityPayments
126
+ #
127
+ # Receive a list of up to 100 UtilityPayment objects previously created in the Stark Bank API and the cursor to the next page.
128
+ # Use this function instead of query if you want to manually page your requests.
129
+ #
130
+ # ## Parameters (optional):
131
+ # - cursor [string, default nil]: cursor returned on the previous page function call
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)
135
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
136
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
137
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid'
138
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
139
+ #
140
+ # ## Return:
141
+ # - list of UtilityPayment objects with updated attributes and cursor to retrieve the next page of UtilityPayment objects
142
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil)
143
+ after = StarkBank::Utils::Checks.check_date(after)
144
+ before = StarkBank::Utils::Checks.check_date(before)
145
+ return StarkBank::Utils::Rest.get_page(
146
+ cursor: cursor,
115
147
  limit: limit,
116
148
  after: after,
117
149
  before: before,
118
150
  tags: tags,
119
151
  ids: ids,
120
152
  status: status,
153
+ user: user,
121
154
  **resource
122
155
  )
123
156
  end
@@ -130,7 +163,7 @@ module StarkBank
130
163
  # - id [string]: UtilityPayment unique id. ex:'5656565656565656'
131
164
  #
132
165
  # ## Parameters (optional):
133
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
166
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
134
167
  #
135
168
  # ## Return:
136
169
  # - deleted UtilityPayment object
data/lib/utils/api.rb CHANGED
@@ -57,6 +57,7 @@ module StarkBank
57
57
  def self.endpoint(resource_name)
58
58
  kebab = StarkBank::Utils::Case.camel_to_kebab(resource_name)
59
59
  kebab.sub!('-log', '/log')
60
+ kebab.sub!('-attempt', '/attempt')
60
61
  kebab
61
62
  end
62
63
 
data/lib/utils/request.rb CHANGED
@@ -61,7 +61,7 @@ module StarkBank
61
61
  req['Access-Time'] = access_time
62
62
  req['Access-Signature'] = signature
63
63
  req['Content-Type'] = 'application/json'
64
- req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.2.1"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.6.0"
65
65
  req['Accept-Language'] = language
66
66
 
67
67
  request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }