unit_ruby_sdk 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +175 -20
  3. data/lib/unit/api_resources/application_form_resource.rb +40 -0
  4. data/lib/unit/api_resources/authorization_request_resource.rb +49 -0
  5. data/lib/unit/api_resources/authorization_resource.rb +31 -0
  6. data/lib/unit/api_resources/card_resource.rb +8 -0
  7. data/lib/unit/api_resources/event_resource.rb +40 -0
  8. data/lib/unit/api_resources/fee_resource.rb +32 -0
  9. data/lib/unit/api_resources/payment_resource.rb +9 -0
  10. data/lib/unit/api_resources/received_payment_resource.rb +47 -0
  11. data/lib/unit/api_resources/recurring_payment_resource.rb +55 -0
  12. data/lib/unit/api_resources/repayment_resource.rb +41 -0
  13. data/lib/unit/api_resources/reward_resource.rb +41 -0
  14. data/lib/unit/api_resources/webhook_resource.rb +65 -0
  15. data/lib/unit/models/application/application.rb +98 -10
  16. data/lib/unit/models/application/create_business_application_request.rb +34 -13
  17. data/lib/unit/models/application/create_individual_application_request.rb +12 -8
  18. data/lib/unit/models/application/create_sole_proprietor_application_request.rb +113 -0
  19. data/lib/unit/models/application/create_trust_application_request.rb +67 -0
  20. data/lib/unit/models/application/patch_trust_application_request.rb +31 -0
  21. data/lib/unit/models/application_form/application_form.rb +43 -0
  22. data/lib/unit/models/application_form/create_application_form_request.rb +48 -0
  23. data/lib/unit/models/application_form/list_application_form_params.rb +30 -0
  24. data/lib/unit/models/authorization/authorization.rb +42 -0
  25. data/lib/unit/models/authorization/get_request.rb +22 -0
  26. data/lib/unit/models/authorization/list_request.rb +67 -0
  27. data/lib/unit/models/authorization_request/approve_request.rb +37 -0
  28. data/lib/unit/models/authorization_request/authorization_request.rb +55 -0
  29. data/lib/unit/models/authorization_request/decline_request.rb +31 -0
  30. data/lib/unit/models/authorization_request/list_authorization_params.rb +44 -0
  31. data/lib/unit/models/card/card.rb +102 -4
  32. data/lib/unit/models/card/create_business_credit_card_request.rb +29 -0
  33. data/lib/unit/models/card/create_business_debit_card_request.rb +10 -6
  34. data/lib/unit/models/card/create_business_virtual_credit_card_request.rb +25 -0
  35. data/lib/unit/models/card/create_business_virtual_debit_card_request.rb +10 -6
  36. data/lib/unit/models/card/create_individual_debit_card_request.rb +7 -3
  37. data/lib/unit/models/card/create_individual_virtual_card_request.rb +6 -3
  38. data/lib/unit/models/card/patch_business_card_request.rb +50 -0
  39. data/lib/unit/models/card/patch_business_credit_card_request.rb +22 -0
  40. data/lib/unit/models/card/patch_business_virtual_card_request.rb +43 -0
  41. data/lib/unit/models/card/patch_business_virtual_credit_card_request.rb +20 -0
  42. data/lib/unit/models/customer/list_customer_params.rb +4 -2
  43. data/lib/unit/models/event/event.rb +37 -0
  44. data/lib/unit/models/event/list_event_params.rb +37 -0
  45. data/lib/unit/models/fee/create_fee_request.rb +43 -0
  46. data/lib/unit/models/fee/fee.rb +34 -0
  47. data/lib/unit/models/fee/reverse_fee_request.rb +43 -0
  48. data/lib/unit/models/payment/batch_release_request_builder.rb +21 -0
  49. data/lib/unit/models/payment/create_batch_release_request.rb +54 -0
  50. data/lib/unit/models/payment/payment.rb +21 -1
  51. data/lib/unit/models/received_payment/list_payment_params.rb +51 -0
  52. data/lib/unit/models/received_payment/patch_payment_request.rb +31 -0
  53. data/lib/unit/models/received_payment/received_payment.rb +54 -0
  54. data/lib/unit/models/recurring_payment/create_recurring_credit_ach_payment_request.rb +52 -0
  55. data/lib/unit/models/recurring_payment/create_recurring_credit_book_payment_request.rb +54 -0
  56. data/lib/unit/models/recurring_payment/create_recurring_debit_ach_payment_request.rb +60 -0
  57. data/lib/unit/models/recurring_payment/list_recurring_payment_params.rb +60 -0
  58. data/lib/unit/models/recurring_payment/recurring_payment.rb +106 -0
  59. data/lib/unit/models/repayment/create_ach_repayment_request.rb +57 -0
  60. data/lib/unit/models/repayment/create_book_repayment_request.rb +53 -0
  61. data/lib/unit/models/repayment/list_repayment_params.rb +48 -0
  62. data/lib/unit/models/repayment/repayment.rb +67 -0
  63. data/lib/unit/models/reward/create_reward_request.rb +49 -0
  64. data/lib/unit/models/reward/get_request.rb +22 -0
  65. data/lib/unit/models/reward/list_reward_params.rb +65 -0
  66. data/lib/unit/models/reward/reward.rb +55 -0
  67. data/lib/unit/models/unit_response.rb +1 -1
  68. data/lib/unit/models/webhook/create_webhook_request.rb +49 -0
  69. data/lib/unit/models/webhook/list_webhook_params.rb +39 -0
  70. data/lib/unit/models/webhook/patch_webhook_request.rb +47 -0
  71. data/lib/unit/models/webhook/webhook.rb +80 -0
  72. data/lib/unit/types/application_form_prefill.rb +84 -0
  73. data/lib/unit/types/application_form_settings_override.rb +51 -0
  74. data/lib/unit/types/beneficial_owner.rb +15 -10
  75. data/lib/unit/types/beneficiary.rb +25 -0
  76. data/lib/unit/types/create_schedule.rb +38 -0
  77. data/lib/unit/types/evaluation_params.rb +4 -4
  78. data/lib/unit/types/grantor.rb +37 -0
  79. data/lib/unit/types/officer.rb +26 -13
  80. data/lib/unit/types/power_of_attorney_agent.rb +5 -12
  81. data/lib/unit/types/require_id_verification.rb +29 -0
  82. data/lib/unit/types/trust_contact.rb +34 -0
  83. data/lib/unit/types/trustee.rb +37 -0
  84. data/lib/unit/version.rb +1 -1
  85. data/lib/unit_ruby_sdk.rb +28 -0
  86. metadata +66 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d20a17ad0586962f7984a43e052bbe2f8a1637adf318b91cbb35c2bd65268efe
