starkinfra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1b2d73527c71a16d43d7ca77550b2587761a4b798b5209b968fba9372965aa63
4
+ data.tar.gz: 913fc4e725a905872303de82eae3f9a78b43af6b2670c9112dc07ab8baf2e6e7
5
+ SHA512:
6
+ metadata.gz: 4fc841538399331ccc143aa5b58dcc7cf9ee9715f7eb1133bc21abeff44937b4e41cb42a8467fa497cb58f407bb1e1df1cd67d8bf1b88dd70e0b96c70d02d2a4
7
+ data.tar.gz: 6d9ab720be52e7ce5789c377eff8d5b9ecf5e51ce4fb90e2c7a8faf73b8baca551e46421daf38af005bf4e165e96d29e6dacbdd158ffbd91f5f8321ac602b2d7
data/lib/error.rb ADDED
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('json')
4
+
5
+ module StarkInfra
6
+ module Error
7
+ class StarkInfraError < StandardError
8
+ attr_reader :message
9
+ def initialize(message)
10
+ @message = message
11
+ super(message)
12
+ end
13
+ end
14
+
15
+ class Error < StarkInfraError
16
+ attr_reader :code, :message
17
+ def initialize(code, message)
18
+ @code = code
19
+ @message = message
20
+ super("#{code}: #{message}")
21
+ end
22
+ end
23
+
24
+ class InputErrors < StarkInfraError
25
+ attr_reader :errors
26
+ def initialize(content)
27
+ errors = []
28
+ content.each do |error|
29
+ errors << Error.new(error['code'], error['message'])
30
+ end
31
+ @errors = errors
32
+
33
+ super(content.to_json)
34
+ end
35
+ end
36
+
37
+ class InternalServerError < StarkInfraError
38
+ def initialize(message = 'Houston, we have a problem.')
39
+ super(message)
40
+ end
41
+ end
42
+
43
+ class UnknownError < StarkInfraError
44
+ def initialize(message)
45
+ super("Unknown exception encountered: #{message}")
46
+ end
47
+ end
48
+
49
+ class InvalidSignatureError < StarkInfraError
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('json')
4
+ require('starkbank-ecdsa')
5
+ require_relative('../utils/resource')
6
+ require_relative('../utils/rest')
7
+ require_relative('../utils/checks')
8
+ require_relative('../utils/cache')
9
+ require_relative('../error')
10
+ require_relative('../pixrequest/log')
11
+ require_relative('../pixreversal/log')
12
+ require_relative('../utils/parse')
13
+
14
+
15
+ module StarkInfra
16
+ # # Webhook Event object
17
+ #
18
+ # An Event is the notification received from the subscription to the Webhook.
19
+ # Events cannot be created, but may be retrieved from the Stark Infra API to
20
+ # list all generated updates on entities.
21
+ #
22
+ # ## Attributes:
23
+ # - id [string]: unique id returned when the event is created. ex: '5656565656565656'
24
+ # - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
25
+ # - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
26
+ # - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
27
+ # - workspace_id [string]: ID of the Workspace that generated this event. Mostly used when multiple Workspaces have Webhooks registered to the same endpoint. ex: '4545454545454545'
28
+ # - subscription [string]: service that triggered this event. ex: 'pix-request.in', 'pix-request.out'
29
+ class Event < StarkInfra::Utils::Resource
30
+ attr_reader :id, :log, :created, :is_delivered, :workspace_id, :subscription
31
+ def initialize(id:, log:, created:, is_delivered:, workspace_id:, subscription:)
32
+ super(id)
33
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
34
+ @is_delivered = is_delivered
35
+ @workspace_id = workspace_id
36
+ @subscription = subscription
37
+
38
+ resource = {
39
+ 'pix-request.in': StarkInfra::PixRequest::Log.resource,
40
+ 'pix-request.out': StarkInfra::PixRequest::Log.resource,
41
+ 'pix-reversal.in': StarkInfra::PixReversal::Log.resource,
42
+ 'pix-reversal.out': StarkInfra::PixReversal::Log.resource,
43
+ }[subscription.to_sym]
44
+
45
+ @log = log
46
+ @log = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], log) unless resource.nil?
47
+ end
48
+
49
+ # # Create single notification Event from a content string
50
+ #
51
+ # Create a single Event object received from event listening at subscribed user endpoint.
52
+ # If the provided digital signature does not check out with the StarkInfra public key, a
53
+ # starkinfra.exception.InvalidSignatureException will be raised.
54
+ #
55
+ # ## Parameters (required):
56
+ # - content [string]: response content from request received at user endpoint (not parsed)
57
+ # - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
58
+ #
59
+ # ## Parameters (optional):
60
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
61
+ #
62
+ # ## Return:
63
+ # - Parsed Event object
64
+ def self.parse(content:, signature:, user: nil)
65
+ return StarkInfra::Utils::Parse.parse_and_verify(content: content, signature: signature, user: user, resource: resource, key: 'event')
66
+ end
67
+
68
+ class << self
69
+ private
70
+
71
+ def resource
72
+ {
73
+ resource_name: 'Event',
74
+ resource_maker: proc { |json|
75
+ Event.new(
76
+ id: json['id'],
77
+ log: json['log'],
78
+ created: json['created'],
79
+ is_delivered: json['is_delivered'],
80
+ workspace_id: json['workspace_id'],
81
+ subscription: json['subscription']
82
+ )
83
+ }
84
+ }
85
+ end
86
+ end
87
+ end
88
+ end
89
+
data/lib/key.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('fileutils')
4
+ require('starkbank-ecdsa')
5
+
6
+ module StarkInfra
7
+ module Key
8
+ # # Generate a new key pair
9
+ # Generates a secp256k1 ECDSA private/public key pair to be used in the API
10
+ # authentications
11
+ #
12
+ # ## Parameters (optional):
13
+ # - path [string]: path to save the keys .pem files. No files will be saved if this parameter isn't provided
14
+ #
15
+ # ## Return:
16
+ # - private and public key pems
17
+ def self.create(path = nil)
18
+ private_key = EllipticCurve::PrivateKey.new
19
+ public_key = private_key.publicKey
20
+
21
+ private_key_pem = private_key.toPem
22
+ public_key_pem = public_key.toPem
23
+
24
+ unless path.nil?
25
+ FileUtils.mkdir_p(path)
26
+ File.write(File.join(path, 'private.pem'), private_key_pem)
27
+ File.write(File.join(path, 'public.pem'), public_key_pem)
28
+ end
29
+
30
+ [private_key_pem, public_key_pem]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkInfra
8
+ # # PixBalance object
9
+ #
10
+ # The PixBalance object displays the current balance of the workspace,
11
+ # which is the result of the sum of all transactions within this
12
+ # workspace. The balance is never generated by the user, but it
13
+ # can be retrieved to see the available information.
14
+ # ## Attributes (return-only):
15
+ # - id [string]: unique id returned when Balance is created. ex: "5656565656565656"
16
+ # - amount [integer]: current balance amount of the workspace in cents. ex: 200 (= R$ 2.00)
17
+ # - currency [string]: currency of the current workspace. Expect others to be added eventually. ex: "BRL"
18
+ # - updated [Datetime]: latest update datetime for the balance. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
+
20
+ class PixBalance < StarkInfra::Utils::Resource
21
+ attr_reader :amount, :currency, :updated, :id
22
+ def initialize(amount: nil, currency: nil, updated: nil, id: nil)
23
+ super(id)
24
+ @amount = amount
25
+ @currency = currency
26
+ @updated = updated
27
+ end
28
+
29
+ # # Retrieve PixBalance
30
+ #
31
+ # Receive the PixBalance object linked to your workspace in the Stark Infra API
32
+ #
33
+ # ## Parameters (optional):
34
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
35
+ #
36
+ # ## Return:
37
+ # - PixBalance object with updated attributes
38
+ def self.get(user: nil)
39
+ StarkInfra::Utils::Rest.get_stream(user: user, **resource)
40
+ end
41
+
42
+ def self.resource
43
+ {
44
+ resource_name: 'PixBalance',
45
+ resource_maker: proc { |json|
46
+ PixBalance.new(
47
+ amount: json['amount'],
48
+ currency: json['currency'],
49
+ updated: json['updated'],
50
+ id: json['id'],
51
+ )
52
+ }
53
+ }
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('pixrequest')
7
+
8
+ module StarkInfra
9
+ class PixRequest
10
+ # # PixRequest::Log object
11
+ #
12
+ # Every time a PixRequest entity is modified, a corresponding PixRequest::Log
13
+ # is generated for the entity. This log is never generated by the
14
+ # user.
15
+ #
16
+ # ## Attributes:
17
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
+ # - type [string]: type of the PixRequest event which triggered the log creation. ex: 'processing' or 'success'
20
+ # - errors [list of strings]: list of errors linked to this PixRequest event.
21
+ # - request [PixRequest]: PixRequest entity to which the log refers to.
22
+ class Log < StarkInfra::Utils::Resource
23
+ attr_reader :id, :created, :type, :errors, :request
24
+ def initialize(id:, created:, type:, errors:, request:)
25
+ super(id)
26
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
27
+ @type = type
28
+ @errors = errors
29
+ @request = request
30
+ end
31
+
32
+ # # Retrieve a specific Log
33
+ #
34
+ # Receive a single Log object previously created by the Stark Infra API by passing its id
35
+ #
36
+ # ## Parameters (required):
37
+ # - id [string]: object unique id. ex: '5656565656565656'
38
+ #
39
+ # ## Parameters (optional):
40
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
41
+ #
42
+ # ## Return:
43
+ # - Log object with updated attributes
44
+ def self.get(id, user: nil)
45
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
46
+ end
47
+
48
+ # # Retrieve Logs
49
+ #
50
+ # Receive a generator of Log objects previously created in the Stark Infra API
51
+ #
52
+ # ## Parameters (optional):
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)
56
+ # - types [list of strings, default nil]: filter retrieved objects by types. ex: 'success' or 'failed'
57
+ # - request_ids [list of strings, default nil]: list of PixRequest 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
59
+ #
60
+ # ## Return:
61
+ # - list of Log objects with updated attributes
62
+ def self.query(limit: nil, after: nil, before: nil, types: nil, request_ids: nil, user: nil)
63
+ after = StarkInfra::Utils::Checks.check_date(after)
64
+ before = StarkInfra::Utils::Checks.check_date(before)
65
+ StarkInfra::Utils::Rest.get_stream(
66
+ limit: limit,
67
+ after: after,
68
+ before: before,
69
+ types: types,
70
+ request_ids: request_ids,
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 Infra 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 types. ex: 'success' or 'failed'
87
+ # - request_ids [list of strings, default nil]: list of PixRequest 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
89
+ #
90
+ # ## Return:
91
+ # - list of Log objects with updated attributes
92
+ # - Cursor to retrieve the next page of Log objects
93
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, request_ids: nil, user: nil)
94
+ after = StarkInfra::Utils::Checks.check_date(after)
95
+ before = StarkInfra::Utils::Checks.check_date(before)
96
+ return StarkInfra::Utils::Rest.get_page(
97
+ cursor: cursor,
98
+ limit: limit,
99
+ after: after,
100
+ before: before,
101
+ types: types,
102
+ request_ids: request_ids,
103
+ user: user,
104
+ **resource
105
+ )
106
+ end
107
+
108
+ def self.resource
109
+ request_maker = StarkInfra::PixRequest.resource[:resource_maker]
110
+ {
111
+ resource_name: 'PixRequestLog',
112
+ resource_maker: proc { |json|
113
+ Log.new(
114
+ id: json['id'],
115
+ created: json['created'],
116
+ type: json['type'],
117
+ errors: json['errors'],
118
+ request: StarkInfra::Utils::API.from_api_json(request_maker, json['request'])
119
+ )
120
+ }
121
+ }
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,259 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/parse')
7
+
8
+ module StarkInfra
9
+ # # PixRequest object
10
+ #
11
+ # When you initialize a PixRequest, the entity will not be automatically
12
+ # created in the Stark Infra API. The 'create' function sends the objects
13
+ # to the Stark Infra API and returns the list of created objects.
14
+ #
15
+ # ## Parameters (required):
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"
30
+ #
31
+ # ## Parameters (optional):
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"
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"
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".
41
+ #
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
+
51
+ 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
53
+ def initialize(
54
+ amount:, external_id:, sender_name:, sender_tax_id:, sender_branch_code:, sender_account_number:,
55
+ sender_account_type:, receiver_name:, receiver_tax_id:, receiver_bank_code:, receiver_account_number:,
56
+ receiver_branch_code:, receiver_account_type:, end_to_end_id:, receiver_key_id: nil, description: nil,
57
+ reconciliation_id: nil, initiator_tax_id: nil, cash_amount: nil, cashier_bank_code: nil, cashier_type: nil,
58
+ tags: nil, id: nil, fee: nil, status:nil, flow: nil, method: nil, sender_bank_code: nil, created: nil, updated: nil
59
+ )
60
+ super(id)
61
+ @amount = amount
62
+ @external_id = external_id
63
+ @sender_name = sender_name
64
+ @sender_tax_id = sender_tax_id
65
+ @sender_branch_code = sender_branch_code
66
+ @sender_account_number = sender_account_number
67
+ @sender_account_type = sender_account_type
68
+ @receiver_name = receiver_name
69
+ @receiver_tax_id = receiver_tax_id
70
+ @receiver_bank_code = receiver_bank_code
71
+ @receiver_account_number = receiver_account_number
72
+ @receiver_branch_code = receiver_branch_code
73
+ @receiver_account_type = receiver_account_type
74
+ @end_to_end_id = end_to_end_id
75
+ @receiver_key_id = receiver_key_id
76
+ @description = description
77
+ @reconciliation_id = reconciliation_id
78
+ @initiator_tax_id = initiator_tax_id
79
+ @cash_amount = cash_amount
80
+ @cashier_bank_code = cashier_bank_code
81
+ @cashier_type = cashier_type
82
+ @tags = tags
83
+ @method = method
84
+ @fee = fee
85
+ @status = status
86
+ @flow = flow
87
+ @sender_bank_code = sender_bank_code
88
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
89
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
90
+ end
91
+
92
+ # # Create PixRequests
93
+ #
94
+ # Send a list of PixRequest objects for creation in the Stark Infra API
95
+ #
96
+ # ## Parameters (required):
97
+ # - requests [list of PixRequest objects]: list of PixRequest objects to be created in the API
98
+ #
99
+ # ## Parameters (optional):
100
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
101
+ #
102
+ # ## Return:
103
+ # - list of PixRequest objects with updated attributes
104
+ def self.create(requests, user: nil)
105
+ StarkInfra::Utils::Rest.post(entities: requests, user: user, **resource)
106
+ end
107
+
108
+ # # Retrieve a specific PixRequest
109
+ #
110
+ # Receive a single PixRequest object previously created in the Stark Infra API by passing its id
111
+ #
112
+ # ## Parameters (required):
113
+ # - id [string]: object unique id. ex: '5656565656565656'
114
+ #
115
+ # ## Parameters (optional):
116
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
117
+ #
118
+ # ## Return:
119
+ # - PixRequest object with updated attributes
120
+ def self.get(id, user: nil)
121
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
122
+ end
123
+
124
+ # # Retrieve PixRequests
125
+ #
126
+ # Receive a generator of PixRequest objects previously created in the Stark Infra API
127
+ #
128
+ # ## Parameters (optional):
129
+ # - 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
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
134
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
135
+ # - 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
139
+ #
140
+ # ## Return:
141
+ # - 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)
143
+ after = StarkInfra::Utils::Checks.check_date(after)
144
+ before = StarkInfra::Utils::Checks.check_date(before)
145
+ StarkInfra::Utils::Rest.get_stream(
146
+ fields: fields,
147
+ limit: limit,
148
+ after: after,
149
+ before: before,
150
+ status: status,
151
+ tags: tags,
152
+ ids: ids,
153
+ end_to_end_ids: end_to_end_ids,
154
+ external_ids: external_ids,
155
+ user: user,
156
+ **resource
157
+ )
158
+ end
159
+
160
+ # # Retrieve paged PixRequests
161
+ #
162
+ # Receive a list of up to 100 PixRequest objects previously created in the Stark infra API and the cursor to the next page.
163
+ # Use this function instead of query if you want to manually page your requests.
164
+ #
165
+ # ## Parameters (optional):
166
+ # - 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)
171
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
172
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
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
177
+ #
178
+ # ## Return:
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)
182
+ after = StarkInfra::Utils::Checks.check_date(after)
183
+ before = StarkInfra::Utils::Checks.check_date(before)
184
+ return StarkInfra::Utils::Rest.get_page(
185
+ cursor: cursor,
186
+ fields: fields,
187
+ limit: limit,
188
+ after: after,
189
+ before: before,
190
+ status: status,
191
+ tags: tags,
192
+ ids: ids,
193
+ end_to_end_ids: end_to_end_ids,
194
+ external_ids: external_ids,
195
+ user: user,
196
+ **resource
197
+ )
198
+ end
199
+
200
+ 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
218
+
219
+ def self.resource
220
+ {
221
+ resource_name: 'PixRequest',
222
+ resource_maker: proc { |json|
223
+ PixRequest.new(
224
+ id: json['id'],
225
+ amount: json['amount'],
226
+ external_id: json['external_id'],
227
+ sender_name: json['sender_name'],
228
+ sender_tax_id: json['sender_tax_id'],
229
+ sender_branch_code: json['sender_branch_code'],
230
+ sender_account_number: json['sender_account_number'],
231
+ sender_account_type: json['sender_account_type'],
232
+ receiver_name: json['receiver_name'],
233
+ receiver_tax_id: json['receiver_tax_id'],
234
+ receiver_bank_code: json['receiver_bank_code'],
235
+ receiver_account_number: json['receiver_account_number'],
236
+ receiver_branch_code: json['receiver_branch_code'],
237
+ receiver_account_type: json['receiver_account_type'],
238
+ end_to_end_id: json['end_to_end_id'],
239
+ receiver_key_id: json['receiver_key_id'],
240
+ description: json['description'],
241
+ reconciliation_id: json['reconciliation_id'],
242
+ initiator_tax_id: json['initiator_tax_id'],
243
+ cash_amount: json['cash_amount'],
244
+ cashier_bank_code: json['cashier_bank_code'],
245
+ cashier_type: json['cashier_type'],
246
+ tags: json['tags'],
247
+ fee: json['fee'],
248
+ status: json['status'],
249
+ flow: json['flow'],
250
+ method: json['method'],
251
+ sender_bank_code: json['sender_bank_code'],
252
+ created: json['created'],
253
+ updated: json['updated'],
254
+ )
255
+ }
256
+ }
257
+ end
258
+ end
259
+ end