unit_ruby_sdk 1.0.5 → 1.2.0

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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +190 -19
  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 +17 -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/bulk_payment_request.rb +15 -0
  50. data/lib/unit/models/payment/create_ach_payment_inline_request.rb +29 -19
  51. data/lib/unit/models/payment/create_batch_release_request.rb +54 -0
  52. data/lib/unit/models/payment/create_book_payment_request.rb +24 -14
  53. data/lib/unit/models/payment/create_payment_linked_request.rb +31 -21
  54. data/lib/unit/models/payment/create_wire_payment_request.rb +22 -12
  55. data/lib/unit/models/payment/create_with_plaid_token_request.rb +32 -22
  56. data/lib/unit/models/payment/payment.rb +40 -12
  57. data/lib/unit/models/received_payment/list_payment_params.rb +51 -0
  58. data/lib/unit/models/received_payment/patch_payment_request.rb +31 -0
  59. data/lib/unit/models/received_payment/received_payment.rb +54 -0
  60. data/lib/unit/models/recurring_payment/create_recurring_credit_ach_payment_request.rb +52 -0
  61. data/lib/unit/models/recurring_payment/create_recurring_credit_book_payment_request.rb +54 -0
  62. data/lib/unit/models/recurring_payment/create_recurring_debit_ach_payment_request.rb +60 -0
  63. data/lib/unit/models/recurring_payment/list_recurring_payment_params.rb +60 -0
  64. data/lib/unit/models/recurring_payment/recurring_payment.rb +106 -0
  65. data/lib/unit/models/repayment/create_ach_repayment_request.rb +57 -0
  66. data/lib/unit/models/repayment/create_book_repayment_request.rb +53 -0
  67. data/lib/unit/models/repayment/list_repayment_params.rb +48 -0
  68. data/lib/unit/models/repayment/repayment.rb +67 -0
  69. data/lib/unit/models/reward/create_reward_request.rb +49 -0
  70. data/lib/unit/models/reward/get_request.rb +22 -0
  71. data/lib/unit/models/reward/list_reward_params.rb +65 -0
  72. data/lib/unit/models/reward/reward.rb +55 -0
  73. data/lib/unit/models/unit_response.rb +1 -1
  74. data/lib/unit/models/webhook/create_webhook_request.rb +49 -0
  75. data/lib/unit/models/webhook/list_webhook_params.rb +39 -0
  76. data/lib/unit/models/webhook/patch_webhook_request.rb +47 -0
  77. data/lib/unit/models/webhook/webhook.rb +80 -0
  78. data/lib/unit/types/application_form_prefill.rb +84 -0
  79. data/lib/unit/types/application_form_settings_override.rb +51 -0
  80. data/lib/unit/types/beneficial_owner.rb +15 -10
  81. data/lib/unit/types/beneficiary.rb +25 -0
  82. data/lib/unit/types/create_schedule.rb +38 -0
  83. data/lib/unit/types/evaluation_params.rb +4 -4
  84. data/lib/unit/types/grantor.rb +37 -0
  85. data/lib/unit/types/officer.rb +26 -13
  86. data/lib/unit/types/power_of_attorney_agent.rb +5 -12
  87. data/lib/unit/types/require_id_verification.rb +29 -0
  88. data/lib/unit/types/trust_contact.rb +34 -0
  89. data/lib/unit/types/trustee.rb +37 -0
  90. data/lib/unit/version.rb +1 -1
  91. data/lib/unit_ruby_sdk.rb +28 -0
  92. metadata +67 -2
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a batch release
4
+ # @see https://docs.unit.co/batch-payments/#create-batch-releases
5
+ module Unit
6
+ module Payment
7
+ class CreateBatchReleaseRequest
8
+ attr_reader :account_id, :batch_account_id, :amount, :description, :sender_name, :sender_address,
9
+ :sender_account_number, :tags, :idempotency_key
10
+
11
+ # @param account_id [String]
12
+ # @param batch_account_id [String]
13
+ # @param amount [Integer]
14
+ # @param description [String]
15
+ # @param sender_name [String]
16
+ # @param sender_address [Address]
17
+ # @param sender_account_number [String]
18
+ # @param tags [Hash] - optional
19
+ # @param idempotency_key [String] - optional
20
+ def initialize(account_id, batch_account_id, amount, description, sender_name, sender_address, sender_account_number, tags = nil, idempotency_key = nil)
21
+ @account_id = account_id
22
+ @batch_account_id = batch_account_id
23
+ @amount = amount
24
+ @description = description
25
+ @sender_name = sender_name
26
+ @sender_address = sender_address
27
+ @sender_account_number = sender_account_number
28
+ @tags = tags
29
+ @idempotency_key = idempotency_key
30
+ end
31
+
32
+ def to_hash
33
+ payload = {
34
+ "type": "batchRelease",
35
+ "attributes": {
36
+ "amount": amount,
37
+ "description": description,
38
+ "senderName": sender_name,
39
+ "senderAddress": sender_address&.represent,
40
+ "senderAccountNumber": sender_account_number,
41
+ "tags": tags,
42
+ "idempotencyKey": idempotency_key
43
+ },
44
+ "relationships": {
45
+ "batchAccount": Unit::Types::Relationship.new("batchAccount", batch_account_id).to_hash,
46
+ "receiver": Unit::Types::Relationship.new("depositAccount", account_id).to_hash
47
+ }
48
+ }
49
+ payload[:attributes].compact!
50
+ payload
51
+ end
52
+ end
53
+ end
54
+ end
@@ -14,8 +14,8 @@ module Unit
14
14
  # @param transaction_summary_override [String] - optional
