unit_ruby_sdk 1.0.3 → 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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -0
  3. data/lib/unit/api_resources/account_resource.rb +1 -1
  4. data/lib/unit/api_resources/payment_resource.rb +24 -5
  5. data/lib/unit/api_resources/transaction_resource.rb +9 -0
  6. data/lib/unit/models/account/account.rb +108 -0
  7. data/lib/unit/models/account/credit/balance_history_request.rb +39 -0
  8. data/lib/unit/models/account/credit/close_account_request.rb +36 -0
  9. data/lib/unit/models/account/credit/create_account_request.rb +44 -0
  10. data/lib/unit/models/account/credit/freeze_account_request.rb +36 -0
  11. data/lib/unit/models/account/credit/list_account_params.rb +51 -0
  12. data/lib/unit/models/account/credit/patch_account_request.rb +36 -0
  13. data/lib/unit/models/payment/create_ach_payment_inline_request.rb +60 -0
  14. data/lib/unit/models/payment/create_payment_linked_request.rb +65 -0
  15. data/lib/unit/models/payment/create_wire_payment_request.rb +44 -0
  16. data/lib/unit/models/payment/create_with_plaid_token_request.rb +69 -0
  17. data/lib/unit/models/payment/get_request.rb +22 -0
  18. data/lib/unit/models/payment/list_payment_params.rb +79 -0
  19. data/lib/unit/models/payment/patch_ach_payment_request.rb +31 -0
  20. data/lib/unit/models/payment/payment.rb +142 -1
  21. data/lib/unit/models/transaction/patch_book_transaction_request.rb +39 -0
  22. data/lib/unit/models/transaction/patch_chargeback_transaction_request.rb +39 -0
  23. data/lib/unit/models/transaction/transaction.rb +24 -0
  24. data/lib/unit/types/counterparty.rb +31 -0
  25. data/lib/unit/types/wire_counterparty.rb +31 -0
  26. data/lib/unit/version.rb +1 -1
  27. data/lib/unit_ruby_sdk.rb +2 -0
  28. metadata +19 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf85eb968fc7cac1337e5093a9c5998a98997ad7f37956e79c45498785b08ffb
4
- data.tar.gz: e60405762229150510a2e82b76d25aecc547c009c287ca694ef95611e2319c28
3
+ metadata.gz: 5b262e1336d0a6f1e2a6633172d3fe0fb030eb658e3a30ced02803e6f00bd22d
4
+ data.tar.gz: cbcb03bfba7390d4b27e5b1485d5f60c66fbc50104d4066764c482a3fd2ecb12
5
5
  SHA512:
6
- metadata.gz: 91ea490c2a75df07cf37281fc32aef9965767fbbcbe12b035a8caf500e3fd08bd23dc2b8eb5c522eef2491885a13c4053ad9c3b0c906925ea077c42ab27c4452
7
- data.tar.gz: 4c687d3bd7a49d5c0bf4c113b20aabf42e1fcfec5381165ced6fb5f45825565bd5ab058529c97224d6d3680df936663589f02011de0b2b636429af8174b37d29
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
@@ -133,6 +155,32 @@ counterparty = response.data
133
155
  puts counterparty.id