4
- data.tar.gz: 113eeaae42a13b4d89d31b870c935fc36d6221c4a09c3e4e8770c19e6b96a724
3
+ metadata.gz: 6886c703f37b77fbd4ccc6e174cf0c79b83c588c53f0cfaaa6a1503598fc1fbd
4
+ data.tar.gz: 0371acc6dc064fb9bf8969d10839cbe915e23772bb088493bf889abfeee50244
5
5
  SHA512:
6
- metadata.gz: '0178fda07e7f4f9b3011c8e5b1dfa7a5fc4efffdc9d77b50bfabdab34c174293a2ca4cc90b77cb521646bba08d34b52732509c1652f96f3eab8bd0d38e573976'
7
- data.tar.gz: 8a2b410f41503b00a1cd23637e8f332d96b4116e7a06d980894adff0f8e5ebf9343652629b6177e1890077805b88bcaded6e5dd525590671bacbae77870dc5ab
6
+ metadata.gz: 11d43e7bdaa9d8af5b2f3ac73823576773a784e9bf098d6fb232c08cbb5d76ac7de441da062ed33645c7804c2f19a897a4f0e8cdc1309f6b2b146c249c8edd0c
7
+ data.tar.gz: b8077c7600d42b3396a2f0b5437edde30b1e3d09899df5e0d5ebec0761822a3a8bbcd3b83cc9706245f3a02c26d3b4e0c0481ef19410874eed952292584464c7
data/README.md CHANGED
@@ -14,7 +14,7 @@ gem install unit_ruby_sdk
14
14
 