15
15
  # @param idempotency_key [String] - optional
16
16
  # @param tags [Hash] - optional
17
- def initialize(amount, description, account_id, counterparty_account_id, transaction_summary_override = nil,
18
- idempotency_key = nil, tags = nil)
17
+ def initialize(amount:, description:, account_id:, counterparty_account_id:, transaction_summary_override: nil,
18
+ idempotency_key: nil, tags: nil)
19
19
  @amount = amount
20
20
  @description = description
21
21
  @account_id = account_id
@@ -27,22 +27,32 @@ module Unit
27
27
 
28
28
  def to_json_api
29
29
  payload = {
30
- data: {
31
- type: "bookPayment",
32
- attributes: {
33
- amount: amount,
34
- description: description,
35
- transactionSummaryOverride: transaction_summary_override,
36
- idempotencyKey: idempotency_key,
37
- tags: tags
38
- },
39
- relationships: { account: Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
40
- counterpartyAccount: Unit::Types::Relationship.new("depositAccount", counterparty_account_id).to_hash }
41
- }
30
+ data: to_hash
42
31
  }
43
32
  payload[:data][:attributes].compact!
44
33
  payload.to_json
45
34
  end
35
+
36
+ def to_hash
37
+ {
38
+ type: "bookPayment",
39
+ attributes: {
40
+ amount: amount,
41
+ description: description,
42
+ transactionSummaryOverride: transaction_summary_override,
43
+ idempotencyKey: idempotency_key,
44
+ tags: tags
45
+ },
46
+ relationships: { account: Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
47
+ counterpartyAccount: Unit::Types::Relationship.new("depositAccount", counterparty_account_id).to_hash }
48
+ }
49
+ end
50
+
51
+ def change_attributes
52
+ payload = to_hash
53
+ payload[:attributes].compact!
54
+ payload
55
+ end
46
56
  end
47
57
  end
48
58
  end
@@ -20,9 +20,9 @@ module Unit
20
20
  # @param verify_counterparty_balance [Boolean] - optional
21
21
  # @param same_day [Boolean] - optional
22
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)
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
26
  @account_id = account_id
27
27
  @counterparty_id = counterparty_id
28
28
  @amount = amount
@@ -38,28 +38,38 @@ module Unit
38
38
 
39
39
  def to_json_api
40
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
- }
41
+ "data": to_hash
59
42
  }
60
43
  payload[:data][:attributes].compact!
61
44
  payload.to_json
62
45
  end
46
+
47
+ def to_hash
48
+ {
49
+ "type": "achPayment",
50
+ "attributes": {
51
+ amount: amount,
52
+ direction: direction,
53
+ description: description,
54
+ addenda: addenda,
55
+ idempotencyKey: idempotency_key,
56
+ tags: tags,
57
+ verifyCounterpartyBalance: verify_counterparty_balance,
58
+ sameDay: same_day,
59
+ secCode: sec_code
60
+ },
61
+ "relationships": {
62
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash,
63
+ "counterparty": Unit::Types::Relationship.new("counterparty", counterparty_id).to_hash
64
+ }
65
+ }
66
+ end
67
+
68
+ def change_attributes
69
+ payload = to_hash
70
+ payload[:attributes].compact!
71
+ payload
72
+ end
63
73
  end
64
74
  end
65
75
  end
@@ -13,7 +13,7 @@ module Unit
13
13
  # @param counterparty [WireCounterparty]
