unit_ruby_sdk 1.0.2 → 1.0.4
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.
- checksums.yaml +4 -4
- data/README.md +60 -0
- data/lib/unit/api_resources/account_resource.rb +1 -1
- data/lib/unit/api_resources/counterparty_resource.rb +65 -0
- data/lib/unit/api_resources/payment_resource.rb +24 -5
- data/lib/unit/api_resources/transaction_resource.rb +9 -0
- data/lib/unit/models/account/account.rb +110 -2
- data/lib/unit/models/account/credit/balance_history_request.rb +39 -0
- data/lib/unit/models/account/credit/close_account_request.rb +36 -0
- data/lib/unit/models/account/credit/create_account_request.rb +44 -0
- data/lib/unit/models/account/credit/freeze_account_request.rb +36 -0
- data/lib/unit/models/account/credit/list_account_params.rb +51 -0
- data/lib/unit/models/account/credit/patch_account_request.rb +36 -0
- data/lib/unit/models/counterparty/counterparty.rb +93 -0
- data/lib/unit/models/counterparty/create_counterparty_request.rb +56 -0
- data/lib/unit/models/counterparty/create_with_plaid_token_request.rb +53 -0
- data/lib/unit/models/counterparty/list_counterparty_params.rb +45 -0
- data/lib/unit/models/counterparty/update_counterparty_request.rb +40 -0
- data/lib/unit/models/payment/create_ach_payment_inline_request.rb +60 -0
- data/lib/unit/models/payment/create_payment_linked_request.rb +65 -0
- data/lib/unit/models/payment/create_wire_payment_request.rb +44 -0
- data/lib/unit/models/payment/create_with_plaid_token_request.rb +69 -0
- data/lib/unit/models/payment/get_request.rb +22 -0
- data/lib/unit/models/payment/list_payment_params.rb +79 -0
- data/lib/unit/models/payment/patch_ach_payment_request.rb +31 -0
- data/lib/unit/models/payment/payment.rb +142 -1
- data/lib/unit/models/transaction/patch_book_transaction_request.rb +39 -0
- data/lib/unit/models/transaction/patch_chargeback_transaction_request.rb +39 -0
- data/lib/unit/models/transaction/transaction.rb +24 -0
- data/lib/unit/types/counterparty.rb +31 -0
- data/lib/unit/types/wire_counterparty.rb +31 -0
- data/lib/unit/version.rb +1 -1
- data/lib/unit_ruby_sdk.rb +5 -0
- metadata +25 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b262e1336d0a6f1e2a6633172d3fe0fb030eb658e3a30ced02803e6f00bd22d
|
4
|
+
data.tar.gz: cbcb03bfba7390d4b27e5b1485d5f60c66fbc50104d4066764c482a3fd2ecb12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35379395a2258233b3b9cff6cc239fde4aeee3ba43b7b423a6da5508e1b4ed2ca0aae735cad7d5bda0ef539816b761d44b1071f637f167010708704c37bb6fff
|
7
|
+
data.tar.gz: 291d0580135e0832bead828127eb3341f740d9cd4b9cb131349fcda06a7700dd02aae5b1cb179de9ac09eda3b347304566b370f19f7eaccfc002b2c1582f995e
|
data/README.md
CHANGED
@@ -62,6 +62,28 @@ upload_document_request = Unit::Application.upload_document(
|
|
62
62
|
puts upload_document_request.data.id
|
63
63
|
```
|
64
64
|
|
65
|
+
### Creating a deposit account request
|
66
|
+
```ruby
|
67
|
+
relationships = { "customer": Unit::Types::Relationship.new("customer", "111009").to_hash }
|
68
|
+
response = Unit::Account::Deposit.create_deposit_account(
|
69
|
+
deposit_product: "checking",
|
70
|
+
tags: { "purpose": "checking" },
|
71
|
+
relationships: relationships)
|
72
|
+
deposit_account = response.data
|
73
|
+
puts deposit_account.id
|
74
|
+
```
|
75
|
+
|
76
|
+
### Creating a credit account request
|
77
|
+
```ruby
|
78
|
+
response = Unit::Account::Credit.create_credit_account(
|
79
|
+
credit_terms: "credit_terms_test",
|
80
|
+
credit_limit: 20_000,
|
81
|
+
customer_id: "851228",
|
82
|
+
tags: { "purpose": "tax" })
|
83
|
+
credit_account = response.data
|
84
|
+
puts credit_account.id
|
85
|
+
```
|
86
|
+
|
65
87
|
### Fetching a Customer
|
66
88
|
|
67
89
|
```ruby
|
@@ -121,6 +143,44 @@ deposit = response.data
|
|
121
143
|
puts deposit.id
|
122
144
|
```
|
123
145
|
|
146
|
+
### Creating a counterparty with a plaid token
|
147
|
+
```ruby
|
148
|
+
response = Unit::Counterparty.create_with_plaid_token(
|
149
|
+
customer_id: "823139",
|
150
|
+
type: "Business",
|
151
|
+
name: "Jo Joel",
|
152
|
+
plaid_processor_token: "processor-sandbox-plaid-token")
|
153
|
+
|
154
|
+
counterparty = response.data
|
155
|
+
puts counterparty.id
|
156
|
+
```
|
157
|
+
|
158
|
+
|
159
|
+
### Creating a Payment to linked counterparty
|
160
|
+
```ruby
|
161
|
+
response = Unit::Payment.create_ach_payment_linked(
|
162
|
+
account_id: "123456",
|
163
|
+
counterparty_id: "56784",
|
164
|
+
amount: 1000,
|
165
|
+
direction: "Credit",
|
166
|
+
description: "test payment"
|
167
|
+
)
|
168
|
+
ach_payment = response.data
|
169
|
+
puts ach_payment.id
|
170
|
+
```
|
171
|
+
|
172
|
+
### Creating a wire payment
|
173
|
+
```ruby
|
174
|
+
address = Unit::Types::Address.new('123 Main St', 'San Francisco', 'CA', '94205', 'US')
|
175
|
+
response = Unit::Payment.create_wire_payment(
|
176
|
+
account_id: "1234",
|
177
|
+
amount: 1000,
|
178
|
+
description: "test payment",
|
179
|
+
counterparty: Unit::Types::WireCounterparty.new("Jane Doe", "27573", "812345678", address))
|
180
|
+
wire_payment = response.data
|
181
|
+
puts wire_payment.id
|
182
|
+
```
|
183
|
+
|
124
184
|
### Logging Errors
|
125
185
|
|
126
186
|
```ruby
|
@@ -98,7 +98,7 @@ module Unit
|
|
98
98
|
# @param params [BalanceHistoryRequest]
|
99
99
|
# @return [UnitResponse, UnitError]
|
100
100
|
def get_account_balance_history(params)
|
101
|
-
response = HttpHelper.get("#{api_url}/account-end-of-day", params: params.to_hash
|
101
|
+
response = HttpHelper.get("#{api_url}/account-end-of-day", params: params.to_hash, headers: headers)
|
102
102
|
response_handler(response)
|
103
103
|
end
|
104
104
|
|
@@ -0,0 +1,65 @@
|
|
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 counterparties to Unit API and parsing responses
|
8
|
+
# @see https://docs.unit.co/payments-counterparties
|
9
|
+
module Unit
|
10
|
+
module Resource
|
11
|
+
class CounterpartyResource < Unit::Resource::BaseResource
|
12
|
+
class << self
|
13
|
+
# Create a counterparty by calling Unit's API
|
14
|
+
# @param request [CreateCounterpartyRequest, CreateWithPlaidTokenRequest]
|
15
|
+
# @return [UnitResponse, UnitError]
|
16
|
+
def create_counterparty(request)
|
17
|
+
payload = request.to_json_api
|
18
|
+
response = HttpHelper.post("#{api_url}/counterparties", body: payload, headers: headers)
|
19
|
+
response_handler(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Update counterparty by calling Unit's API
|
23
|
+
# @param request [UpdateCounterpartyRequest]
|
24
|
+
# @return [UnitResponse, UnitError]
|
25
|
+
def update_counterparty(request)
|
26
|
+
payload = request.to_json_api
|
27
|
+
response = HttpHelper.patch("#{api_url}/counterparties/#{request.counterparty_id}", body: payload, headers: headers)
|
28
|
+
response_handler(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Delete counterparty by calling Unit's API
|
32
|
+
# @param counterparty_id String
|
33
|
+
# @return [UnitResponse, UnitError]
|
34
|
+
def delete(counterparty_id)
|
35
|
+
response = HttpHelper.delete("#{api_url}/counterparties/#{counterparty_id}", headers: headers, response_type: "delete")
|
36
|
+
file_response_handler(response)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get counterparty by id by calling Unit's API
|
40
|
+
# @param counterparty_id String
|
41
|
+
# @return [UnitResponse, UnitError]
|
42
|
+
def get_counterparty(counterparty_id)
|
43
|
+
response = HttpHelper.get("#{api_url}/counterparties/#{counterparty_id}", headers: headers)
|
44
|
+
response_handler(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get counterparty balance
|
48
|
+
# @param counterparty_id String
|
49
|
+
# @return [UnitResponse, UnitError]
|
50
|
+
def get_counterparty_balance(counterparty_id)
|
51
|
+
response = HttpHelper.get("#{api_url}/counterparties/#{counterparty_id}/balance", headers: headers)
|
52
|
+
response_handler(response)
|
53
|
+
end
|
54
|
+
|
55
|
+
# List counterparties
|
56
|
+
# @param params [ListCounterpartyParams]
|
57
|
+
# @return [UnitResponse, UnitError]
|
58
|
+
def list(params = nil)
|
59
|
+
response = HttpHelper.get("#{api_url}/counterparties", params: params.to_hash, headers: headers)
|
60
|
+
response_handler(response)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -3,14 +3,15 @@
|
|
3
3
|
require_relative "./base_resource"
|
4
4
|
require_relative "../utils/http_helper"
|
5
5
|
|
6
|
-
# class for creating requests for
|
6
|
+
# class for creating requests for payments to Unit API and parsing responses
|
7
7
|
# @see https://docs.unit.co/book-payments#book-payments
|
8
|
+
# @see https://docs.unit.co/ach-origination
|
8
9
|
module Unit
|
9
10
|
module Resource
|
10
11
|
class PaymentResource < Unit::Resource::BaseResource
|
11
12
|
class << self
|
12
|
-
# Create a new
|
13
|
-
# @param request [
|
13
|
+
# Create a new payment by calling Unit's API
|
14
|
+
# @param request [CreateAchPaymentInlineRequest, CreatePaymentLinkedRequest, CreateBookPaymentRequest, CreateWithPlaidTokenRequest, CreateWirePaymentRequest]
|
14
15
|
# @return [UnitResponse, UnitError]
|
15
16
|
def create_payment(request)
|
16
17
|
payload = request.to_json_api
|
@@ -18,14 +19,32 @@ module Unit
|
|
18
19
|
response_handler(response)
|
19
20
|
end
|
20
21
|
|
21
|
-
# Update a
|
22
|
-
# @param request [PatchBookPaymentRequest]
|
22
|
+
# Update a payment by calling Unit's API
|
23
|
+
# @param request [PatchBookPaymentRequest, PatchAchPaymentRequest]
|
23
24
|
# @return [UnitResponse, UnitError]
|
24
25
|
def update_payment(request)
|
25
26
|
payload = request.to_json_api
|
26
27
|
response = HttpHelper.patch("#{api_url}/payments/#{request.payment_id}", body: payload, headers: headers)
|
27
28
|
response_handler(response)
|
28
29
|
end
|
30
|
+
|
31
|
+
# Get a payment by calling Unit's API
|
32
|
+
# @param request [GetRequest]
|
33
|
+
# @return [UnitResponse, UnitError]
|
34
|
+
def get_payment(request)
|
35
|
+
payload = request.to_hash
|
36
|
+
response = HttpHelper.get("#{api_url}/payments/#{request.payment_id}", params: payload, headers: headers)
|
37
|
+
response_handler(response)
|
38
|
+
end
|
39
|
+
|
40
|
+
# List payments by calling Unit's API
|
41
|
+
# @param request [ListPaymentParams]
|
42
|
+
# @return [UnitResponse, UnitError]
|
43
|
+
def list_payments(request)
|
44
|
+
payload = request.to_hash
|
45
|
+
response = HttpHelper.get("#{api_url}/payments", params: payload, headers: headers)
|
46
|
+
response_handler(response)
|
47
|
+
end
|
29
48
|
end
|
30
49
|
end
|
31
50
|
end
|
@@ -34,6 +34,15 @@ module Unit
|
|
34
34
|
response = HttpHelper.patch("#{api_url}/accounts/#{request.account_id}/transactions/#{request.transaction_id}", body: payload, headers: headers)
|
35
35
|
response_handler(response)
|
36
36
|
end
|
37
|
+
|
38
|
+
# Update a transaction by calling Unit's API
|
39
|
+
# @param request [PatchBookTransactionRequest, PatchChargeTransactionRequest]
|
40
|
+
# @return [UnitResponse, UnitError]
|
41
|
+
def update_transaction(request)
|
42
|
+
payload = request.to_json_api
|
43
|
+
response = HttpHelper.patch("#{api_url}/transactions/#{request.transaction_id}", body: payload, headers: headers)
|
44
|
+
response_handler(response)
|
45
|
+
end
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
@@ -34,8 +34,8 @@ module Unit
|
|
34
34
|
# @param reason [String]
|
35
35
|
# @param fraud_reason [String] - optional
|
36
36
|
# @return [UnitResponse, UnitError]
|
37
|
-
def close_deposit_account(account_id:, reason:)
|
38
|
-
request = CloseDepositAccountRequest.new(account_id, reason)
|
37
|
+
def close_deposit_account(account_id:, reason:, fraud_reason: nil)
|
38
|
+
request = CloseDepositAccountRequest.new(account_id, reason, fraud_reason)
|
39
39
|
Unit::Resource::AccountResource.close_account(request)
|
40
40
|
end
|
41
41
|
|
@@ -153,5 +153,113 @@ module Unit
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
156
|
+
|
157
|
+
module Credit
|
158
|
+
ACCOUNT_LIST_LIMIT = 100
|
159
|
+
ACCOUNT_LIST_OFFSET = 0
|
160
|
+
BALANCE_HISTORY_LIMIT = 100
|
161
|
+
BALANCE_HISTORY_OFFSET = 0
|
162
|
+
autoload :CreateAccountRequest, "unit/models/account/credit/create_account_request"
|
163
|
+
autoload :CloseAccountRequest, "unit/models/account/credit/close_account_request"
|
164
|
+
autoload :PatchAccountRequest, "unit/models/account/credit/patch_account_request"
|
165
|
+
autoload :BalanceHistoryRequest, "unit/models/account/credit/balance_history_request"
|
166
|
+
autoload :FreezeAccountRequest, "unit/models/account/credit/freeze_account_request"
|
167
|
+
autoload :ListAccountParams, "unit/models/account/credit/list_account_params"
|
168
|
+
|
169
|
+
class << self
|
170
|
+
# Create a credit account
|
171
|
+
# @see https://docs.unit.co/credit-accounts#create-credit-account
|
172
|
+
# @param credit_terms [String]
|
173
|
+
# @param credit_limit [Integer]
|
174
|
+
# @param customer_id [String] - optional
|
175
|
+
# @param tags [Hash] - optional
|
176
|
+
# @param idempotency_key [String] - optional
|
177
|
+
def create_credit_account(credit_terms:, credit_limit:, customer_id: nil, tags: nil, idempotency_key: nil)
|
178
|
+
request = CreateAccountRequest.new(credit_terms, credit_limit, customer_id, tags, idempotency_key)
|
179
|
+
Unit::Resource::AccountResource.create_account(request)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Close a credit account
|
183
|
+
# @see https://docs.unit.co/credit-accounts#close-account
|
184
|
+
# @param account_id [String]
|
185
|
+
# @param reason [String]
|
186
|
+
# @param fraud_reason [String] - optional
|
187
|
+
def close_credit_account(account_id:, reason:, fraud_reason: nil)
|
188
|
+
request = CloseAccountRequest.new(account_id, reason, fraud_reason)
|
189
|
+
Unit::Resource::AccountResource.close_account(request)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Get a credit account by id
|
193
|
+
# @see https://docs.unit.co/credit-accounts#get-specific-credit-account
|
194
|
+
# @param account_id [String]
|
195
|
+
def get_credit_account(account_id:)
|
196
|
+
Unit::Resource::AccountResource.get_account(account_id)
|
197
|
+
end
|
198
|
+
|
199
|
+
# Freeze credit account
|
200
|
+
# @see https://docs.unit.co/credit-accounts#freeze-account
|
201
|
+
# @param account_id [String]
|
202
|
+
# @param reason [String]
|
203
|
+
# @param reason_text [String] - optional
|
204
|
+
def freeze_credit_account(account_id:, reason:, reason_text: nil)
|
205
|
+
request = FreezeAccountRequest.new(account_id, reason, reason_text)
|
206
|
+
Unit::Resource::AccountResource.freeze_account(request)
|
207
|
+
end
|
208
|
+
|
209
|
+
# Unfreeze credit account
|
210
|
+
# @see https://docs.unit.co/credit-accounts#unfreeze-account
|
211
|
+
# @param account_id [String]
|
212
|
+
def unfreeze_credit_account(account_id:)
|
213
|
+
Unit::Resource::AccountResource.unfreeze_account(account_id)
|
214
|
+
end
|
215
|
+
|
216
|
+
# List credit accounts by calling Unit's API
|
217
|
+
# @see https://docs.unit.co/credit-accounts#list-credit-accounts
|
218
|
+
# @param limit [Integer] - optional
|
219
|
+
# @param offset [Integer] - optional
|
220
|
+
# @param customer_id [String] - optional
|
221
|
+
# @param tags [Hash] - optional
|
222
|
+
# @param status [Array<String>] - optional
|
223
|
+
# @param from_balance [Integer] - optional
|
224
|
+
# @param to_balance [Integer] - optional
|
225
|
+
# @param include [Array] - optional
|
226
|
+
# @param type [String] - optional
|
227
|
+
def list_credit_accounts(limit: ACCOUNT_LIST_LIMIT, offset: ACCOUNT_LIST_OFFSET, customer_id: nil, tags: nil,
|
228
|
+
status: nil, from_balance: nil, to_balance: nil, include: nil, type: nil)
|
229
|
+
request = ListAccountParams.new(limit, offset, customer_id, tags, status, from_balance, to_balance, include, type)
|
230
|
+
Unit::Resource::AccountResource.list_accounts(request)
|
231
|
+
end
|
232
|
+
|
233
|
+
# Update a credit account by calling Unit's API
|
234
|
+
# @see https://docs.unit.co/credit-accounts#update-accounts
|
235
|
+
# @param tags [Hash] - optional
|
236
|
+
# @param credit_limit [Integer] - optional
|
237
|
+
def update_credit_account(account_id:, tags: nil, credit_limit: nil)
|
238
|
+
request = PatchAccountRequest.new(account_id, tags, credit_limit)
|
239
|
+
Unit::Resource::AccountResource.update_account(request)
|
240
|
+
end
|
241
|
+
|
242
|
+
# Limit a credit account
|
243
|
+
# @see https://docs.unit.co/credit-accounts#account-limits
|
244
|
+
# @param account_id [String]
|
245
|
+
def limits(account_id:)
|
246
|
+
Unit::Resource::AccountResource.limits(account_id)
|
247
|
+
end
|
248
|
+
|
249
|
+
# Get account balance history by calling Unit's API
|
250
|
+
# @see https://docs.unit.co/credit-accounts#get-account-balance-history
|
251
|
+
# @param limit [Integer] - optional
|
252
|
+
# @param offset [Integer] - optional
|
253
|
+
# @param account_id [String] - optional
|
254
|
+
# @param customer_id [String] - optional
|
255
|
+
# @param since [String] - optional
|
256
|
+
# @param _until [String] - optional
|
257
|
+
def get_balance_history(limit = BALANCE_HISTORY_LIMIT, offset = BALANCE_HISTORY_OFFSET, account_id: nil, customer_id: nil,
|
258
|
+
since: nil, _until: nil)
|
259
|
+
request = BalanceHistoryRequest.new(limit, offset, account_id, customer_id, since, _until)
|
260
|
+
Unit::Resource::AccountResource.get_account_balance_history(request)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
156
264
|
end
|
157
265
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to get the balance history of a credit account
|
4
|
+
# @see https://docs.unit.co/credit-accounts/#get-account-balance-history
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Credit
|
8
|
+
class BalanceHistoryRequest
|
9
|
+
attr_reader :limit, :offset, :account_id, :customer_id, :since, :_until
|
10
|
+
|
11
|
+
# @param limit [Integer] - optional
|
12
|
+
# @param offset [Integer] - optional
|
13
|
+
# @param account_id [String] - optional
|
14
|
+
# @param customer_id [String] - optional
|
15
|
+
# @param since [String] - optional
|
16
|
+
# @param _until [String] - optional
|
17
|
+
def initialize(limit = BALANCE_HISTORY_LIMIT, offset = BALANCE_HISTORY_OFFSET, account_id = nil, customer_id = nil,
|
18
|
+
since = nil, _until = nil)
|
19
|
+
@limit = limit
|
20
|
+
@offset = offset
|
21
|
+
@account_id = account_id
|
22
|
+
@customer_id = customer_id
|
23
|
+
@since = since
|
24
|
+
@_until = _until
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
params = { "page[limit]": limit,
|
29
|
+
"page[offset]": offset,
|
30
|
+
"filter[accountId]": account_id,
|
31
|
+
"filter[customerId]": customer_id,
|
32
|
+
"filter[since]": since,
|
33
|
+
"filter[until]": _until }
|
34
|
+
params.compact
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to close a credit account
|
4
|
+
# @see https://docs.unit.co/credit-accounts/#close-account
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Credit
|
8
|
+
class CloseAccountRequest
|
9
|
+
attr_reader :account_id, :reason, :fraud_reason
|
10
|
+
|
11
|
+
# @param account_id [String]
|
12
|
+
# @param reason [String]
|
13
|
+
# @param fraud_reason [String] - optional
|
14
|
+
def initialize(account_id, reason, fraud_reason = nil)
|
15
|
+
@account_id = account_id
|
16
|
+
@reason = reason
|
17
|
+
@fraud_reason = fraud_reason
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json_api
|
21
|
+
payload = {
|
22
|
+
data: {
|
23
|
+
type: "creditAccountClose",
|
24
|
+
attributes: {
|
25
|
+
reason: reason,
|
26
|
+
fraudReason: fraud_reason
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
payload[:data][:attributes].compact!
|
31
|
+
payload.to_json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a deposit account
|
4
|
+
# @see https://docs.unit.co/credit-accounts#create-credit-account
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Credit
|
8
|
+
class CreateAccountRequest
|
9
|
+
attr_reader :credit_terms, :credit_limit, :customer_id, :tags, :idempotency_key
|
10
|
+
|
11
|
+
# @param credit_terms [String]
|
12
|
+
# @param credit_limit [Integer]
|
13
|
+
# @param customer_id [String] - optional
|
14
|
+
# @param tags [Hash] - optional
|
15
|
+
# @param idempotency_key [String] - optional
|
16
|
+
def initialize(credit_terms, credit_limit, customer_id = nil, tags = nil, idempotency_key = nil)
|
17
|
+
@credit_terms = credit_terms
|
18
|
+
@credit_limit = credit_limit
|
19
|
+
@customer_id = customer_id
|
20
|
+
@tags = tags
|
21
|
+
@idempotency_key = idempotency_key
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json_api
|
25
|
+
payload = {
|
26
|
+
data: {
|
27
|
+
type: "creditAccount",
|
28
|
+
attributes: {
|
29
|
+
creditTerms: credit_terms,
|
30
|
+
creditLimit: credit_limit,
|
31
|
+
tags: tags
|
32
|
+
},
|
33
|
+
relationships: {
|
34
|
+
customer: Unit::Types::Relationship.new("customer", customer_id).to_hash
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
payload[:data][:attributes].compact!
|
39
|
+
payload.to_json
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to freeze a credit account
|
4
|
+
# @see https://docs.unit.co/credit-accounts#freeze-account
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Credit
|
8
|
+
class FreezeAccountRequest
|
9
|
+
attr_reader :account_id, :reason, :reason_text
|
10
|
+
|
11
|
+
# @param account_id [String]
|
12
|
+
# @param reason [String]
|
13
|
+
# @param reason_text [String] - optional
|
14
|
+
def initialize(account_id, reason, reason_text = nil)
|
15
|
+
@account_id = account_id
|
16
|
+
@reason = reason
|
17
|
+
@reason_text = reason_text
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json_api
|
21
|
+
payload = {
|
22
|
+
data: {
|
23
|
+
type: "creditAccountFreeze",
|
24
|
+
attributes: {
|
25
|
+
reason: reason,
|
26
|
+
reasonText: reason_text
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
payload[:data][:attributes].compact!
|
31
|
+
payload.to_json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# params for listing credit accounts
|
4
|
+
# @see https://docs.unit.co/credit-accounts/#list-credit-accounts
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Credit
|
8
|
+
class ListAccountParams
|
9
|
+
attr_reader :limit, :offset, :customer_id, :tags, :status,
|
10
|
+
:from_balance, :to_balance, :include, :type
|
11
|
+
|
12
|
+
# @param limit [Integer] - optional
|
13
|
+
# @param offset [Integer] - optional
|
14
|
+
# @param customer_id [String] - optional
|
15
|
+
# @param tags [Hash] - optional
|
16
|
+
# @param status [Array<String>] - optional
|
17
|
+
# @param from_balance [Integer] - optional
|
18
|
+
# @param to_balance [Integer] - optional
|
19
|
+
# @param include [Array] - optional
|
20
|
+
# @param type [String] - optional
|
21
|
+
def initialize(limit = ACCOUNT_LIST_LIMIT, offset = ACCOUNT_LIST_OFFSET, customer_id = nil, tags = nil,
|
22
|
+
status = nil, from_balance = nil, to_balance = nil, include = nil, type = nil)
|
23
|
+
@limit = limit
|
24
|
+
@offset = offset
|
25
|
+
@customer_id = customer_id
|
26
|
+
@tags = tags
|
27
|
+
@status = status
|
28
|
+
@from_balance = from_balance
|
29
|
+
@to_balance = to_balance
|
30
|
+
@include = include
|
31
|
+
@type = type
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_hash
|
35
|
+
params = { "page[limit]": limit,
|
36
|
+
"page[offset]": offset,
|
37
|
+
"filter[customerId]": customer_id,
|
38
|
+
"filter[tags]": tags,
|
39
|
+
"filter[fromBalance]": from_balance,
|
40
|
+
"filter[toBalance]": to_balance,
|
41
|
+
"filter[type]": type,
|
42
|
+
"include": include&.join(",") }
|
43
|
+
status&.each_with_index&.map do |val, index|
|
44
|
+
params.merge!({ "filter[status][#{index}]": val })
|
45
|
+
end
|
46
|
+
params.compact
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to update a credit account
|
4
|
+
# @see https://docs.unit.co/credit-accounts#update-accounts
|
5
|
+
module Unit
|
6
|
+
module Account
|
7
|
+
module Credit
|
8
|
+
class PatchAccountRequest
|
9
|
+
attr_reader :account_id, :tags, :credit_limit
|
10
|
+
|
11
|
+
# @param account_id [String]
|
12
|
+
# @param tags [Hash] - optional
|
13
|
+
# @param credit_limit [Integer] - optional
|
14
|
+
def initialize(account_id, tags = nil, credit_limit = nil)
|
15
|
+
@account_id = account_id
|
16
|
+
@tags = tags
|
17
|
+
@credit_limit = credit_limit
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json_api
|
21
|
+
payload = {
|
22
|
+
data: {
|
23
|
+
type: "creditAccount",
|
24
|
+
attributes: {
|
25
|
+
tags: tags,
|
26
|
+
creditLimit: credit_limit
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
payload[:data][:attributes].compact!
|
31
|
+
payload.to_json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|