15
15
  ## Usage
16
16
 
17
- Bellow are a few exapmles of the Ruby SDK application. For full documentation of the Unit API please refer to the full documentation at https://docs.unit.co/
17
+ Bellow are a few usage examples of Unit's Ruby SDK. For full documentation of Unit's API please refer to the full documentation at https://docs.unit.co/
18
18
 
19
19
  ### Creating a Business Application
20
20
 
@@ -40,13 +40,13 @@ response = Unit::Application.create_business_application(
40
40
  industry: "Retail",
41
41
  contact: Unit::Types::BusinessContact.new(full_name, email, phone),
42
42
  officer: Unit::Types::Officer.new(full_name, date_of_birth, address, phone, email, ssn),
43
- beneficial_owners: [beneficial_owner, beneficial_owner],
43
+ beneficial_owners: [beneficial_owner],
44
44
  entity_type: 'LLC'
45
45
  )
46
46
 
47
47
  application = response.data
48
48
 
49
- puts application.id
49
+ puts application["id"]
50
50
 
51
51
  file = File.open("./spec/test.pdf", "rb")
52
52
  contents = file.read
@@ -59,7 +59,42 @@ upload_document_request = Unit::Application.upload_document(
59
59
  file_type: Unit::Types::DocumentFileType::PDF,
60
60
  is_back_side: true)
61
61
 
62
- puts upload_document_request.data.id
62
+ puts upload_document_request.data["id"]
63
+ ```
64
+
65
+ ### Creating a trust application
66
+
67
+ ```ruby
68
+ full_name = Unit::Types::FullName.new('John', 'Doe')
69
+ date_of_birth = '1980-08-10'
70
+ address = Unit::Types::Address.new('123 Main St', 'San Francisco', 'CA', '94205', 'US')
71
+ phone = Unit::Types::Phone.new('380', '555123222')
72
+ email = 'jone.doe@unit-finance.com'
73
+ ssn = '123456789'
74
+ trust_contact = Unit::Types::TrustContact.new(full_name, email, phone, address)
75
+ beneficiaries = [Unit::Types::Beneficiary.new(full_name, date_of_birth).represent]
76
+ grantor = Unit::Types::Grantor.new(full_name, ssn, email, phone, address, date_of_birth)
77
+ trustees = [Unit::Types::Trustee.new(full_name, ssn, email, phone, address, date_of_birth).represent]
78
+
79
+
80
+ response = Unit::Application.create_trust_application(
81
+ name: "Trust me Inc.",
82
+ state_of_incorporation: "CA",
83
+ revocability: "Revocable",
84
+ source_of_funds: "Salary",
85
+ tax_id: "123456789",
86
+ grantor: grantor,
87
+ trustees: trustees,
88
+ beneficiaries: beneficiaries,
89
+ contact: trust_contact,
90
+ ip: "127.0.0.2",
91
+ tags: {
92
+ "userId": "106a75e9-de77-4e25-9561-faffe59d7814"
93
+ },
94
+ idempotency_key: "3a1a33be-4e12-4603-9ed0-820922389fb8")
95
+
96
+ trust_application = response.data
97
+ puts trust_application["id"]
63
98
  ```
64
99
 
65
100
  ### Creating a deposit account request
@@ -70,7 +105,7 @@ response = Unit::Account::Deposit.create_deposit_account(
70
105
  tags: { "purpose": "checking" },
71
106
  relationships: relationships)
72
107
  deposit_account = response.data
73
- puts deposit_account.id
108
+ puts deposit_account["id"]
74
109
  ```
75
110
 
76
111
  ### Creating a credit account request
@@ -81,9 +116,22 @@ response = Unit::Account::Credit.create_credit_account(
81
116
  customer_id: "851228",
82
117
  tags: { "purpose": "tax" })
83
118
  credit_account = response.data