14
14
  # @param idempotency_key [String] - optional
15
15
  # @param tags [Hash] - optional
16
- def initialize(account_id, amount, description, counterparty, idempotency_key = nil, tags = nil)
16
+ def initialize(account_id:, amount:, description:, counterparty:, idempotency_key: nil, tags: nil)
17
17
  @account_id = account_id
18
18
  @amount = amount
19
19
  @description = description
@@ -24,21 +24,31 @@ module Unit
24
24
 
25
25
  def to_json_api
26
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
- }
27
+ data: to_hash
38
28
  }
39
29
  payload[:data][:attributes].compact!
40
30
  payload.to_json
41
31
  end
32
+
33
+ def to_hash
34
+ {
35
+ type: "wirePayment",
36
+ attributes: {
37
+ amount: amount,
38
+ description: description,
39
+ counterparty: counterparty.represent,
40
+ idempotencyKey: idempotency_key,
41
+ tags: tags
42
+ },
43
+ relationships: { account: Unit::Types::Relationship.new("account", account_id).to_hash }
44
+ }
45
+ end
46
+
47
+ def change_attributes
48
+ payload = to_hash
49
+ payload[:attributes].compact!
50
+ payload
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -22,9 +22,9 @@ module Unit
22
22
  # @param verify_counterparty_balance [Boolean] - optional
23
23
  # @param same_day [Boolean] - optional
24
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)
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
28
  @account_id = account_id
29
29
  @amount = amount
30
30
  @direction = direction
@@ -41,29 +41,39 @@ module Unit
41
41
 
42
42
  def to_json_api
43
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
- }
44
+ "data": to_hash
63
45
  }
64
46
  payload[:data][:attributes].compact!
65
47
  payload.to_json
66
48
  end
49
+
50
+ def to_hash
51
+ {
52
+ "type": "achPayment",
53
+ "attributes": {
54
+ amount: amount,
55
+ direction: direction,
56
+ description: description,
57
+ plaidProcessorToken: plaid_processor_token,
58
+ addenda: addenda,
59
+ idempotencyKey: idempotency_key,
60
+ counterpartyName: counterparty_name,
61
+ tags: tags,
62
+ verifyCounterpartyBalance: verify_counterparty_balance,
63
+ sameDay: same_day,
64
+ secCode: sec_code
65
+ },
66
+ "relationships": {
67
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash
68
+ }
69
+ }
70
+ end
71
+
72
+ def change_attributes
73
+ payload = to_hash
74
+ payload[:attributes].compact!
75
+ payload
76
+ end
67
77
  end
68
78
  end
69
79
  end
@@ -13,6 +13,9 @@ module Unit
13
13
  autoload :CreateWirePaymentRequest, "unit/models/payment/create_wire_payment_request"
14
14
  autoload :ListPaymentParams, "unit/models/payment/list_payment_params"
15
15
  autoload :GetRequest, "unit/models/payment/get_request"
16
+ autoload :BulkPaymentRequest, "unit/models/payment/bulk_payment_request"
17
+ autoload :CreateBatchReleaseRequest, "unit/models/payment/create_batch_release_request"
18
+ autoload :BatchReleaseRequestBuilder, "unit/models/payment/batch_release_request_builder"
16
19
  class << self
17
20
  # Create a new book payment by calling Unit's API
18
21
  # @see https://docs.unit.co/book-payments#book-payments
@@ -26,8 +29,9 @@ module Unit
26
29
  # @return [UnitResponse, UnitError]
27
30
  def create_book_payment(amount:, description:, account_id:, counterparty_account_id:, transaction_summary_override: nil,
28
31
  idempotency_key: nil, tags: nil)
29
- request = Unit::Payment::CreateBookPaymentRequest.new(amount, description, account_id, counterparty_account_id, transaction_summary_override,
30
- idempotency_key, tags)
32
+ request = Unit::Payment::CreateBookPaymentRequest.new(amount: amount, description: description, account_id: account_id, counterparty_account_id: counterparty_account_id, transaction_summary_override: transaction_summary_override,
33
+ idempotency_key: idempotency_key, tags: tags)
34
+
31
35
  Unit::Resource::PaymentResource.create_payment(request)
32
36
  end
33
37
 
@@ -56,8 +60,8 @@ module Unit
56
60
  def create_ach_payment_inline(account_id:, amount:, direction:, counterparty:,
57
61
  description:, addenda: nil, idempotency_key: nil, tags: nil,
58
62
  same_day: nil, sec_code: nil)
