starkbank 2.1.0.beta1 → 2.2.1

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.
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('deposit')
7
+
8
+ module StarkBank
9
+ class Deposit
10
+ # # Deposit::Log object
11
+ #
12
+ # Every time a Deposit entity is updated, a corresponding Deposit::Log
13
+ # is generated for the entity. This log is never generated by the
14
+ # user, but it can be retrieved to check additional information
15
+ # on the Deposit.
16
+ #
17
+ # ## Attributes:
18
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
19
+ # - deposit [Deposit]: Deposit entity to which the log refers to.
20
+ # - errors [list of strings]: list of errors linked to this Deposit event
21
+ # - type [string]: type of the Deposit event which triggered the log creation. ex: 'canceled' or 'paid'
22
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
23
+ class Log < StarkBank::Utils::Resource
24
+ attr_reader :id, :created, :type, :errors, :deposit
25
+ def initialize(id:, created:, type:, errors:, deposit:)
26
+ super(id)
27
+ @type = type
28
+ @errors = errors
29
+ @deposit = deposit
30
+ @created = StarkBank::Utils::Checks.check_datetime(created)
31
+ end
32
+
33
+ # # Retrieve a specific Log
34
+ #
35
+ # Receive a single Log object previously created by the Stark Bank API by passing its id
36
+ #
37
+ # ## Parameters (required):
38
+ # - id [string]: object unique id. ex: '5656565656565656'
39
+ #
40
+ # ## Parameters (optional):
41
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
42
+ #
43
+ # ## Return:
44
+ # - Log object with updated attributes
45
+ def self.get(id, user: nil)
46
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
47
+ end
48
+
49
+ # # Retrieve Logs
50
+ #
51
+ # Receive a generator of Log objects previously created in the Stark Bank API
52
+ #
53
+ # ## Parameters (optional):
54
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
+ # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
57
+ # - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
58
+ # - deposit_ids [list of strings, default nil]: list of Deposit ids to filter logs. ex: ['5656565656565656', '4545454545454545']
59
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
60
+ #
61
+ # ## Return:
62
+ # - list of Log objects with updated attributes
63
+ def self.query(limit: nil, after: nil, before: nil, types: nil, deposit_ids: nil, user: nil)
64
+ after = StarkBank::Utils::Checks.check_date(after)
65
+ before = StarkBank::Utils::Checks.check_date(before)
66
+ StarkBank::Utils::Rest.get_list(
67
+ limit: limit,
68
+ after: after,
69
+ before: before,
70
+ types: types,
71
+ deposit_ids: deposit_ids,
72
+ user: user,
73
+ **resource
74
+ )
75
+ end
76
+
77
+ def self.resource
78
+ deposit_maker = StarkBank::Deposit.resource[:resource_maker]
79
+ {
80
+ resource_name: 'DepositLog',
81
+ resource_maker: proc { |json|
82
+ Log.new(
83
+ id: json['id'],
84
+ created: json['created'],
85
+ type: json['type'],
86
+ errors: json['errors'],
87
+ deposit: StarkBank::Utils::API.from_api_json(deposit_maker, json['deposit'])
88
+ )
89
+ }
90
+ }
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource.rb')
4
+ require_relative('../utils/rest.rb')
5
+ require_relative('../utils/checks.rb')
6
+
7
+ module StarkBank
8
+ # # DictKey object
9
+ #
10
+ # DictKey represents a PIX key registered in Bacen's DICT system.
11
+ #
12
+ # ## Parameters (required):
13
+ # - id [string]: DictKey object unique id and PIX key itself. ex: 'tony@starkbank.com', '722.461.430-04', '20.018.183/0001-80', '+5511988887777', 'b6295ee1-f054-47d1-9e90-ee57b74f60d9'
14
+ #
15
+ # ## Attributes (return-only):
16
+ # - type [string, default nil]: DICT key type. ex: 'email', 'cpf', 'cnpj', 'phone' or 'evp'
17
+ # - name [string, default nil]: account owner full name. ex: 'Tony Stark'
18
+ # - tax_id [string, default nil]: key owner tax ID (CNPJ or masked CPF). ex: '***.345.678-**' or '20.018.183/0001-80'
19
+ # - owner_type [string, default nil]: DICT key owner type. ex 'naturalPerson' or 'legalPerson'
20
+ # - ispb [string, default nil]: bank ISPB associated with the DICT key. ex: '20018183'
21
+ # - branch_code [string, default nil]: bank account branch code associated with the DICT key. ex: '9585'
22
+ # - account_number [string, default nil]: bank account number associated with the DICT key. ex: '9828282578010513'
23
+ # - account_type [string, default nil]: bank account type associated with the DICT key. ex: 'checking', 'saving' e 'salary'
24
+ # - status [string, default nil]: current DICT key status. ex: 'created', 'registered', 'canceled' or 'failed'
25
+ # - account_created [DateTime or string, default nil]: creation datetime of the bank account associated with the DICT key. ex: '2020-11-05T14:55:08.812665+00:00'
26
+ # - owned [DateTime or string, default nil]: datetime since when the current owner hold this DICT key. ex : '2020-11-05T14:55:08.812665+00:00'
27
+ # - created [DateTime or string, default nil]: creation datetime for the DICT key. ex: '2020-03-10 10:30:00.000'
28
+ class DictKey < StarkBank::Utils::Resource
29
+ attr_reader :id, :type, :name, :tax_id, :owner_type, :ispb, :branch_code, :account_number, :account_type, :status, :account_created, :owned, :created
30
+ def initialize(
31
+ id:, type:, name:, tax_id:, owner_type:, ispb:, branch_code:, account_number:, account_type:,
32
+ status:, account_created:, owned:, created:
33
+ )
34
+ super(id)
35
+ @type = type
36
+ @name = name
37
+ @tax_id = tax_id
38
+ @owner_type = owner_type
39
+ @ispb = ispb
40
+ @branch_code = branch_code
41
+ @account_number = account_number
42
+ @account_type = account_type
43
+ @status = status
44
+ @account_created = StarkBank::Utils::Checks.check_datetime(account_created)
45
+ @owned = StarkBank::Utils::Checks.check_datetime(owned)
46
+ @created = StarkBank::Utils::Checks.check_datetime(created)
47
+ end
48
+
49
+ # # Retrieve a specific DictKey
50
+ #
51
+ # Receive a single DictKey object by passing its id
52
+ #
53
+ # ## Parameters (required):
54
+ # - id [string]: DictKey object unique id and PIX key itself. ex: 'tony@starkbank.com', '722.461.430-04', '20.018.183/0001-80', '+5511988887777', 'b6295ee1-f054-47d1-9e90-ee57b74f60d9'
55
+ #
56
+ # ## Parameters (optional):
57
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
58
+ #
59
+ # ## Return:
60
+ # - DictKey object with updated attributes
61
+ def self.get(id, user: nil)
62
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
63
+ end
64
+
65
+ # # Retrieve DitcKeys
66
+ #
67
+ # Receive a generator of DitcKey objects previously created in the Stark Bank API
68
+ #
69
+ # ## Parameters (optional):
70
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
71
+ # - type [string, default nil]: DictKey type. ex: 'cpf', 'cnpj', 'phone', 'email' or 'evp'
72
+ # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
73
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
74
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
75
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'canceled', 'registered'
76
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
77
+ #
78
+ # ## Return:
79
+ # - generator of DitcKey objects with updated attributes
80
+ def self.query(limit: nil, type: nil, after: nil, before: nil, ids: nil, status: nil, user: nil)
81
+ after = StarkBank::Utils::Checks.check_date(after)
82
+ before = StarkBank::Utils::Checks.check_date(before)
83
+ StarkBank::Utils::Rest.get_list(
84
+ limit: limit,
85
+ type: type,
86
+ after: after,
87
+ before: before,
88
+ ids: ids,
89
+ status: status,
90
+ user: user,
91
+ **resource
92
+ )
93
+ end
94
+
95
+ def self.resource
96
+ {
97
+ resource_name: 'DictKey',
98
+ resource_maker: proc { |json|
99
+ DictKey.new(
100
+ id: json['id'],
101
+ account_type: json['account_type'],
102
+ name: json['name'],
103
+ tax_id: json['tax_id'],
104
+ owner_type: json['owner_type'],
105
+ ispb: json['ispb'],
106
+ branch_code: json['branch_code'],
107
+ account_number: json['account_number'],
108
+ type: json['type'],
109
+ status: json['status'],
110
+ account_created: json['account_created'],
111
+ owned: json['owned'],
112
+ created: json['created']
113
+ )
114
+ }
115
+ }
116
+ end
117
+ end
118
+ end
@@ -9,6 +9,9 @@ require_relative('../utils/cache')
9
9
  require_relative('../error')