84
- puts credit_account.id
119
+ puts credit_account["id"]
120
+ ```
121
+
122
+ ### Creating a batch release request
123
+ ```ruby
124
+ requests =
125
+ [
126
+ { account_id: "49230", batch_account_id: "1296383", amount: 100, description: "Description 1", sender_name: "Sender Name 1", sender_address: ADDRESS, sender_account_number: "1234" },
127
+ { account_id: "49230", batch_account_id: "1296383", amount: 100, description: "Description 1", sender_name: "Sender Name 1", sender_address: ADDRESS, sender_account_number: "12324" }
128
+ ]
129
+ response = Unit::Payment.create_batch_release(requests)
130
+ batch_release = response.data
131
+ puts batch_release[0].id
85
132
  ```
86
133
 
134
+
87
135
  ### Fetching a Customer
88
136
 
89
137
  ```ruby
@@ -91,11 +139,10 @@ require 'unit_ruby_sdk'
91
139
 
92
140
  Unit.config(api_url: ENV['API_URL'], token: ENV['TOKEN'])
93
141
 
94
- customer = Unit::Customer.list_customers.first
95
- puts customer.id
142
+ customer = Unit::Customer.list_customers(limit: 20, offset: 10).data.first
143
+ puts customer["id"]
96
144
  ```
97
145
 
98
- ###
99
146
  ### Creating a Payment
100
147
 
101
148
  ```ruby
@@ -108,7 +155,7 @@ response = Unit::Payment.create_book_payment(
108
155
  counterparty_account_id: "36981"
109
156
  )
110
157
  payment = response.data
111
- puts payment.id
158
+ puts payment["id"]
112
159
  ```
113
160
 
114
161
  ### Get a transaction by id
@@ -116,9 +163,21 @@ puts payment.id
116
163
  ```ruby
117
164
  response = Unit::Transaction.get_transaction(transaction_id: '12345', account_id: '72345')
118
165
  transaction = response.data
119
- puts transaction.id
166
+ puts transaction["id"]
120
167
  ```
121
168
 
169
+ ### Get an authorization by id
170
+
171
+ ```ruby
172
+ response = Unit::Authorization.get_authorization(
173
+ authorization_id: '12345',
174
+ include_non_authorized: true
175
+ )
176
+ authorization = response.data
177
+ puts authorization.id
178
+ ```
179
+
180
+
122
181
  ### Creating an individual debit card
123
182
  ```ruby
124
183
  response = Unit::Card.create_individual_debit_card(
@@ -126,10 +185,38 @@ response = Unit::Card.create_individual_debit_card(
126
185
  type: "depositAccount",
127
186
  shipping_address: address,
128
187
  design: "default",
129
- additional_embossed_text: "Second Cardholder"
188
+ additional_embossed_text: "Second Cardholder",
189
+ expiry_date: "03/27"
130
190
  )
131
191
  card = response.data
132
- puts card.id
192
+ puts card["id"]
193
+ ```
194
+
195
+ ### Updating a received payment
196
+ ```ruby
197
+ response = Unit::ReceivedPayment.update_payment(
198
+ payment_id: "1232",
199
+ tags: { purpose: "test" })
200
+ received_payment = response.data
201
+ puts received_payment["id"]
202
+
203
+ ### Creating a business credit card
204
+ ```ruby
205
+ full_name = Unit::Types::FullName.new('John', 'Doe')
206
+ date_of_birth = '1980-08-10'
207
+ address = Unit::Types::Address.new('123 Main St', 'San Francisco', 'CA', '94205', 'US')
208
+ phone = Unit::Types::Phone.new('380', '555123222')
209
+ email = 'jone.doe@unit-finance.com'
210
+ response = Unit::Card.create_business_credit_card(
211
+ account_id: "1234",
212
+ full_name: full_name,
213
+ date_of_birth: date_of_birth,
214
+ address: address,
215
+ phone: phone,
216
+ email: email
217
+ )
218
+ charge_card = response.data
219
+ puts charge_card.id
133
220
  ```
134
221
 
135
222
  ### Creating a check deposit
@@ -140,7 +227,7 @@ response = Unit::CheckDeposit.create_deposit(
140
227
  description: "test check deposit"
141
228
  )
142
229
  deposit = response.data
143
- puts deposit.id
230
+ puts deposit["id"]
144
231
  ```
145
232
 
146
233
  ### Creating a counterparty with a plaid token
@@ -152,7 +239,7 @@ response = Unit::Counterparty.create_with_plaid_token(
152
239
  plaid_processor_token: "processor-sandbox-plaid-token")
153
240
 
154
241
  counterparty = response.data
155
- puts counterparty.id
242
+ puts counterparty["id"]
156
243
  ```
157
244
 
158
245
 
@@ -166,9 +253,19 @@ puts counterparty.id
166
253
  description: "test payment"
167
254
  )