59
- request = Unit::Payment::CreateAchPaymentInlineRequest.new(account_id, amount, direction, counterparty, description,
60
- addenda, idempotency_key, tags, same_day, sec_code)
63
+ request = Unit::Payment::CreateAchPaymentInlineRequest.new(account_id: account_id, amount: amount, direction: direction, counterparty: counterparty, description: description, addenda: addenda, idempotency_key: idempotency_key,
64
+ tags: tags, same_day: same_day, sec_code: sec_code)
61
65
  Unit::Resource::PaymentResource.create_payment(request)
62
66
  end
63
67
 
@@ -77,9 +81,8 @@ module Unit
77
81
  def create_ach_payment_linked(account_id:, counterparty_id:, amount:, direction:,
78
82
  description:, addenda: nil, idempotency_key: nil, tags: nil,
79
83
  verify_counterparty_balance: nil, same_day: nil, sec_code: nil)
80
- request = Unit::Payment::CreatePaymentLinkedRequest.new(account_id, counterparty_id, amount, direction,
81
- description, addenda, idempotency_key, tags,
82
- verify_counterparty_balance, same_day, sec_code)
84
+ request = Unit::Payment::CreatePaymentLinkedRequest.new(account_id: account_id, counterparty_id: counterparty_id, amount: amount, direction: direction, description: description, addenda: addenda, idempotency_key: idempotency_key,
85
+ tags: tags, verify_counterparty_balance: verify_counterparty_balance, same_day: same_day, sec_code: sec_code)
83
86
  Unit::Resource::PaymentResource.create_payment(request)
84
87
  end
85
88
 
@@ -100,9 +103,8 @@ module Unit
100
103
  def create_ach_payment_with_plaid_token(account_id:, amount:, direction:, description:, plaid_processor_token:,
101
104
  addenda: nil, idempotency_key: nil, counterparty_name: nil, tags: nil,
102
105
  verify_counterparty_balance: nil, same_day: nil, sec_code: nil)
103
- request = Unit::Payment::CreateWithPlaidTokenRequest.new(account_id, amount, direction, description, plaid_processor_token,
104
- addenda, idempotency_key, counterparty_name, tags,
105
- verify_counterparty_balance, same_day, sec_code)
106
+ request = Unit::Payment::CreateWithPlaidTokenRequest.new(account_id: account_id, amount: amount, direction: direction, description: description, plaid_processor_token: plaid_processor_token, addenda: addenda, idempotency_key: idempotency_key,
107
+ counterparty_name: counterparty_name, tags: tags, verify_counterparty_balance: verify_counterparty_balance, same_day: same_day, sec_code: sec_code)
106
108
  Unit::Resource::PaymentResource.create_payment(request)
107
109
  end
108
110
 
@@ -131,7 +133,7 @@ module Unit
131
133
  # @param idempotency_key [String] - optional
132
134
  # @param tags [Hash] - optional
133
135
  def create_wire_payment(account_id:, amount:, description:, counterparty:, idempotency_key: nil, tags: nil)
134
- request = Unit::Payment::CreateWirePaymentRequest.new(account_id, amount, description, counterparty, idempotency_key, tags)
136
+ request = Unit::Payment::CreateWirePaymentRequest.new(account_id: account_id, amount: amount, description: description, counterparty: counterparty, idempotency_key: idempotency_key, tags: tags)
135
137
  Unit::Resource::PaymentResource.create_payment(request)
136
138
  end
137
139
 
@@ -173,6 +175,32 @@ module Unit
173
175
  request = Unit::Payment::GetRequest.new(payment_id, include)
174
176
  Unit::Resource::PaymentResource.get_payment(request)
175
177
  end
176
- end
178
+
179
+ # Create a bulk payment by calling Unit's API
180
+ # @see https://docs.unit.co/payments/#bulk-payments
181
+ # @param requests [Array<CreateAchPaymentInlineRequest, CreatePaymentLinkedRequest, CreateBookPaymentRequest, CreateWithPlaidTokenRequest, CreateWirePaymentRequest>]
182
+ def create_bulk_payment(requests:)
183
+ request = Unit::Payment::BulkPaymentRequest.serialize(requests)
184
+ Unit::Resource::PaymentResource.create_bulk_payment(request)
185
+ end
186
+
187
+ # Create a batch release
188
+ # @see https://docs.unit.co/batch-payments/#create-batch-releases
189
+ # @param account_id [String]
190
+ # @param amount [Integer]
191
+ # @param description [String]
192
+ # @param sender_name [String]
193
+ # @param sender_address [Address]
194
+ # @param sender_account_number [String]
195
+ # @param tags [Hash] - optional
196
+ # @param idempotency_key [String] - optional
197
+ def create_batch_release(requests)
198
+ payload = BatchReleaseRequestBuilder.new
199
+ requests.each do |req|
200
+ payload.add_request(req[:account_id], req[:batch_account_id], req[:amount], req[:description], req[:sender_name], req[:sender_address], req[:sender_account_number], req[:tags], req[:idempotency_key])
201
+ end
202
+ Unit::Resource::PaymentResource.create_batch_release(payload.to_hash)
203
+ end
204
+ end
177
205
  end