10
10
  require_relative('../boleto/log')
11
11
  require_relative('../boleto_holmes/log')
12
+ require_relative('../invoice/log')
13
+ require_relative('../deposit/log')
14
+ require_relative('../brcode_payment/log')
12
15
  require_relative('../transfer/log')
13
16
  require_relative('../boleto_payment/log')
14
17
  require_relative('../utility_payment/log')
@@ -22,7 +25,7 @@ module StarkBank
22
25
  #
23
26
  # ## Attributes:
24
27
  # - id [string]: unique id returned when the event is created. ex: '5656565656565656'
25
- # - log [Log]: a Log object from one the subscription services (TransferLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
28
+ # - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
26
29
  # - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
27
30
  # - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
28
31
  # - subscription [string]: service that triggered this event. ex: 'transfer', 'utility-payment'
@@ -36,6 +39,9 @@ module StarkBank
36
39
 
37
40
  resource = {
38
41
  'transfer': StarkBank::Transfer::Log.resource,
42
+ 'invoice': StarkBank::Invoice::Log.resource,
43
+ 'deposit': StarkBank::Deposit::Log.resource,
44
+ 'brcode-payment': StarkBank::BrcodePayment::Log.resource,
39
45
  'boleto': StarkBank::Boleto::Log.resource,
40
46
  'boleto-payment': StarkBank::BoletoPayment::Log.resource,
41
47
  'utility-payment': StarkBank::UtilityPayment::Log.resource,
@@ -0,0 +1,211 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ # # Invoice object
9
+ #
10
+ # When you initialize an Invoice, the entity will not be automatically
11
+ # sent to the Stark Bank API. The 'create' function sends the objects
12
+ # to the Stark Bank API and returns the list of created objects.
13
+ #
14
+ # ## Parameters (required):
15
+ # - amount [integer]: Invoice value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34)
16
+ # - tax_id [string]: payer tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
17
+ # - name [string]: payer name. ex: 'Iron Bank S.A.'
18
+ #
19
+ # ## Parameters (optional):
20
+ # - due [DateTime or string, default now + 2 days]: Invoice due date in UTC ISO format. ex: '2020-10-28T17:59:26.249976+00:00'
21
+ # - expiration [integer, default 5097600 (59 days)]: time interval in seconds between due date and expiration date. ex 123456789
22
+ # - fine [float, default 0.0]: Invoice fine for overdue payment in %. ex: 2.5
23
+ # - interest [float, default 0.0]: Invoice monthly interest for overdue payment in %. ex: 5.2
24
+ # - discounts [list of hashes, default nil]: list of hashes with 'percentage':float and 'due':DateTime or string pairs
25
+ # - descriptions [list of hashes, default nil]: list of hashes with 'key':string and 'value':string pairs
26
+ # - tags [list of strings, default nil]: list of strings for tagging
27
+ #
28
+ # ## Attributes (return-only):
29
+ # - id [string, default nil]: unique id returned when Invoice is created. ex: '5656565656565656'
30
+ # - nominal_amount [integer, default nil]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
31
+ # - fine_amount [integer, default nil]: Invoice fine value calculated over nominal_amount. ex: 20000
32
+ # - interest_amount [integer, default nil]: Invoice interest value calculated over nominal_amount. ex: 10000
33
+ # - discount_amount [integer, default nil]: Invoice discount value calculated over nominal_amount. ex: 3000
34
+ # - brcode [string, default nil]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
35
+ # - fee [integer, default nil]: fee charged by the Invoice. ex: 65 (= R$ 0.65)
36
+ # - status [string, default nil]: current Invoice status. ex: 'registered' or 'paid'
37
+ # - created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
38
+ # - updated [DateTime, default nil]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
39
+ class Invoice < StarkBank::Utils::Resource
40
+ attr_reader :amount, :tax_id, :name, :due, :expiration, :fine, :interest, :discounts, :tags, :descriptions, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :id, :brcode, :fee, :status, :created, :updated
41
+ def initialize(
42
+ amount:, tax_id:, name:, due: nil, expiration: nil, fine: nil, interest: nil, discounts: nil,
43
+ tags: nil, descriptions: nil, nominal_amount: nil, fine_amount: nil, interest_amount: nil,
44
+ discount_amount: nil, id: nil, brcode: nil, fee: nil, status: nil, created: nil, updated: nil
45
+ )
46
+ super(id)
47
+ @amount = amount
48
+ @due = StarkBank::Utils::Checks.check_datetime(due)
49
+ @tax_id = tax_id
50
+ @name = name
51
+ @expiration = expiration
52
+ @fine = fine
53
+ @interest = interest
54
+ @discounts = discounts
55
+ @tags = tags
56
+ @descriptions = descriptions
57
+ @nominal_amount = nominal_amount
58
+ @fine_amount = fine_amount
59
+ @interest_amount = interest_amount
60
+ @discount_amount = discount_amount
61
+ @brcode = brcode
62
+ @fee = fee
63
+ @status = status
64
+ @updated = StarkBank::Utils::Checks.check_datetime(updated)
65
+ @created = StarkBank::Utils::Checks.check_datetime(created)
66
+ end
67
+
68
+ # # Create Invoices
69
+ #
70
+ # Send a list of Invoice objects for creation in the Stark Bank API
71
+ #
72
+ # ## Parameters (required):
73
+ # - invoices [list of Invoice objects]: list of Invoice objects to be created in the API
74
+ #
75
+ # ## Parameters (optional):
76
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
77
+ #
78
+ # ## Return:
79
+ # - list of Invoice objects with updated attributes
80
+ def self.create(invoices, user: nil)
81
+ StarkBank::Utils::Rest.post(entities: invoices, user: user, **resource)
82
+ end
83
+
84
+ # # Retrieve a specific Invoice
85
+ #
86
+ # Receive a single Invoice object previously created in the Stark Bank API by passing its id
87
+ #
88
+ # ## Parameters (required):
89
+ # - id [string]: object unique id. ex: '5656565656565656'
90
+ #
91
+ # ## Parameters (optional):
92
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
93
+ #
94
+ # ## Return:
95
+ # - Invoice object with updated attributes
96
+ def self.get(id, user: nil)
97
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
98
+ end
99
+
100
+ # # Retrieve a specific Invoice pdf file
101
+ #
102
+ # Receive a single Invoice pdf file generated in the Stark Bank API by passing its id.
103
+ #
104
+ # ## Parameters (required):
105
+ # - id [string]: object unique id. ex: '5656565656565656'
106
+ #
107
+ # ## Parameters (optional):
108
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
109
+ #
110
+ # ## Return:
111
+ # - Invoice pdf file
112
+ def self.pdf(id, user: nil)
113
+ StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
114
+ end
115
+
116
+ # # Retrieve a specific Invoice QR Code file
117
+ #
118
+ # Receive a single Invoice QR Code png file generated in the Stark Bank API by passing its id.
119
+ #
120
+ # ## Parameters (required):
121
+ # - id [string]: object unique id. ex: '5656565656565656'
122
+ #
123
+ # ## Parameters (optional):
124
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
125
+ #
126
+ # ## Return:
127
+ # - Invoice QR Code png blob
128
+ def self.qrcode(id, user: nil)
129
+ StarkBank::Utils::Rest.get_qrcode(id: id, user: user, **resource)
130
+ end
131
+
132
+ # # Retrieve Invoices
133
+ #
134
+ # Receive a generator of Invoice objects previously created in the Stark Bank API
135
+ #
136
+ # ## Parameters (optional):
137
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
138
+ # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
139
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
140
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
141
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
142
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
143
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
144
+ #
145
+ # ## Return:
146
+ # - generator of Invoice objects with updated attributes
147
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
148
+ after = StarkBank::Utils::Checks.check_date(after)
149
+ before = StarkBank::Utils::Checks.check_date(before)
150
+ StarkBank::Utils::Rest.get_list(
151
+ limit: limit,
152
+ after: after,
153
+ before: before,
154
+ status: status,
155
+ tags: tags,
156
+ ids: ids,
157
+ user: user,
158
+ **resource
159
+ )
160
+ end
161
+
162
+ # # Update an Invoice entity
163
+ #
164
+ # Update an Invoice entity previously created in the Stark Bank API
165
+ #
166
+ # ## Parameters (required):
167
+ # - id [string]: Invoice unique id. ex: '5656565656565656'
168
+ #
169
+ # ## Parameters (optional):
170
+ # - status [string, nil]: You may cancel the invoice by passing 'canceled' in the status
171
+ # - amount [string, nil]: Nominal amount charged by the invoice. ex: 100 (R$1.00)
172
+ # - due [datetime.date or string, default nil]: Invoice due date in UTC ISO format. ex: DateTime.new(2020, 3, 10, 10, 30, 12, 21)
173
+ # - expiration [number, default nil]: time interval in seconds between the due date and the expiration date. ex 123456789
174
+ #
175
+ # ## Return:
176
+ # - updated Invoice object
177
+ def self.update(id, status: nil, amount: nil, due: nil, expiration: nil, user: nil)
178
+ StarkBank::Utils::Rest.patch_id(id: id, status: status, amount: amount, due: due, expiration: expiration, user: user, **resource)
179
+ end
180
+
181
+ def self.resource
182
+ {
183
+ resource_name: 'Invoice',
184
+ resource_maker: proc { |json|
185
+ Invoice.new(
186
+ id: json['id'],
187
+ amount: json['amount'],
188
+ due: json['due'],
189
+ tax_id: json['tax_id'],
190
+ name: json['name'],
191
+ expiration: json['expiration'],
192
+ fine: json['fine'],
193
+ interest: json['interest'],
194
+ discounts: json['discounts'],
195
+ tags: json['tags'],
196
+ descriptions: json['descriptions'],
197
+ nominal_amount: json['nominal_amount'],
198
+ fine_amount: json['fine_amount'],
199
+ interest_amount: json['interest_amount'],
200
+ discount_amount: json['discount_amount'],
201
+ brcode: json['brcode'],
202
+ fee: json['fee'],
203
+ status: json['status'],
204
+ updated: json['updated'],
205
+ created: json['created'],
206
+ )
207
+ }
208
+ }
209
+ end
210
+ end
211
+ end