starkbank 0.0.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,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../../utils/resource')
4
+ require_relative('../../utils/rest')
5
+ require_relative('../../utils/checks')
6
+ require_relative('boleto')
7
+
8
+ module StarkBank
9
+ class BoletoPayment
10
+ # # BoletoPayment::Log object
11
+ #
12
+ # Every time a BoletoPayment entity is modified, a corresponding BoletoPayment::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 BoletoPayment.
16
+ #
17
+ # ## Attributes:
18
+ # - id [string]: unique id returned when the log is created. ex: "5656565656565656"
19
+ # - payment [BoletoPayment]: BoletoPayment entity to which the log refers to.
20
+ # - errors [list of strings]: list of errors linked to this BoletoPayment event.
21
+ # - type [string]: type of the BoletoPayment event which triggered the log creation. ex: "registered" or "paid"
22
+ # - created [DateTime]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
23
+ class Log < StarkBank::Utils::Resource
24
+ attr_reader :id, :created, :type, :errors, :payment
25
+ def initialize(id:, created:, type:, errors:, payment:)
26
+ super(id)
27
+ @type = type
28
+ @errors = errors
29
+ @payment = payment
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
+ # - payment_ids [list of strings, default nil]: list of BoletoPayment ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
56
+ # - types [list of strings, default nil]: filter retrieved objects by event types. ex: "paid" or "registered"
57
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
58
+ #
59
+ # ## Return:
60
+ # - list of Log objects with updated attributes
61
+ def self.query(limit: nil, payment_ids: nil, types: nil, user: nil)
62
+ StarkBank::Utils::Rest.get_list(user: user, limit: limit, payment_ids: payment_ids, types: types, **resource)
63
+ end
64
+
65
+ def self.resource
66
+ payment_maker = StarkBank::BoletoPayment.resource[:resource_maker]
67
+ {
68
+ resource_name: 'BoletoPaymentLog',
69
+ resource_maker: proc { |json|
70
+ Log.new(
71
+ id: json['id'],
72
+ created: json['created'],
73
+ type: json['type'],
74
+ errors: json['errors'],
75
+ payment: StarkBank::Utils::API.from_api_json(payment_maker, json['payment'])
76
+ )
77
+ }
78
+ }
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../../utils/resource')
4
+ require_relative('../../utils/rest')
5
+ require_relative('../../utils/checks')
6
+ require_relative('utility')
7
+
8
+ module StarkBank
9
+ class UtilityPayment
10
+ # # UtilityPayment::Log object
11
+ #
12
+ # Every time a UtilityPayment entity is modified, a corresponding UtilityPayment::Log
13
+ # is generated for the entity. This log is never generated by the user, but it can
14
+ # be retrieved to check additional information on the UtilityPayment.
15
+ #
16
+ # ## Attributes:
17
+ # - id [string]: unique id returned when the log is created. ex: "5656565656565656"
18
+ # - payment [UtilityPayment]: UtilityPayment entity to which the log refers to.
19
+ # - errors [list of strings]: list of errors linked to this BoletoPayment event.
20
+ # - type [string]: type of the UtilityPayment event which triggered the log creation. ex: "registered" or "paid"
21
+ # - created [DateTime]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
+ class Log < StarkBank::Utils::Resource
23
+ attr_reader :id, :created, :type, :errors, :payment
24
+ def initialize(id:, created:, type:, errors:, payment:)
25
+ super(id)
26
+ @type = type
27
+ @errors = errors
28
+ @payment = payment
29
+ @created = StarkBank::Utils::Checks.check_datetime(created)
30
+ end
31
+
32
+ # # Retrieve a specific Log
33
+ #
34
+ # Receive a single Log object previously created by the Stark Bank API by passing its id
35
+ #
36
+ # ## Parameters (required):
37
+ # - id [string]: object unique id. ex: "5656565656565656"
38
+ #
39
+ # ## Parameters (optional):
40
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
41
+ #
42
+ # ## Return:
43
+ # - Log object with updated attributes
44
+ def self.get(id:, user: nil)
45
+ StarkBank::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 Bank API
51
+ #
52
+ # ## Parameters (optional):
53
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
54
+ # - payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
55
+ # - types [list of strings, default nil]: filter retrieved objects by event types. ex: "paid" or "registered"
56
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
57
+ #
58
+ # ## Return:
59
+ # - list of Log objects with updated attributes
60
+ def self.query(limit: nil, payment_ids: nil, types: nil, user: nil)
61
+ StarkBank::Utils::Rest.get_list(user: user, limit: limit, payment_ids: payment_ids, types: types, **resource)
62
+ end
63
+
64
+ def self.resource
65
+ payment_maker = StarkBank::UtilityPayment.resource[:resource_maker]
66
+ {
67
+ resource_name: 'UtilityPaymentLog',
68
+ resource_maker: proc { |json|
69
+ Log.new(
70
+ id: json['id'],
71
+ created: json['created'],
72
+ type: json['type'],
73
+ errors: json['errors'],
74
+ payment: StarkBank::Utils::API.from_api_json(payment_maker, json['payment'])
75
+ )
76
+ }
77
+ }
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,152 @@
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
+ # # UtilityPayment object
9
+ #
10
+ # When you initialize a UtilityPayment, the entity will not be automatically
11
+ # created in 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 (conditionally required):
15
+ # - line [string, default nil]: Number sequence that describes the payment. Either 'line' or 'bar_code' parameters are required. If both are sent, they must match. ex: "34191.09008 63571.277308 71444.640008 5 81960000000062"
16
+ # - bar_code [string, default nil]: Bar code number that describes the payment. Either 'line' or 'barCode' parameters are required. If both are sent, they must match. ex: "34195819600000000621090063571277307144464000"
17
+ #
18
+ # ## Parameters (required):
19
+ # - description [string]: Text to be displayed in your statement (min. 10 characters). ex: "payment ABC"
20
+ #
21
+ # ## Parameters (optional):
22
+ # - scheduled [Date, default today]: payment scheduled date. ex: Date.new(2020, 3, 10)
23
+ # - tags [list of strings]: list of strings for tagging
24
+ #
25
+ # ## Attributes (return-only):
26
+ # - id [string, default nil]: unique id returned when payment is created. ex: "5656565656565656"
27
+ # - status [string, default nil]: current payment status. ex: "registered" or "paid"
28
+ # - amount [int, default nil]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)
29
+ # - fee [integer, default nil]: fee charged when utility payment is created. ex: 200 (= R$ 2.00)
30
+ # - created [DateTime, default nil]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
31
+ class UtilityPayment < StarkBank::Utils::Resource
32
+ attr_reader :description, :line, :bar_code, :tags, :scheduled, :id, :amount, :fee, :status, :created
33
+ def initialize(description:, line: nil, bar_code: nil, tags: nil, scheduled: nil, id: nil, amount: nil, fee: nil, status: nil, created: nil)
34
+ super(id)
35
+ @description = description
36
+ @line = line
37
+ @bar_code = bar_code
38
+ @tags = tags
39
+ @scheduled = StarkBank::Utils::Checks.check_datetime(scheduled)
40
+ @amount = amount
41
+ @fee = fee
42
+ @status = status
43
+ @created = StarkBank::Utils::Checks.check_datetime(created)
44
+ end
45
+
46
+ # # Create UtilityPayments
47
+ #
48
+ # Send a list of UtilityPayment objects for creation in the Stark Bank API
49
+ #
50
+ # ## Parameters (required):
51
+ # - payments [list of UtilityPayment objects]: list of UtilityPayment objects to be created in the API
52
+ #
53
+ # ## Parameters (optional):
54
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
55
+ #
56
+ # ## Return:
57
+ # - list of UtilityPayment objects with updated attributes
58
+ def self.create(payments:, user: nil)
59
+ StarkBank::Utils::Rest.post(entities: payments, user: user, **resource)
60
+ end
61
+
62
+ # # Retrieve a specific UtilityPayment
63
+ #
64
+ # Receive a single UtilityPayment object previously created by the Stark Bank API by passing its id
65
+ #
66
+ # ## Parameters (required):
67
+ # - id [string]: object unique id. ex: "5656565656565656"
68
+ #
69
+ # ## Parameters (optional):
70
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
71
+ #
72
+ # ## Return:
73
+ # - UtilityPayment object with updated attributes
74
+ def self.get(id:, user: nil)
75
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
76
+ end
77
+
78
+ # # Retrieve a specific UtilityPayment pdf file
79
+ #
80
+ # Receive a single UtilityPayment pdf file generated in the Stark Bank API by passing its id.
81
+ # Only valid for utility payments with "success" status.
82
+ #
83
+ # ## Parameters (required):
84
+ # - id [string]: object unique id. ex: "5656565656565656"
85
+ #
86
+ # ## Parameters (optional):
87
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
88
+ #
89
+ # ## Return:
90
+ # - UtilityPayment pdf file
91
+ def self.pdf(id:, user: nil)
92
+ StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
93
+ end
94
+
95
+ # # Retrieve UtilityPayments
96
+ #
97
+ # Receive a generator of UtilityPayment objects previously created in the Stark Bank API
98
+ #
99
+ # ## Parameters (optional):
100
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
101
+ # - status [string, default nil]: filter for status of retrieved objects. ex: "paid"
102
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"]
103
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
104
+ # - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
105
+ # - before [Date, default nil] date filter for objects only before specified date. ex: Date.new(2020, 3, 10)
106
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
107
+ #
108
+ # ## Return:
109
+ # - generator of UtilityPayment objects with updated attributes
110
+ def self.query(limit: nil, status: nil, tags: nil, ids: nil, after: nil, before: nil, user: nil)
111
+ after = StarkBank::Utils::Checks.check_date(after)
112
+ before = StarkBank::Utils::Checks.check_date(before)
113
+ StarkBank::Utils::Rest.get_list(user: user, limit: limit, status: status, tags: tags, ids: ids, after: after, before: before, **resource)
114
+ end
115
+
116
+ # # Delete a UtilityPayment entity
117
+ #
118
+ # Delete a UtilityPayment entity previously created in the Stark Bank API
119
+ #
120
+ # ## Parameters (required):
121
+ # - id [string]: UtilityPayment 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
+ # - deleted UtilityPayment with updated attributes
128
+ def self.delete(id:, user: nil)
129
+ StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
130
+ end
131
+
132
+ def self.resource
133
+ {
134
+ resource_name: 'UtilityPayment',
135
+ resource_maker: proc { |json|
136
+ UtilityPayment.new(
137
+ id: json['id'],
138
+ description: json['description'],
139
+ line: json['line'],
140
+ bar_code: json['bar_code'],
141
+ tags: json['tags'],
142
+ scheduled: json['scheduled'],
143
+ amount: json['amount'],
144
+ fee: json['fee'],
145
+ status: json['status'],
146
+ created: json['created']
147
+ )
148
+ }
149
+ }
150
+ end
151
+ end
152
+ end
data/lib/starkbank.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('key')
4
+ require_relative('user/project')
5
+ require_relative('ledger/balance')
6
+ require_relative('ledger/transaction')
7
+ require_relative('boleto/boleto')
8
+ require_relative('boleto/log')
9
+ require_relative('transfer/transfer')
10
+ require_relative('transfer/log')
11
+ require_relative('payment/boleto/boleto')
12
+ require_relative('payment/boleto/log')
13
+ require_relative('payment/utility/utility')
14
+ require_relative('payment/utility/log')
15
+ require_relative('webhook/webhook')
16
+ require_relative('webhook/event')
17
+
18
+ # SDK to facilitate Ruby integrations with Stark Bank
19
+ module StarkBank
20
+ @user = nil
21
+ class << self; attr_accessor :user; end
22
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('transfer')
7
+
8
+ module StarkBank
9
+ class Transfer
10
+ # # Transfer::Log object
11
+ #
12
+ # Every time a Transfer entity is modified, a corresponding Transfer::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
+ # - transfer [Transfer]: Transfer entity to which the log refers to.
19
+ # - errors [list of strings]: list of errors linked to this BoletoPayment event.
20
+ # - type [string]: type of the Transfer event which triggered the log creation. ex: "processing" or "success"
21
+ # - created [DateTime]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
+ class Log < StarkBank::Utils::Resource
23
+ attr_reader :id, :created, :type, :errors, :transfer
24
+ def initialize(id:, created:, type:, errors:, transfer:)
25
+ super(id)
26
+ @type = type
27
+ @errors = errors
28
+ @transfer = transfer
29
+ @created = StarkBank::Utils::Checks.check_datetime(created)
30
+ end
31
+
32
+ # # Retrieve a specific Log
33
+ #
34
+ # Receive a single Log object previously created by the Stark Bank API by passing its id
35
+ #
36
+ # ## Parameters (required):
37
+ # - id [string]: object unique id. ex: "5656565656565656"
38
+ #
39
+ # ## Parameters (optional):
40
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
41
+ #
42
+ # ## Return:
43
+ # - Log object with updated attributes
44
+ def self.get(id:, user: nil)
45
+ StarkBank::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 Bank API
51
+ #
52
+ # ## Parameters (optional):
53
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
54
+ # - transfer_ids [list of strings, default nil]: list of Transfer ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
55
+ # - types [list of strings, default nil]: filter retrieved objects by types. ex: "success" or "failed"
56
+ # - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
57
+ # - before [Date, default nil] date filter for objects only before specified date. ex: Date.new(2020, 3, 10)
58
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
59
+ #
60
+ # ## Return:
61
+ # - list of Log objects with updated attributes
62
+ def self.query(limit: nil, transfer_ids: nil, types: nil, after: nil, before: nil, user: nil)
63
+ after = StarkBank::Utils::Checks.check_date(after)
64
+ before = StarkBank::Utils::Checks.check_date(before)
65
+ StarkBank::Utils::Rest.get_list(user: user, limit: limit, transfer_ids: transfer_ids, types: types, after: after, before: before, **resource)
66
+ end
67
+
68
+ def self.resource
69
+ transfer_maker = StarkBank::Transfer.resource[:resource_maker]
70
+ {
71
+ resource_name: 'TransferLog',
72
+ resource_maker: proc { |json|
73
+ Log.new(
74
+ id: json['id'],
75
+ created: json['created'],
76
+ type: json['type'],
77
+ errors: json['errors'],
78
+ transfer: StarkBank::Utils::API.from_api_json(transfer_maker, json['transfer'])
79
+ )
80
+ }
81
+ }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,143 @@
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
+ # # Transfer object
9
+ #
10
+ # When you initialize a Transfer, the entity will not be automatically
11
+ # created in 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]: amount in cents to be transferred. ex: 1234 (= R$ 12.34)
16
+ # - name [string]: receiver full name. ex: "Anthony Edward Stark"
17
+ # - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80"
18
+ # - bank_code [string]: receiver 1 to 3 digits of the bank institution in Brazil. ex: "200" or "341"
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"
21
+ #
22
+ # ## Parameters (optional):
23
+ # - tags [list of strings]: list of strings for reference when searching for transfers. ex: ["employees", "monthly"]
24
+ #
25
+ # ## Attributes (return-only):
26
+ # - id [string, default nil]: unique id returned when Transfer is created. ex: "5656565656565656"
27
+ # - fee [integer, default nil]: fee charged when transfer is created. ex: 200 (= R$ 2.00)
28
+ # - status [string, default nil]: current boleto status. ex: "registered" or "paid"
29
+ # - transaction_ids [list of strings, default nil]: ledger transaction ids linked to this transfer (if there are two, second is the chargeback). ex: ["19827356981273"]
30
+ # - created [DateTime, default nil]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
31
+ # - updated [DateTime, default nil]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
+ class Transfer < StarkBank::Utils::Resource
33
+ attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
34
+ def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
35
+ super(id)
36
+ @amount = amount
37
+ @name = name
38
+ @tax_id = tax_id
39
+ @bank_code = bank_code
40
+ @branch_code = branch_code
41
+ @account_number = account_number
42
+ @transaction_ids = transaction_ids
43
+ @fee = fee
44
+ @tags = tags
45
+ @status = status
46
+ @created = StarkBank::Utils::Checks.check_datetime(created)
47
+ @updated = StarkBank::Utils::Checks.check_datetime(updated)
48
+ end
49
+
50
+ # # Create Transfers
51
+ #
52
+ # Send a list of Transfer objects for creation in the Stark Bank API
53
+ #
54
+ # ## Parameters (required):
55
+ # - transfers [list of Transfer objects]: list of Transfer objects to be created in the API
56
+ #
57
+ # ## Parameters (optional):
58
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
59
+ #
60
+ # ## Return:
61
+ # - list of Transfer objects with updated attributes
62
+ def self.create(transfers:, user: nil)
63
+ StarkBank::Utils::Rest.post(entities: transfers, user: user, **resource)
64
+ end
65
+
66
+ # # Retrieve a specific Transfer
67
+ #
68
+ # Receive a single Transfer object previously created in the Stark Bank API by passing its id
69
+ #
70
+ # ## Parameters (required):
71
+ # - id [string]: object unique id. ex: "5656565656565656"
72
+ #
73
+ # ## Parameters (optional):
74
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
75
+ #
76
+ # ## Return:
77
+ # - Transfer object with updated attributes
78
+ def self.get(id:, user: nil)
79
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
80
+ end
81
+
82
+ # # Retrieve a specific Transfer pdf file
83
+ #
84
+ # Receive a single Transfer pdf receipt file generated in the Stark Bank API by passing its id.
85
+ # Only valid for transfers with "processing" and "success" status.
86
+ #
87
+ # ## Parameters (required):
88
+ # - id [string]: object unique id. ex: "5656565656565656"
89
+ #
90
+ # ## Parameters (optional):
91
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
92
+ #
93
+ # ## Return:
94
+ # - Transfer pdf file
95
+ def self.pdf(id:, user: nil)
96
+ StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
97
+ end
98
+
99
+ # # Retrieve Transfers
100
+ #
101
+ # Receive a generator of Transfer objects previously created in the Stark Bank API
102
+ #
103
+ # ## Parameters (optional):
104
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
105
+ # - status [string, default nil]: filter for status of retrieved objects. ex: "paid" or "registered"
106
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"]
107
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
108
+ # - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
109
+ # - before [Date, default nil] date filter for objects only before specified date. ex: Date.new(2020, 3, 10)
110
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
111
+ #
112
+ # ## Return:
113
+ # - generator of Transfer objects with updated attributes
114
+ def self.query(limit: nil, status: nil, tags: nil, transaction_ids: nil, sort: nil, after: nil, before: nil, user: nil)
115
+ after = StarkBank::Utils::Checks.check_date(after)
116
+ before = StarkBank::Utils::Checks.check_date(before)
117
+ StarkBank::Utils::Rest.get_list(user: user, limit: limit, status: status, tags: tags, transaction_ids: transaction_ids, sort: sort, after: after, before: before, **resource)
118
+ end
119
+
120
+ def self.resource
121
+ {
122
+ resource_name: 'Transfer',
123
+ resource_maker: proc { |json|
124
+ Transfer.new(
125
+ id: json['id'],
126
+ amount: json['amount'],
127
+ name: json['name'],
128
+ tax_id: json['tax_id'],
129
+ bank_code: json['bank_code'],
130
+ branch_code: json['branch_code'],
131
+ account_number: json['account_number'],
132
+ transaction_ids: json['transaction_ids'],
133
+ fee: json['fee'],
134
+ tags: json['tags'],
135
+ status: json['status'],
136
+ created: json['created'],
137
+ updated: json['updated']
138
+ )
139
+ }
140
+ }
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('user')
4
+
5
+ module StarkBank
6
+ # # Project object
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,
10
+ # 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
13
+ # each request or may be defined as the default user at the start (See README).
14
+ #
15
+ # ## Parameters (required):
16
+ # - 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
+ # - environment [string]: environment where the project is being used. ex: "sandbox" or "production"
19
+ #
20
+ # ## Attributes (return-only):
21
+ # - name [string, default ""]: project name. ex: "MyProject"
22
+ # - 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
+ # - pem [string]: private key in pem format. ex: "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----"
24
+ class Project < StarkBank::User
25
+ attr_reader :name, :allowed_ips
26
+ def initialize(environment:, id:, private_key:, name: '', allowed_ips: nil)
27
+ super(environment, id, private_key)
28
+ @name = name
29
+ @allowed_ips = allowed_ips
30
+ end
31
+ end
32
+ end
data/lib/user/user.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkbank-ecdsa')
4
+ require_relative('../utils/resource')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class User < StarkBank::Utils::Resource
9
+ attr_reader :pem, :environment
10
+ def initialize(environment, id, private_key)
11
+ super(id)
12
+ @pem = StarkBank::Utils::Checks.check_private_key(private_key)
13
+ @environment = StarkBank::Utils::Checks.check_environment(environment)
14
+ end
15
+
16
+ def access_id
17
+ "#{self.class.name.split('::').last.downcase}/#{@id}"
18
+ end
19
+
20
+ def private_key
21
+ EllipticCurve::PrivateKey.fromPem(@pem)
22
+ end
23
+ end
24
+ end
data/lib/utils/api.rb ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('case')
4
+
5
+ module StarkBank
6
+ module Utils
7
+ module API
8
+ def self.api_json(entity)
9
+ entity_hash = {}
10
+ entity.instance_variables.each do |key|
11
+ entity_hash[key[1..-1]] = entity.instance_variable_get(key)
12
+ end
13
+ cast_json_to_api_format(entity_hash)
14
+ end
15
+
16
+ def self.cast_json_to_api_format(hash)
17
+ entity_hash = {}
18
+ hash.each do |key, value|
19
+ next if value.nil?
20
+
21
+ value = value.is_a?(Date) || value.is_a?(DateTime) || value.is_a?(Time) ? value.strftime('%Y-%m-%d') : value
22
+ entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = value
23
+ end
24
+ entity_hash
25
+ end
26
+
27
+ def self.from_api_json(resource_maker, json)
28
+ snakes = {}
29
+ json.each do |key, value|
30
+ snakes[StarkBank::Utils::Case.camel_to_snake(key)] = value
31
+ end
32
+ resource_maker.call(snakes)
33
+ end
34
+
35
+ def self.endpoint(resource_name)
36
+ kebab = StarkBank::Utils::Case.camel_to_kebab(resource_name)
37
+ kebab.sub!('-log', '/log')
38
+ kebab
39
+ end
40
+
41
+ def self.last_name_plural(resource_name)
42
+ "#{last_name(resource_name)}s"
43
+ end
44
+
45
+ def self.last_name(resource_name)
46
+ StarkBank::Utils::Case.camel_to_kebab(resource_name).split('-').last
47
+ end
48
+ end
49
+ end
50
+ end