178
206
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to list ach received payments by calling Unit's API
4
+ # @see https://docs.unit.co/received-ach#list-received-payments
5
+ module Unit
6
+ module ReceivedPayment
7
+ class ListPaymentParams
8
+ attr_reader :limit, :offset, :account_id, :customer_id, :status,
9
+ :include_completed, :tags, :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 status [Array<String>] - optional
16
+ # @param include_completed [Boolean] - optional
17
+ # @param tags [Hash] - optional
18
+ # @param sort [String] - optional
19
+ # @param include [Array<String>] - optional
20
+ def initialize(limit = RECEIVED_PAYMENT_LIMIT, offset = ACH_PAYMENT_OFFSET, account_id = nil, customer_id = nil, status = nil,
21
+ include_completed = nil, tags = nil, sort = nil, include = nil)
22
+ @limit = limit
23
+ @offset = offset
24
+ @account_id = account_id
25
+ @customer_id = customer_id
26
+ @status = status
27
+ @include_completed = include_completed
28
+ @tags = tags
29
+ @sort = sort
30
+ @include = include
31
+ end
32
+
33
+ def to_hash
34
+ params = {
35
+ "page[limit]": limit,
36
+ "page[offset]": offset,
37
+ "filter[accountId]": account_id,
38
+ "filter[customerId]": customer_id,
39
+ "filter[includeCompleted]": include_completed,
40
+ "filter[tags]": tags,
41
+ "sort": sort,
42
+ "include": include&.join(",")
43
+ }
44
+ status&.each_with_index&.map do |val, index|
45
+ params.merge!({ "filter[status][#{index}]": val })
46
+ end
47
+ params.compact
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to update a received ACH payment
4
+ # @see https://docs.unit.co/received-ach#update-received-payment
5
+ module Unit
6
+ module ReceivedPayment
7
+ class PatchPaymentRequest
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": "achReceivedPayment",
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
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module ReceivedPayment
5
+ RECEIVED_PAYMENT_LIMIT = 100
6
+ RECEIVED_PAYMENT_OFFSET = 0
7
+
8
+ autoload :PatchPaymentRequest, "unit/models/received_payment/patch_payment_request"
9
+ autoload :ListPaymentParams, "unit/models/received_payment/list_payment_params"
10
+
11
+ class << self
12
+ # Get received ach payment by calling Unit's API
13
+ # @see https://docs.unit.co/received-ach#get-specific-received-payment
14
+ # @param payment_id [String]
15
+ def get_payment(payment_id:)
16
+ Unit::Resource::ReceivedPaymentResource.get_payment(payment_id)
17
+ end
18
+
19
+ # Update a received ACH payment by calling Unit's API
20
+ # @see https://docs.unit.co/received-ach#update-received-payment
21
+ # @param payment_id [String]
22
+ # @param tags [Hash] - optional
23
+ def update_payment(payment_id:, tags: nil)
24
+ request = Unit::ReceivedPayment::PatchPaymentRequest.new(payment_id, tags)
25
+ Unit::Resource::ReceivedPaymentResource.update_payment(request)
26
+ end
27
+
28
+ # List ach payments by calling Unit's API
29
+ # @see https://docs.unit.co/received-ach#list-received-payments
30
+ # @param limit [Integer] - optional
31
+ # @param offset [Integer] - optional
32
+ # @param account_id [String] - optional
33
+ # @param customer_id [String] - optional
34
+ # @param status [Array<String>] - optional
35
+ # @param include_completed [Boolean] - optional
36
+ # @param tags [Hash] - optional
37
+ # @param sort [String] - optional
38
+ # @param include [Array<String>] - optional
39
+ def list_payments(limit: RECEIVED_PAYMENT_LIMIT, offset: RECEIVED_PAYMENT_OFFSET, account_id: nil, customer_id: nil, status: nil,
40
+ include_completed: nil, tags: nil, sort: nil, include: nil)
41
+ request = Unit::ReceivedPayment::ListPaymentParams.new(limit, offset, account_id, customer_id, status,
42
+ include_completed, tags, sort, include)
43
+ Unit::Resource::ReceivedPaymentResource.list_payments(request)
44
+ end
45
+
46
+ # Advance a received payment by calling Unit's API
47
+ # @see https://docs.unit.co/received-ach#advance-received-payment
48
+ # @param payment_id [String]
49
+ def advance_payment(payment_id:)
50
+ Unit::Resource::ReceivedPaymentResource.advance_payment(payment_id)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a recurring credit ach payment
4
+ # @see https://docs.unit.co/recurring-payments/#recurring-payment-credit-ach-payment
5
+ module Unit
6
+ module RecurringPayment
7
+ class CreateRecurringCreditAchPaymentRequest
8
+ attr_reader :account_id, :counterparty_id, :amount, :description, :addenda, :schedule, :idempotency_key, :tags
9
+
10
+ # @param account_id [String]
11
+ # @param counterparty_id [String]
12
+ # @param amount [Integer]
13
+ # @param description [String]
14
+ # @param schedule [CreateSchedule]
15
+ # @param addenda [String] - optional
16
+ # @param idempotency_key [String] - optional
17
+ # @param tags [Hash] - optional
18
+ def initialize(account_id, counterparty_id, amount, description, schedule, addenda = nil, idempotency_key = nil, tags = nil)
19
+ @account_id = account_id
20
+ @counterparty_id = counterparty_id
21
+ @amount = amount
22
+ @description = description
23
+ @addenda = addenda
24
+ @schedule = schedule
25
+ @idempotency_key = idempotency_key
26
+ @tags = tags
27
+ end
28
+
29
+ def to_json_api
30
+ payload = {
31
+ "data": {
32
+ "type": "recurringCreditAchPayment",
33
+ "attributes": {
34
+ "amount": amount,
35
+ "description": description,
36
+ "addenda": addenda,
37
+ "schedule": schedule&.represent,
38
+ "idempotencyKey": idempotency_key,
39
+ "tags": tags
40
+ },
41
+ "relationships": {
42
+ account: Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
43
+ counterparty: Unit::Types::Relationship.new("counterparty", counterparty_id).to_hash
44
+ }
45
+ }
46
+ }
47
+ payload[:data][:attributes].compact!
48
+ payload.to_json
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a recurring credit book payment
4
+ # @see https://docs.unit.co/recurring-payments/#recurring-credit-book-payment
5
+ module Unit
6
+ module RecurringPayment
7
+ class CreateRecurringCreditBookPaymentRequest
8
+ attr_reader :account_id, :counterparty_id, :amount, :description, :schedule, :transaction_summary_override, :idempotency_key, :tags
9
+
10
+ # @param account_id [String]
11
+ # @param counterparty_id [String]
12
+ # @param amount [Integer]
13
+ # @param description [String]
14
+ # @param schedule [CreateSchedule]
15
+ # @param transaction_summary_override [String] - optional
16
+ # @param idempotency_key [String] - optional
17
+ # @param tags [Hash] - optional
18
+ def initialize(account_id, counterparty_id, amount, description, schedule,
19
+ transaction_summary_override = nil, idempotency_key = nil, tags = nil)
20
+ @account_id = account_id
21
+ @counterparty_id = counterparty_id
22
+ @amount = amount
23
+ @description = description
24
+ @transaction_summary_override = transaction_summary_override
25
+ @schedule = schedule
26
+ @idempotency_key = idempotency_key
27
+ @tags = tags
28
+ end
29
+
30
+ def to_json_api
31
+ payload = {
32
+ "data": {
33
+ "type": "recurringCreditBookPayment",
34
+ "attributes": {
35
+ "amount": amount,
36
+ "description": description,
37
+ "schedule": schedule&.represent,
38
+ "transaction_summary_override": transaction_summary_override,
39
+ "idempotencyKey": idempotency_key,
40
+ "tags": tags
41
+ },
42
+ "relationships":
43
+ {
44
+ account: Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
45
+ counterpartyAccount: Unit::Types::Relationship.new("depositAccount", counterparty_id).to_hash
46
+ }
47
+ }
48
+ }
49
+ payload[:data][:attributes].compact!
50
+ payload.to_json
51
+ end
52
+ end
53
+ end
54
+ end