168
255
  ach_payment = response.data
169
- puts ach_payment.id
256
+ puts ach_payment["id"]
170
257
  ```
171
258
 
259
+ ### Creating a recurring payment
260
+ ```ruby
261
+ schedule = Unit::Types::CreateSchedule.new("Monthly", 3)
262
+ response = Unit::RecurringPayment.create_recurring_credit_book_payment(account_id: "27573", counterparty_id: "36099", amount: 1000,
263
+ description: "test payme", schedule: schedule)
264
+ recurring_payment = response.data
265
+ puts recurring_payment.id
266
+ ```
267
+
268
+
172
269
  ### Creating a wire payment
173
270
  ```ruby
174
271
  address = Unit::Types::Address.new('123 Main St', 'San Francisco', 'CA', '94205', 'US')
@@ -178,7 +275,14 @@ puts counterparty.id
178
275
  description: "test payment",
179
276
  counterparty: Unit::Types::WireCounterparty.new("Jane Doe", "27573", "812345678", address))
180
277
  wire_payment = response.data
181
- puts wire_payment.id
278
+ puts wire_payment["id"]
279
+ ```
280
+
281
+ ### Get an event by id
282
+ ```ruby
283
+ response = Unit::Event.get_event(event_id: "12605774")
284
+ event = response.data
285
+ puts event.id
182
286
  ```
183
287
 
184
288
  ### Creating a bulk payment
@@ -195,10 +299,56 @@ ach_payment_plaid_token_request = Unit::Payment::CreateWithPlaidTokenRequest.new
195
299
  response = Unit::Payment.create_bulk_payment(
196
300
  requests: [book_payment_request, wire_payment_request, ach_payment_inline_request, ach_payment_linked_request, ach_payment_plaid_token_request])
197
301
  bulk_payment = response.data
198
- puts bulk_payment.id
302
+ puts bulk_payment["id"]
303
+ ```
304
+
305
+ ### Creating a book repayment
306
+ ```ruby
307
+ response = Unit::Repayment.create_book_repayment(
308
+ account_id: "10001",
309
+ credit_account_id: "10002",
310
+ counterparty_account_id: "10003",
311
+ description: "test", amount: 100,
312
+ transaction_summary_override: "override",
313
+ tags: { purpose: "test" },
314
+ idempotency_key: "3a1a33be-4e12-4603-9ed0-820922389fb8")
315
+ book_repayment = response.data
316
+ puts book_repayment.id
199
317
  ```
318
+
200
319
  ### Logging Errors
201
320
 