134
156
  ```
135
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
+
136
184
  ### Logging Errors
137
185
 
138
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.to_json, headers: headers)
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
 
@@ -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 book payments to Unit API and parsing responses
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 book payment by calling Unit's API
13
- # @param request [CreatePaymentRequest]
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 book payment by calling Unit's API
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
@@ -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
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a new ach payment to inline counterparty by calling Unit's API
4
+ # @see https://docs.unit.co/ach-origination#payment-inline-counterparty
5
+ module Unit
6
+ module Payment
7
+ class CreateAchPaymentInlineRequest
8
+ attr_reader :account_id, :amount, :direction, :counterparty, :description,
9
+ :addenda, :idempotency_key, :tags, :same_day, :sec_code
10
+
11
+ # @param account_id [String]
12
+ # @param amount [Integer]
13
+ # @param direction [String]
14
+ # @param counterparty [Counterparty]
15
+ # @param description [String]
16
+ # @param addenda [String] - optional
17
+ # @param idempotency_key [String] - optional
18
+ # @param tags [Hash] - optional
19
+ # @param same_day [Boolean] - optional
20
+ # @param sec_code [String] - optional
21
+ def initialize(account_id, amount, direction, counterparty, description,
22
+ addenda = nil, idempotency_key = nil, tags = nil, same_day = nil, sec_code = nil)
23
+ @account_id = account_id
24
+ @amount = amount
25
+ @direction = direction
26
+ @counterparty = counterparty
27
+ @description = description
28
+ @addenda = addenda
29
+ @idempotency_key = idempotency_key
30
+ @tags = tags
31
+ @same_day = same_day
32
+ @sec_code = sec_code
33
+ end
34
+
35
+ def to_json_api
36
+ payload = {
37
+ "data": {
38
+ "type": "achPayment",
39
+ "attributes": {
40
+ amount: amount,
41
+ direction: direction,
42
+ counterparty: counterparty.represent,
43
+ description: description,
44
+ addenda: addenda,
45
+ idempotencyKey: idempotency_key,
46
+ tags: tags,
47
+ sameDay: same_day,
48
+ secCode: sec_code
49
+ },
50
+ "relationships": {
51
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash
52
+ }
53
+ }
54
+ }
55
+ payload[:data][:attributes].compact!
56
+ payload.to_json
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a new ach payment to linked counterparty by calling Unit's API
4
+ # @see https://docs.unit.co/ach-origination#payment-linked-counterparty
5
+ module Unit
6
+ module Payment
7
+ class CreatePaymentLinkedRequest
8
+ attr_reader :account_id, :counterparty_id, :amount, :direction, :description,
9
+ :addenda, :idempotency_key, :tags, :verify_counterparty_balance,
10
+ :same_day, :sec_code
11
+
12
+ # @param account_id [String]
13
+ # @param counterparty_id [String]
14
+ # @param amount [Integer]
15
+ # @param direction [String]
16
+ # @param description [String]
17
+ # @param addenda [String] - optional
18
+ # @param idempotency_key [String] - optional
19
+ # @param tags [Hash] - optional
20
+ # @param verify_counterparty_balance [Boolean] - optional
21
+ # @param same_day [Boolean] - optional
22
+ # @param sec_code [String] - optional
23
+ def initialize(account_id, counterparty_id, amount, direction, description,
24
+ addenda = nil, idempotency_key = nil, tags = nil, verify_counterparty_balance = nil,
25
+ same_day = nil, sec_code = nil)
26
+ @account_id = account_id
27
+ @counterparty_id = counterparty_id
28
+ @amount = amount
29
+ @direction = direction
30
+ @description = description
31
+ @addenda = addenda
32
+ @idempotency_key = idempotency_key
33
+ @tags = tags
34
+ @verify_counterparty_balance = verify_counterparty_balance
35
+ @same_day = same_day
36
+ @sec_code = sec_code
37
+ end
38
+
39
+ def to_json_api
40
+ payload = {
41
+ "data": {
42
+ "type": "achPayment",
43
+ "attributes": {
44
+ amount: amount,
45
+ direction: direction,
46
+ description: description,
47
+ addenda: addenda,
48
+ idempotencyKey: idempotency_key,
49
+ tags: tags,
50
+ verifyCounterpartyBalance: verify_counterparty_balance,
51
+ sameDay: same_day,
52
+ secCode: sec_code
53
+ },
54
+ "relationships": {
55
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash,
56
+ "counterparty": Unit::Types::Relationship.new("counterparty", counterparty_id).to_hash
57
+ }
58
+ }
59
+ }
60
+ payload[:data][:attributes].compact!
61
+ payload.to_json
62
+ end
63
+ end
64
+ end
65
+ end