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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +60 -0
  3. data/lib/unit/api_resources/account_resource.rb +1 -1
  4. data/lib/unit/api_resources/counterparty_resource.rb +65 -0
  5. data/lib/unit/api_resources/payment_resource.rb +24 -5
  6. data/lib/unit/api_resources/transaction_resource.rb +9 -0
  7. data/lib/unit/models/account/account.rb +110 -2
  8. data/lib/unit/models/account/credit/balance_history_request.rb +39 -0
  9. data/lib/unit/models/account/credit/close_account_request.rb +36 -0
  10. data/lib/unit/models/account/credit/create_account_request.rb +44 -0
  11. data/lib/unit/models/account/credit/freeze_account_request.rb +36 -0
  12. data/lib/unit/models/account/credit/list_account_params.rb +51 -0
  13. data/lib/unit/models/account/credit/patch_account_request.rb +36 -0
  14. data/lib/unit/models/counterparty/counterparty.rb +93 -0
  15. data/lib/unit/models/counterparty/create_counterparty_request.rb +56 -0
  16. data/lib/unit/models/counterparty/create_with_plaid_token_request.rb +53 -0
  17. data/lib/unit/models/counterparty/list_counterparty_params.rb +45 -0
  18. data/lib/unit/models/counterparty/update_counterparty_request.rb +40 -0
  19. data/lib/unit/models/payment/create_ach_payment_inline_request.rb +60 -0
  20. data/lib/unit/models/payment/create_payment_linked_request.rb +65 -0
  21. data/lib/unit/models/payment/create_wire_payment_request.rb +44 -0
  22. data/lib/unit/models/payment/create_with_plaid_token_request.rb +69 -0
  23. data/lib/unit/models/payment/get_request.rb +22 -0
  24. data/lib/unit/models/payment/list_payment_params.rb +79 -0
  25. data/lib/unit/models/payment/patch_ach_payment_request.rb +31 -0
  26. data/lib/unit/models/payment/payment.rb +142 -1
  27. data/lib/unit/models/transaction/patch_book_transaction_request.rb +39 -0
  28. data/lib/unit/models/transaction/patch_chargeback_transaction_request.rb +39 -0
  29. data/lib/unit/models/transaction/transaction.rb +24 -0
  30. data/lib/unit/types/counterparty.rb +31 -0
  31. data/lib/unit/types/wire_counterparty.rb +31 -0
  32. data/lib/unit/version.rb +1 -1
  33. data/lib/unit_ruby_sdk.rb +5 -0
  34. metadata +25 -2
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module Counterparty
5
+ COUNTER_PARTY_LIMIT = 100
6
+ COUNTER_PARTY_OFFSET = 0
7
+
8
+ autoload :CreateCounterpartyRequest, "unit/models/counterparty/create_counterparty_request"
9
+ autoload :CreateWithPlaidTokenRequest, "unit/models/counterparty/create_with_plaid_token_request"
10
+ autoload :ListCounterpartyParams, "unit/models/counterparty/list_counterparty_params"
11
+ autoload :UpdateCounterpartyRequest, "unit/models/counterparty/update_counterparty_request"
12
+
13
+ class << self
14
+ # Create counterparty by calling Unit's API
15
+ # @see https://docs.unit.co/payments-counterparties/#create-counterparty
16
+ # @param customer_id [String]
17
+ # @param name [String]
18
+ # @param routing_number [String]
19
+ # @param account_number [String]
20
+ # @param account_type [String]
21
+ # @param type [String]
22
+ # @param tags [Hash] - optional
23
+ # @param permissions [String] - optional
24
+ # @param idempotency_key [String] - optional
25
+ def create_counterparty(customer_id:, name:, routing_number:, account_number:, account_type:, type:, tags: nil, permissions: nil, idempotency_key: nil)
26
+ request = CreateCounterpartyRequest.new(customer_id, name, routing_number, account_number, account_type, type, tags, permissions, idempotency_key)
27
+ Unit::Resource::CounterpartyResource.create_counterparty(request)
28
+ end
29
+
30
+ # Create counterparty with plaid token
31
+ # @see https://docs.unit.co/payments-counterparties/#create-counterparty-with-plaid-token
32
+ # @param customer_id [String]
33
+ # @param type [String]
34
+ # @param name [String]
35
+ # @param plaid_processor_token [String]
36
+ # @param verify_name [Boolean] - optional
37
+ # @param permissions [String] - optional
38
+ # @param tags [Hash] - optional
39
+ # @param idempotency_key [String] - optional
40
+ def create_with_plaid_token(customer_id:, type:, name:, plaid_processor_token:, verify_name: nil, permissions: nil, tags: nil, idempotency_key: nil)
41
+ request = CreateWithPlaidTokenRequest.new(customer_id, type, name, plaid_processor_token, verify_name, permissions, tags, idempotency_key)
42
+ Unit::Resource::CounterpartyResource.create_counterparty(request)
43
+ end
44
+
45
+ # List counterparties
46
+ # @see https://docs.unit.co/payments-counterparties/#list-counterparties
47
+ # @param limit [Integer] - optional
48
+ # @param offset [Integer] - optional
49
+ # @param customer_id [String] - optional
50
+ # @param account_number [String] - optional
51
+ # @param routing_number [String] - optional
52
+ # @param tags [Hash] - optional
53
+ # @param permissions [Array<String>] - optional
54
+ def list_counterparty(limit: COUNTER_PARTY_LIMIT, offset: COUNTER_PARTY_OFFSET, customer_id: nil, account_number: nil, routing_number: nil, tags: nil, permissions: nil)
55
+ params = ListCounterpartyParams.new(limit, offset, customer_id, account_number, routing_number, tags, permissions)
56
+ Unit::Resource::CounterpartyResource.list(params)
57
+ end
58
+
59
+ # Get counterparty by id
60
+ # @param counterparty_id [String]
61
+ # @see https://docs.unit.co/payments-counterparties/#get-one-counterparty
62
+ def get_counterparty(counterparty_id:)
63
+ Unit::Resource::CounterpartyResource.get_counterparty(counterparty_id)
64
+ end
65
+
66
+ # Get counterparty balance
67
+ # @param counterparty_id [String]
68
+ # @see https://docs.unit.co/payments-counterparties/#get-counterparty-balance
69
+ def get_counterparty_balance(counterparty_id:)
70
+ Unit::Resource::CounterpartyResource.get_counterparty_balance(counterparty_id)
71
+ end
72
+
73
+ # Update counterparty
74
+ # @see https://docs.unit.co/payments-counterparties/#list-counterparties
75
+ # @param counterparty_id [String]
76
+ # @param plaid_processor_token [String]
77
+ # @param verify_name [Boolean] - optional
78
+ # @param permissions [String] - optional
79
+ # @param tags [Hash] - optional
80
+ def update_counterparty(counterparty_id:, plaid_processor_token: nil, verify_name: nil, permissions: nil, tags: nil)
81
+ request = UpdateCounterpartyRequest.new(counterparty_id, plaid_processor_token, verify_name, permissions, tags)
82
+ Unit::Resource::CounterpartyResource.update_counterparty(request)
83
+ end
84
+
85
+ # Delete counterparty
86
+ # @param counterparty_id [String]
87
+ # @see https://docs.unit.co/payments-counterparties/#get-one-counterparty
88
+ def delete_counterparty(counterparty_id:)
89
+ Unit::Resource::CounterpartyResource.delete(counterparty_id)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a counterparty
4
+ # @see https://docs.unit.co/payments-counterparties/#create-counterparty
5
+ module Unit
6
+ module Counterparty
7
+ class CreateCounterpartyRequest
8
+ attr_reader :customer_id, :name, :routing_number, :account_number, :account_type,
9
+ :type, :tags, :permissions, :idempotency_key
10
+
11
+ # @param customer_id [String]
12
+ # @param name [String]
13
+ # @param routing_number [String]
14
+ # @param account_number [String]
15
+ # @param account_type [String]
16
+ # @param type [String]
17
+ # @param tags [Hash] - optional
18
+ # @param permissions [String] - optional
19
+ # @param idempotency_key [String] - optional
20
+ def initialize(customer_id, name, routing_number, account_number, account_type, type, tags = nil, permissions = nil, idempotency_key = nil)
21
+ @customer_id = customer_id
22
+ @name = name
23
+ @routing_number = routing_number
24
+ @account_number = account_number
25
+ @account_type = account_type
26
+ @type = type
27
+ @tags = tags
28
+ @permissions = permissions
29
+ @idempotency_key = idempotency_key
30
+ end
31
+
32
+ def to_json_api
33
+ payload = {
34
+ "data": {
35
+ "type": "achCounterparty",
36
+ "attributes": {
37
+ name: name,
38
+ routingNumber: routing_number,
39
+ accountNumber: account_number,
40
+ accountType: account_type,
41
+ type: type,
42
+ tags: tags,
43
+ permissions: permissions,
44
+ idempotencyKey: idempotency_key
45
+ },
46
+ "relationships": {
47
+ customer: Unit::Types::Relationship.new("customer", customer_id).to_hash
48
+ }
49
+ }
50
+ }
51
+ payload[:data][:attributes].compact!
52
+ payload.to_json
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a counterparty with plaid token
4
+ # @see https://docs.unit.co/payments-counterparties/#create-counterparty-with-plaid-token
5
+ module Unit
6
+ module Counterparty
7
+ class CreateWithPlaidTokenRequest
8
+ attr_reader :customer_id, :type, :name, :plaid_processor_token,
9
+ :verify_name, :permissions, :tags, :idempotency_key
10
+
11
+ # @param customer_id [String]
12
+ # @param type [String]
13
+ # @param name [String]
14
+ # @param plaid_processor_token [String]
15
+ # @param verify_name [Boolean] - optional
16
+ # @param permissions [String] - optional
17
+ # @param tags [Hash] - optional
18
+ # @param idempotency_key [String] - optional
19
+ def initialize(customer_id, type, name, plaid_processor_token, verify_name = nil, permissions = nil, tags = nil, idempotency_key = nil)
20
+ @customer_id = customer_id
21
+ @type = type
22
+ @name = name
23
+ @plaid_processor_token = plaid_processor_token
24
+ @verify_name = verify_name
25
+ @permissions = permissions
26
+ @tags = tags
27
+ @idempotency_key = idempotency_key
28
+ end
29
+
30
+ def to_json_api
31
+ payload = {
32
+ "data": {
33
+ "type": "achCounterparty",
34
+ "attributes": {
35
+ type: type,
36
+ name: name,
37
+ plaidProcessorToken: plaid_processor_token,
38
+ verifyName: verify_name,
39
+ permissions: permissions,
40
+ tags: tags,
41
+ idempotencyKey: idempotency_key
42
+ },
43
+ "relationships": {
44
+ customer: Unit::Types::Relationship.new("customer", customer_id).to_hash
45
+ }
46
+ }
47
+ }
48
+ payload[:data][:attributes].compact!
49
+ payload.to_json
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to list counterparties
4
+ # @see https://docs.unit.co/payments-counterparties/#list-counterparties
5
+ module Unit
6
+ module Counterparty
7
+ class ListCounterpartyParams
8
+ attr_reader :limit, :offset, :customer_id, :account_number, :routing_number, :tags, :permissions
9
+
10
+ # @param limit [Integer] - optional
11
+ # @param offset [Integer] - optional
12
+ # @param customer_id [String] - optional
13
+ # @param account_number [String] - optional
14
+ # @param routing_number [String] - optional
15
+ # @param tags [Hash] - optional
16
+ # @param permissions [Array<String>] - optional
17
+ def initialize(limit = COUNTER_PARTY_LIMIT, offset = COUNTER_PARTY_OFFSET, customer_id = nil,
18
+ account_number = nil, routing_number = nil, tags = nil, permissions = nil)
19
+ @limit = limit
20
+ @offset = offset
21
+ @customer_id = customer_id
22
+ @account_number = account_number
23
+ @routing_number = routing_number
24
+ @tags = tags
25
+ @permissions = permissions
26
+ end
27
+
28
+ def to_hash
29
+ params =
30
+ {
31
+ "page[limit]": limit,
32
+ "page[offset]": offset,
33
+ "filter[customerId]": customer_id,
34
+ "filter[accountNumber]": account_number,
35
+ "filter[routingNumber]": routing_number,
36
+ "filter[tags]": tags
37
+ }
38
+ permissions&.each_with_index&.map do |val, index|
39
+ params.merge!({ "filter[permissions][#{index}]": val })
40
+ end
41
+ params.compact
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to update a counterparty
4
+ # @see https://docs.unit.co/payments-counterparties/#list-counterparties
5
+ module Unit
6
+ module Counterparty
7
+ class UpdateCounterpartyRequest
8
+ attr_reader :counterparty_id, :plaid_processor_token, :verify_name, :permissions, :tags
9
+
10
+ # @param counterparty_id [String]
11
+ # @param plaid_processor_token [String]
12
+ # @param verify_name [Boolean] - optional
13
+ # @param permissions [String] - optional
14
+ # @param tags [Hash] - optional
15
+ def initialize(counterparty_id, plaid_processor_token, verify_name = nil, permissions = nil, tags = nil)
16
+ @counterparty_id = counterparty_id
17
+ @plaid_processor_token = plaid_processor_token
18
+ @verify_name = verify_name
19
+ @permissions = permissions
20
+ @tags = tags
21
+ end
22
+
23
+ def to_json_api
24
+ payload = {
25
+ "data": {
26
+ "type": "counterparty",
27
+ attributes: {
28
+ plaidProcessorToken: plaid_processor_token,
29
+ verifyName: verify_name,
30
+ permissions: permissions,
31
+ tags: tags
32
+ }
33
+ }
34
+ }
35
+ payload[:data][:attributes].compact!
36
+ payload.to_json
37
+ end
38
+ end
39
+ end
40
+ 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
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a wire payment by calling Unit's API
4
+ # @see https://docs.unit.co/wires#wire-payments
5
+ module Unit
6
+ module Payment
7
+ class CreateWirePaymentRequest
8
+ attr_reader :account_id, :amount, :description, :counterparty, :idempotency_key, :tags
9
+
10
+ # @param account_id [String]
11
+ # @param amount [Integer]
12
+ # @param description [String]
13
+ # @param counterparty [WireCounterparty]
14
+ # @param idempotency_key [String] - optional
15
+ # @param tags [Hash] - optional
16
+ def initialize(account_id, amount, description, counterparty, idempotency_key = nil, tags = nil)
17
+ @account_id = account_id
18
+ @amount = amount
19
+ @description = description
20
+ @counterparty = counterparty
21
+ @idempotency_key = idempotency_key
22
+ @tags = tags
23
+ end
24
+
25
+ def to_json_api
26
+ payload = {
27
+ data: {
28
+ type: "wirePayment",
29
+ attributes: {
30
+ amount: amount,
31
+ description: description,
32
+ counterparty: counterparty.represent,
33
+ idempotencyKey: idempotency_key,
34
+ tags: tags
35
+ },
36
+ relationships: { account: Unit::Types::Relationship.new("account", account_id).to_hash }
37
+ }
38
+ }
39
+ payload[:data][:attributes].compact!
40
+ payload.to_json
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a new ach payment with a plaid token by calling Unit's API
4
+ # @see https://docs.unit.co/ach-origination#create-ach-payment-with-plaid-token
5
+ module Unit
6
+ module Payment
7
+ class CreateWithPlaidTokenRequest
8
+ attr_reader :account_id, :amount, :direction, :description,
9
+ :plaid_processor_token, :addenda, :idempotency_key,
10
+ :counterparty_name, :tags, :verify_counterparty_balance,
11
+ :same_day, :sec_code
12
+
13
+ # @param account_id [String]
14
+ # @param amount [Integer]
15
+ # @param direction [String]
16
+ # @param description [String]
17
+ # @param plaid_processor_token [String]
18
+ # @param addenda [String] - optional
19
+ # @param idempotency_key [String] - optional
20
+ # @param counterparty_name [String] - optional
21
+ # @param tags [Hash] - optional
22
+ # @param verify_counterparty_balance [Boolean] - optional
23
+ # @param same_day [Boolean] - optional
24
+ # @param sec_code [String] - optional
25
+ def initialize(account_id, amount, direction, description, plaid_processor_token,
26
+ addenda = nil, idempotency_key = nil, counterparty_name = nil, tags = nil,
27
+ verify_counterparty_balance = nil, same_day = nil, sec_code = nil)
28
+ @account_id = account_id
29
+ @amount = amount
30
+ @direction = direction
31
+ @description = description
32
+ @plaid_processor_token = plaid_processor_token
33
+ @addenda = addenda
34
+ @idempotency_key = idempotency_key
35
+ @counterparty_name = counterparty_name
36
+ @tags = tags
37
+ @verify_counterparty_balance = verify_counterparty_balance
38
+ @same_day = same_day
39
+ @sec_code = sec_code
40
+ end
41
+
42
+ def to_json_api
43
+ payload = {
44
+ "data": {
45
+ "type": "achPayment",
46
+ "attributes": {
47
+ amount: amount,
48
+ direction: direction,
49
+ description: description,
50
+ plaidProcessorToken: plaid_processor_token,
51
+ addenda: addenda,
52
+ idempotencyKey: idempotency_key,
53
+ counterpartyName: counterparty_name,
54
+ tags: tags,
55
+ verifyCounterpartyBalance: verify_counterparty_balance,
56
+ sameDay: same_day,
57
+ secCode: sec_code
58
+ },
59
+ "relationships": {
60
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash
61
+ }
62
+ }
63
+ }
64
+ payload[:data][:attributes].compact!
65
+ payload.to_json
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to get payment by id
4
+ # @see https://docs.unit.co/payments#get-specific-payment
5
+ module Unit
6
+ module Payment
7
+ class GetRequest
8
+ attr_reader :payment_id, :include
9
+
10
+ # @param payment_id [String]
11
+ # @param include [Array<String>] - optional
12
+ def initialize(payment_id, include = nil)
13
+ @payment_id = payment_id
14
+ @include = include
15
+ end
16
+
17
+ def to_hash
18
+ { include: include&.join(",") }.compact
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Params to list payments
4
+ # @see https://docs.unit.co/payments#list-payments
5
+
6
+ module Unit
7
+ module Payment
8
+ class ListPaymentParams
9
+ attr_reader :limit, :offset, :account_id, :customer_id, :counterparty_account_id, :tags, :status, :type, :direction, :since, :_until, :from_amount, :to_amount, :recurring_payment_id, :feature, :sort, :include
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 counterparty_account_id [String] - optional
16
+ # @param tags [Hash] - optional
17
+ # @param status [Array<String>] - optional
18
+ # @param type [Array<String>] - optional
19
+ # @param direction [Array<String>] - optional
20
+ # @param since [String] - optional
21
+ # @param _until [String] - optional
22
+ # @param from_amount [Integer] - optional
23
+ # @param to_amount [Integer] - optional
24
+ # @param recurring_payment_id [String] - optional
25
+ # @param feature [Array<String>] - optional
26
+ # @param sort [String] - optional
27
+ # @param include [Array<String>] - optional
28
+ def initialize(limit = PAYMENT_LIMIT, offset = PAYMENT_OFFSET, account_id = nil, customer_id = nil,
29
+ counterparty_account_id = nil, tags = nil, status = nil,
30
+ type = nil, direction = nil, since = nil, _until = nil,
31
+ from_amount = nil, to_amount = nil, recurring_payment_id = nil,
32
+ feature = nil, sort = nil, include = nil)
33
+ @limit = limit
34
+ @offset = offset
35
+ @account_id = account_id
36
+ @customer_id = customer_id
37
+ @counterparty_account_id = counterparty_account_id
38
+ @tags = tags
39
+ @status = status
40
+ @type = type
41
+ @direction = direction
42
+ @since = since
43
+ @until = _until
44
+ @from_amount = from_amount
45
+ @to_amount = to_amount
46
+ @recurring_payment_id = recurring_payment_id
47
+ @feature = feature
48
+ @sort = sort
49
+ @include = include
50
+ end
51
+
52
+ def to_hash
53
+ params = {
54
+ "page[limit]": limit,
55
+ "page[offset]": offset,
56
+ "filter[accountId]": account_id,
57
+ "filter[customerId]": customer_id,
58
+ "filter[counterpartyAccountId]": counterparty_account_id,
59
+ "filter[tags]": tags,
60
+ "filter[since]": since,
61
+ "filter[until]": _until,
62
+ "filter[fromAmount]": from_amount,
63
+ "filter[toAmount]": to_amount,
64
+ "filter[recurringPaymentId]": recurring_payment_id,
65
+ sort: sort,
66
+ include: include&.join(",")
67
+ }
68
+ filters = %i[status type direction feature]
69
+ filters.each do |filter|
70
+ values = send(filter)
71
+ values&.each_with_index&.map do |val, index|
72
+ params.merge!({ "filter[#{filter}][#{index}]": val })
73
+ end
74
+ end
75
+ params.compact
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to update an ACH payment
4
+ # @see https://docs.unit.co/ach-origination#update-ach-payment
5
+ module Unit
6
+ module Payment
7
+ class PatchAchPaymentRequest
8
+ attr_reader :payment_id, :tags
9
+
10
+ # @param payment_id [String]
11
+ # @param tags [Hash] - optional
12
+ def initialize(payment_id, tags = nil)
13
+ @payment_id = payment_id
14
+ @tags = tags
15
+ end
16
+
17
+ def to_json_api
18
+ payload = {
19
+ "data": {
20
+ "type": "achPayment",
21
+ "attributes": {
22
+ tags: tags
23
+ }
24
+ }
25
+ }
26
+ payload[:data][:attributes].compact!
27
+ payload.to_json
28
+ end
29
+ end
30
+ end
31
+ end