321
+ ### Handling Response
322
+
323
+ ### Creating a webhook
324
+ ```ruby
325
+ response = Unit::Webhook.create_webhook(
326
+ label: "some label",
327
+ url: "https://webhook.site/81ee6b53-fde4-4b7d-85a0-0b6249a4488d",
328
+ token: "MyToken",
329
+ content_type: "Json",
330
+ delivery_mode: "AtLeastOnce",
331
+ include_resources: false,
332
+ subscription_type: "OnlyAuthorizationRequest")
333
+ webhook = response.data
334
+ puts webhook["id"]
335
+ ```
336
+
337
+ ### Creating a fee
338
+ ```ruby
339
+ response = Unit::Fee.create_fee(
340
+ account_id: "27573",
341
+ amount: 12_345,
342
+ description: "test",
343
+ tags: { purpose: "test" },
344
+ idempotency_key: "123"
345
+ )
346
+ fee = response.data
347
+ puts fee["id"]
348
+ ```
349
+
350
+
351
+ ### Handling Response
202
352
  ```ruby
203
353
  require 'unit_ruby_sdk'
204
354
 
@@ -207,6 +357,11 @@ Unit.config(api_url: ENV['API_URL'], token: "missing token")
207
357
  # response is a Unit::UnitError
208
358
  response = Unit::Application.get_application('123')
209
359
 
210
- # Prints "Bearer token is missing"
211
- response.errors.each{|error| puts error.title}
360
+ # Checks the response to be an instance of UnitResponse
361
+ if response.instance_of?(Unit::UnitResponse)
362
+ # handle response
363
+ else
364
+ # handle error
365
+ response.errors.each{|error| puts error.title}
366
+ end
212
367
  ```
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
+ require "json"
6
+
7
+ # class for creating requests for application forms to Unit API and parsing responses
8
+ # @see https://docs.unit.co/application-forms
9
+ module Unit
10
+ module Resource
11
+ class ApplicationFormResource < Unit::Resource::BaseResource
12
+ class << self
13
+ # Create a new application form by calling Unit's API
14
+ # @param request [CreateApplicationFormRequest] request
15
+ # @return [UnitResponse, UnitError]
16
+ def create_application_form(request)
17
+ payload = request.to_json_api
18
+ response = HttpHelper.post("#{api_url}/application-forms", body: payload, headers: headers)
19
+ response_handler(response)
20
+ end
21
+
22
+ # Get application form by calling Unit's API
23
+ # @param application_form_id [String]
24
+ # @return [UnitResponse, UnitError]
25
+ def get_application_form(application_form_id)
26
+ response = HttpHelper.get("#{api_url}/application-forms/#{application_form_id}", headers: headers)
27
+ response_handler(response)
28
+ end
29
+
30
+ # List application forms by calling Unit's API
31
+ # @param params [ListApplicationFormParams]
32
+ # @return [UnitResponse, UnitError]
33
+ def list_application_forms(params = nil)
34
+ response = HttpHelper.get("#{api_url}/application-forms", headers: headers, params: params.to_hash)
35
+ response_handler(response)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
+
6
+ # class for creating cards authorization requests
7
+ # @see https://docs.unit.co/cards-authorization-requests
8
+
9
+ module Unit
10
+ module Resource
11
+ class AuthorizationRequestResource < Unit::Resource::BaseResource
12
+ class << self
13
+ # Get authorization request by calling Unit's API
14
+ # @param request_id [String]
15
+ # @return [UnitResponse, UnitError]
16
+ def get_authorization_request(request_id)
17
+ response = HttpHelper.get("#{api_url}/authorization-requests/#{request_id}", headers: headers)
18
+ response_handler(response)
19
+ end
20
+
21
+ # List authorization requests by calling Unit's API
22
+ # @param params [ListAuthorizationParams]
23
+ # @return [UnitResponse, UnitError]
24
+ def list(params = nil)
25
+ response = HttpHelper.get("#{api_url}/authorization-requests", params: params.to_hash, headers: headers)
26
+ response_handler(response)
27
+ end
28
+
29
+ # Approve an authorization request by calling Unit's API
30
+ # @param request [ApproveRequest]
31
+ # @return [UnitResponse, UnitError]
32
+ def approve(request)
33
+ payload = request.to_json_api
34
+ response = HttpHelper.post("#{api_url}/authorization-requests/#{request.authorization_request_id}/approve", body: payload, headers: headers)
35
+ response_handler(response)
36
+ end
37
+
38
+ # Decline an authorization request by calling Unit's API
39
+ # @param request [DeclineRequest]
40
+ # @return [UnitResponse, UnitError]
41
+ def decline(request)
42
+ payload = request.to_json_api
43
+ response = HttpHelper.post("#{api_url}/authorization-requests/#{request.authorization_request_id}/decline", body: payload, headers: headers)
44
+ response_handler(response)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
+ require "json"
6
+ # class for creating requests for authorizations to Unit API and parsing responses
7
+ # @see https://docs.unit.co/cards-authorizations
8
+ module Unit
9
+ module Resource
10
+ class AuthorizationResource < Unit::Resource::BaseResource
11
+ class << self
12
+ # Get authorization by calling Unit's API
13
+ # @param params [GetRequest]
14
+ # @return [UnitResponse, UnitError]
15
+ def get(params)
16
+ payload = params.to_hash
17
+ response = HttpHelper.get("#{api_url}/authorizations/#{params.authorization_id}", params: payload, headers: headers)
18
+ response_handler(response)
19
+ end
20
+
21
+ # Get authorization by calling Unit's API
22
+ # @param params [GetRequest]
23
+ # @return [UnitResponse, UnitError]
24
+ def list(params = nil)
25
+ response = HttpHelper.get("#{api_url}/authorizations", params: params&.to_hash, headers: headers)
26
+ response_handler(response)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -83,6 +83,14 @@ module Unit
83
83
  response_handler(response)
84
84
  end
85
85
 
86
+ # Update card by calling Unit's API
87
+ # @param request [PatchBusinessCardRequest, PatchBusinessCreditCardRequest, PatchBusinessVirtualCardRequest, PatchBusinessVirtualCreditCardRequest]
88
+ def update(request)
89
+ payload = request.to_json_api
90
+ response = HttpHelper.patch("#{api_url}/cards/#{request.card_id}", headers: headers, body: payload)
91
+ response_handler(response)
92
+ end
93
+
86
94
  # List cards by calling Unit's API
87
95
  # @param params [ListCardParams]
88
96
  # @return [UnitResponse, UnitError]
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../api_resources/base_resource"
4
+ require_relative "../models/unit_response"
5
+ require_relative "../errors/unit_error"
6
+ require_relative "../utils/http_helper"
7
+
8
+ # class for creating requests for events to Unit API and parsing responses
9
+ # @see https://docs.unit.co/events
10
+ module Unit
11
+ module Resource
12
+ class EventResource < Unit::Resource::BaseResource
13
+ class << self
14
+ # Get an event by id by calling Unit's API
15
+ # @param event_id [String]
16
+ # @return [UnitResponse, UnitError]
17
+ def get(event_id)
18
+ response = HttpHelper.get("#{api_url}/events/#{event_id}", headers: headers)
19
+ response_handler(response)
20
+ end
21
+
22
+ # List events by calling Unit's API
23
+ # @param params [ListEventParams]
24
+ # @return [UnitResponse, UnitError]
25
+ def list(params = nil)
26
+ response = HttpHelper.get("#{api_url}/events", params: params&.to_hash, headers: headers)
27
+ response_handler(response)
28
+ end
29
+
30
+ # Fire an event by calling Unit's API
31
+ # @param event_id [String]
32
+ # @return [UnitResponse, UnitError]
33
+ def fire(event_id)
34
+ response = HttpHelper.post("#{api_url}/events/#{event_id}", headers: headers)
35
+ response_handler(response)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
+
6
+ # class for creating requests for fees to Unit API and parsing responses
7
+ # @see https://docs.unit.co/fees/
8
+ module Unit
9
+ module Resource
10
+ class FeeResource < Unit::Resource::BaseResource
11
+ class << self
12
+ # Create a new fee by calling Unit's API
13
+ # @param request [CreateFeeRequest]
14
+ # @return [UnitResponse, UnitError]
15
+ def create_fee(request)
16
+ payload = request.to_json_api
17
+ response = HttpHelper.post("#{api_url}/fees", body: payload, headers: headers)
18
+ response_handler(response)
19
+ end
20
+
21
+ # Reverse a fee by calling Unit's API
22
+ # @param request [ReverseFeeRequest]
23
+ # @return [UnitResponse, UnitError]
24
+ def reverse_fee(request)
25
+ payload = request.to_json_api
26
+ response = HttpHelper.post("#{api_url}/fees/reverse", body: payload, headers: headers)
27
+ response_handler(response)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -53,6 +53,15 @@ module Unit
53
53
  response = HttpHelper.get("#{api_url}/payments", params: payload, headers: headers)
54
54
  response_handler(response)
55
55
  end
56
+
57
+ # Create a new batch release by calling Unit's API
58
+ # @param request [BatchReleaseRequestBuilder]
59
+ # @return [UnitResponse, UnitError]
60
+ def create_batch_release(request)
61
+ payload = request.to_hash.to_json
62
+ response = HttpHelper.post("#{api_url}/batch-releases", body: payload, headers: headers)
63
+ response_handler(response)
64
+ end
56
65
  end
57
66
  end
58
67
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
+
6
+ # class for creating requests for book payments to Unit API and parsing responses
7
+ # @see https://docs.unit.co/book-payments#book-payments
8
+ module Unit
9
+ module Resource
10
+ class ReceivedPaymentResource < Unit::Resource::BaseResource
11
+ class << self
12
+ # Get a received ach payment by calling Unit's API
13
+ # @param payment_id [String]
14
+ # @return [UnitResponse, UnitError]
15
+ def get_payment(payment_id)
16
+ response = HttpHelper.get("#{api_url}/received-payments/#{payment_id}", headers: headers)
17
+ response_handler(response)
18
+ end
19
+
20
+ # List received ach payments by calling Unit's API
21
+ # @param params [ListAchPaymentParams]
22
+ # @return [UnitResponse, UnitError]
23
+ def list_payments(params = nil)
24
+ response = HttpHelper.get("#{api_url}/received-payments", params: params&.to_hash, headers: headers)
25
+ response_handler(response)
26
+ end
27
+
28
+ # Update a received ach payment by calling Unit's API
29
+ # @param request [PatchReceivedPaymentRequest]
30
+ # @return [UnitResponse, UnitError]
31
+ def update_payment(request)
32
+ payload = request.to_json_api
33
+ response = HttpHelper.patch("#{api_url}/received-payments/#{request.payment_id}", body: payload, headers: headers)
34
+ response_handler(response)
35
+ end
36
+
37
+ # Advance an ach payment by calling Unit's API
38
+ # @param payment_id [String]
39
+ # @return [UnitResponse, UnitError]
40
+ def advance_received_payment(payment_id)
41
+ response = HttpHelper.post("#{api_url}/received-payments/#{payment_id}/advance", headers: headers)
42
+ response_handler(response)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./base_resource"
4
+ require_relative "../utils/http_helper"
5
+
6
+ # class for creating requests for payments to Unit API and parsing responses
7
+ # @see https://docs.unit.co/recurring-payments
8
+ module Unit
9
+ module Resource
10
+ class RecurringPaymentResource < Unit::Resource::BaseResource
11
+ class << self
12
+ # Create a new recurring payment by calling Unit's API
13
+ # @param request [CreateRecurringCreditAchPaymentRequest, CreateRecurringDebitAchPaymentRequest, CreateRecurringCreditBookPaymentRequest]
14
+ # @return [UnitResponse, UnitError]
15
+ def create_recurring_payment(request)
16
+ payload = request.to_json_api
17
+ response = HttpHelper.post("#{api_url}/recurring-payments", body: payload, headers: headers)
18
+ response_handler(response)
19
+ end
20
+
21
+ # Disable a new recurring payment by calling Unit's API
22
+ # @param recurring_payment_id [String]
23
+ # @return [UnitResponse, UnitError]
24
+ def disable_recurring_payment(recurring_payment_id)
25
+ response = HttpHelper.post("#{api_url}/recurring-payments/#{recurring_payment_id}/disable", headers: headers)
26
+ response_handler(response)
27
+ end
28
+
29
+ # Enable a new recurring payment by calling Unit's API
30
+ # @param recurring_payment_id [String]
31
+ # @return [UnitResponse, UnitError]
32
+ def enable_recurring_payment(recurring_payment_id)
33
+ response = HttpHelper.post("#{api_url}/recurring-payments/#{recurring_payment_id}/enable", headers: headers)
34
+ response_handler(response)
35
+ end
36
+
37
+ # List a new recurring payment by calling Unit's API
38
+ # @param request [ListRecurringPaymentParams]
39
+ # @return [UnitResponse, UnitError]
40
+ def list_recurring_payment(params = {})
41
+ response = HttpHelper.get("#{api_url}/recurring-payments", params: params.to_hash, headers: headers)
42
+ response_handler(response)
43
+ end
44
+
45
+ # Get a new recurring payment by calling Unit's API
46
+ # @param recurring_payment_id [String]
47
+ # @return [UnitResponse, UnitError]
48
+ def get_recurring_payment(recurring_payment_id)
49
+ response = HttpHelper.get("#{api_url}/recurring-payments/#{recurring_payment_id}", headers: headers)
50
+ response_handler(response)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end