unit_ruby_sdk 1.1.0 → 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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +175 -20
  3. data/lib/unit/api_resources/application_form_resource.rb +40 -0
  4. data/lib/unit/api_resources/authorization_request_resource.rb +49 -0
  5. data/lib/unit/api_resources/authorization_resource.rb +31 -0
  6. data/lib/unit/api_resources/card_resource.rb +8 -0
  7. data/lib/unit/api_resources/event_resource.rb +40 -0
  8. data/lib/unit/api_resources/fee_resource.rb +32 -0
  9. data/lib/unit/api_resources/payment_resource.rb +9 -0
  10. data/lib/unit/api_resources/received_payment_resource.rb +47 -0
  11. data/lib/unit/api_resources/recurring_payment_resource.rb +55 -0
  12. data/lib/unit/api_resources/repayment_resource.rb +41 -0
  13. data/lib/unit/api_resources/reward_resource.rb +41 -0
  14. data/lib/unit/api_resources/webhook_resource.rb +65 -0
  15. data/lib/unit/models/application/application.rb +98 -10
  16. data/lib/unit/models/application/create_business_application_request.rb +34 -13
  17. data/lib/unit/models/application/create_individual_application_request.rb +12 -8
  18. data/lib/unit/models/application/create_sole_proprietor_application_request.rb +113 -0
  19. data/lib/unit/models/application/create_trust_application_request.rb +67 -0
  20. data/lib/unit/models/application/patch_trust_application_request.rb +31 -0
  21. data/lib/unit/models/application_form/application_form.rb +43 -0
  22. data/lib/unit/models/application_form/create_application_form_request.rb +48 -0
  23. data/lib/unit/models/application_form/list_application_form_params.rb +30 -0
  24. data/lib/unit/models/authorization/authorization.rb +42 -0
  25. data/lib/unit/models/authorization/get_request.rb +22 -0
  26. data/lib/unit/models/authorization/list_request.rb +67 -0
  27. data/lib/unit/models/authorization_request/approve_request.rb +37 -0
  28. data/lib/unit/models/authorization_request/authorization_request.rb +55 -0
  29. data/lib/unit/models/authorization_request/decline_request.rb +31 -0
  30. data/lib/unit/models/authorization_request/list_authorization_params.rb +44 -0
  31. data/lib/unit/models/card/card.rb +102 -4
  32. data/lib/unit/models/card/create_business_credit_card_request.rb +29 -0
  33. data/lib/unit/models/card/create_business_debit_card_request.rb +10 -6
  34. data/lib/unit/models/card/create_business_virtual_credit_card_request.rb +25 -0
  35. data/lib/unit/models/card/create_business_virtual_debit_card_request.rb +10 -6
  36. data/lib/unit/models/card/create_individual_debit_card_request.rb +7 -3
  37. data/lib/unit/models/card/create_individual_virtual_card_request.rb +6 -3
  38. data/lib/unit/models/card/patch_business_card_request.rb +50 -0
  39. data/lib/unit/models/card/patch_business_credit_card_request.rb +22 -0
  40. data/lib/unit/models/card/patch_business_virtual_card_request.rb +43 -0
  41. data/lib/unit/models/card/patch_business_virtual_credit_card_request.rb +20 -0
  42. data/lib/unit/models/customer/list_customer_params.rb +4 -2
  43. data/lib/unit/models/event/event.rb +37 -0
  44. data/lib/unit/models/event/list_event_params.rb +37 -0
  45. data/lib/unit/models/fee/create_fee_request.rb +43 -0
  46. data/lib/unit/models/fee/fee.rb +34 -0
  47. data/lib/unit/models/fee/reverse_fee_request.rb +43 -0
  48. data/lib/unit/models/payment/batch_release_request_builder.rb +21 -0
  49. data/lib/unit/models/payment/create_batch_release_request.rb +54 -0
  50. data/lib/unit/models/payment/payment.rb +21 -1
  51. data/lib/unit/models/received_payment/list_payment_params.rb +51 -0
  52. data/lib/unit/models/received_payment/patch_payment_request.rb +31 -0
  53. data/lib/unit/models/received_payment/received_payment.rb +54 -0
  54. data/lib/unit/models/recurring_payment/create_recurring_credit_ach_payment_request.rb +52 -0
  55. data/lib/unit/models/recurring_payment/create_recurring_credit_book_payment_request.rb +54 -0
  56. data/lib/unit/models/recurring_payment/create_recurring_debit_ach_payment_request.rb +60 -0
  57. data/lib/unit/models/recurring_payment/list_recurring_payment_params.rb +60 -0
  58. data/lib/unit/models/recurring_payment/recurring_payment.rb +106 -0
  59. data/lib/unit/models/repayment/create_ach_repayment_request.rb +57 -0
  60. data/lib/unit/models/repayment/create_book_repayment_request.rb +53 -0
  61. data/lib/unit/models/repayment/list_repayment_params.rb +48 -0
  62. data/lib/unit/models/repayment/repayment.rb +67 -0
  63. data/lib/unit/models/reward/create_reward_request.rb +49 -0
  64. data/lib/unit/models/reward/get_request.rb +22 -0
  65. data/lib/unit/models/reward/list_reward_params.rb +65 -0
  66. data/lib/unit/models/reward/reward.rb +55 -0
  67. data/lib/unit/models/unit_response.rb +1 -1
  68. data/lib/unit/models/webhook/create_webhook_request.rb +49 -0
  69. data/lib/unit/models/webhook/list_webhook_params.rb +39 -0
  70. data/lib/unit/models/webhook/patch_webhook_request.rb +47 -0
  71. data/lib/unit/models/webhook/webhook.rb +80 -0
  72. data/lib/unit/types/application_form_prefill.rb +84 -0
  73. data/lib/unit/types/application_form_settings_override.rb +51 -0
  74. data/lib/unit/types/beneficial_owner.rb +15 -10
  75. data/lib/unit/types/beneficiary.rb +25 -0
  76. data/lib/unit/types/create_schedule.rb +38 -0
  77. data/lib/unit/types/evaluation_params.rb +4 -4
  78. data/lib/unit/types/grantor.rb +37 -0
  79. data/lib/unit/types/officer.rb +26 -13
  80. data/lib/unit/types/power_of_attorney_agent.rb +5 -12
  81. data/lib/unit/types/require_id_verification.rb +29 -0
  82. data/lib/unit/types/trust_contact.rb +34 -0
  83. data/lib/unit/types/trustee.rb +37 -0
  84. data/lib/unit/version.rb +1 -1
  85. data/lib/unit_ruby_sdk.rb +28 -0
  86. metadata +66 -2
@@ -14,6 +14,8 @@ module Unit
14
14
  autoload :ListPaymentParams, "unit/models/payment/list_payment_params"
15
15
  autoload :GetRequest, "unit/models/payment/get_request"
16
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"
17
19
  class << self
18
20
  # Create a new book payment by calling Unit's API
19
21
  # @see https://docs.unit.co/book-payments#book-payments
@@ -181,6 +183,24 @@ module Unit
181
183
  request = Unit::Payment::BulkPaymentRequest.serialize(requests)
182
184
  Unit::Resource::PaymentResource.create_bulk_payment(request)
183
185
  end
184
- 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
185
205
  end
186
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
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Create a recurring debit ACH payment request
4
+ # @see https://docs.unit.co/recurring-payments/#recurring-payment-debit-ach-payment
5
+ module Unit
6
+ module RecurringPayment
7
+ class CreateRecurringDebitAchPaymentRequest
8
+ attr_reader :account_id, :counterparty_id, :amount, :description, :addenda, :schedule, :idempotency_key, :tags,
9
+ :verify_counterparty_balance, :same_day
10
+
11
+ # @param account_id [String]
12
+ # @param counterparty_id [String]
13
+ # @param amount [Integer]
14
+ # @param description [String]
15
+ # @param schedule [CreateSchedule]
16
+ # @param addenda [String] - optional
17
+ # @param idempotency_key [String] - optional
18
+ # @param tags [Hash] - optional
19
+ # @param verify_counterparty_balance [Boolean] - optional
20
+ # @param same_day [Boolean] - optional
21
+ def initialize(account_id, counterparty_id, amount, description, schedule, addenda = nil, idempotency_key = nil, tags = nil,
22
+ verify_counterparty_balance = nil, same_day = nil)
23
+ @account_id = account_id
24
+ @counterparty_id = counterparty_id
25
+ @amount = amount
26
+ @description = description
27
+ @addenda = addenda
28
+ @schedule = schedule
29
+ @idempotency_key = idempotency_key
30
+ @tags = tags
31
+ @verify_counterparty_balance = verify_counterparty_balance
32
+ @same_day = same_day
33
+ end
34
+
35
+ def to_json_api
36
+ payload = {
37
+ "data": {
38
+ "type": "recurringDebitAchPayment",
39
+ "attributes": {
40
+ "amount": amount,
41
+ "description": description,
42
+ "addenda": addenda,
43
+ "schedule": schedule&.represent,
44
+ "idempotencyKey": idempotency_key,
45
+ "tags": tags,
46
+ "verifyCounterpartyBalance": verify_counterparty_balance,
47
+ "sameDay": same_day
48
+ },
49
+ "relationships": {
50
+ account: Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
51
+ counterparty: Unit::Types::Relationship.new("counterparty", counterparty_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,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Params for listing recurring payments
4
+ # @see https://docs.unit.co/recurring-payments/#list-recurring-payments
5
+ module Unit
6
+ module RecurringPayment
7
+ class ListRecurringPaymentParams
8
+ attr_reader :limit, :offset, :account_id, :customer_id, :status, :type,
9
+ :from_start_time, :to_start_time, :from_end_time, :to_end_time, :sort
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] - optional
16
+ # @param type [Array] - optional
17
+ # @param from_start_time [String] - optional
18
+ # @param to_start_time [String] - optional
19
+ # @param from_end_time [String] - optional
20
+ # @param to_end_time [String] - optional
21
+ # @param sort [String] - optional
22
+ def initialize(limit = RECURRING_PAYMENT_LIMIT, offset = RECURRING_PAYMENT_OFFSET, account_id = nil, customer_id = nil, status = nil, type = nil,
23
+ from_start_time = nil, to_start_time = nil, from_end_time = nil, to_end_time = nil, sort = nil)
24
+ @limit = limit
25
+ @offset = offset
26
+ @account_id = account_id
27
+ @customer_id = customer_id
28
+ @status = status
29
+ @type = type
30
+ @from_start_date = from_start_time
31
+ @to_start_date = to_start_time
32
+ @from_end_date = from_end_time
33
+ @to_end_date = to_end_time
34
+ @sort = sort
35
+ end
36
+
37
+ def to_hash
38
+ payload = {
39
+ "page[limit]": limit,
40
+ "page[offset]": offset,
41
+ "filter[accountId]": account_id,
42
+ "filter[customerId]": customer_id,
43
+ "filter[fromStartTime]": from_start_time,
44
+ "filter[toStartTime]": to_start_time,
45
+ "filter[fromEndTime]": from_end_time,
46
+ "filter[toEndTime]": to_end_time,
47
+ "sort": sort
48
+ }
49
+ filters = %i[status type]
50
+ filters.each do |filter|
51
+ values = send(filter)
52
+ values&.each_with_index&.map do |val, index|
53
+ params.merge!({ "filter[#{filter}][#{index}]": val })
54
+ end
55
+ end
56
+ payload.compact!
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module RecurringPayment
5
+ RECURRING_PAYMENT_LIMIT = 100
6
+ RECURRING_PAYMENT_OFFSET = 0
7
+ autoload :CreateRecurringCreditBookPaymentRequest, "unit/models/recurring_payment/create_recurring_credit_book_payment_request"
8
+ autoload :CreateRecurringCreditAchPaymentRequest, "unit/models/recurring_payment/create_recurring_credit_ach_payment_request"
9
+ autoload :CreateRecurringDebitAchPaymentRequest, "unit/models/recurring_payment/create_recurring_debit_ach_payment_request"
10
+ autoload :ListRecurringPaymentParams, "unit/models/recurring_payment/list_recurring_payment_params"
11
+
12
+ class << self
13
+ # Create a recurring credit book payment
14
+ # @see https://docs.unit.co/recurring-payments/#recurring-credit-book-payment
15
+ # @param account_id [String]
16
+ # @param counterparty_id [String]
17
+ # @param amount [Integer]
18
+ # @param description [String]
19
+ # @param schedule [CreateSchedule]
20
+ # @param transaction_summary_override [String] - optional
21
+ # @param idempotency_key [String] - optional
22
+ # @param tags [Hash] - optional
23
+ def create_recurring_credit_book_payment(account_id:, counterparty_id:, amount:, description:,
24
+ schedule:, transaction_summary_override: nil, idempotency_key: nil, tags: nil)
25
+ request = Unit::RecurringPayment::CreateRecurringCreditBookPaymentRequest.new(account_id, counterparty_id, amount, description, schedule,
26
+ transaction_summary_override, idempotency_key, tags)
27
+ Unit::Resource::RecurringPaymentResource.create_recurring_payment(request)
28
+ end
29
+
30
+ # Create a recurring credit ACH payment
31
+ # @see https://docs.unit.co/recurring-payments/#recurring-payment-credit-ach-payment
32
+ # @param account_id [String]
33
+ # @param counterparty_id [String]
34
+ # @param amount [Integer]
35
+ # @param description [String]
36
+ # @param schedule [CreateSchedule]
37
+ # @param addenda [String] - optional
38
+ # @param idempotency_key [String] - optional
39
+ # @param tags [Hash] - optional
40
+ def create_recurring_credit_ach_payment(account_id:, counterparty_id:, amount:, description:, schedule:, addenda: nil, idempotency_key: nil, tags: nil)
41
+ request = Unit::RecurringPayment::CreateRecurringCreditAchPaymentRequest.new(account_id, counterparty_id, amount, description, schedule, addenda, idempotency_key, tags)
42
+ Unit::Resource::RecurringPaymentResource.create_recurring_payment(request)
43
+ end
44
+
45
+ # Create a recurring debit ACH payment
46
+ # @see https://docs.unit.co/recurring-payments/#recurring-payment-debit-ach-payment
47
+ # @param account_id [String]
48
+ # @param counterparty_id [String]
49
+ # @param amount [Integer]
50
+ # @param description [String]
51
+ # @param schedule [CreateSchedule]
52
+ # @param addenda [String] - optional
53
+ # @param idempotency_key [String] - optional
54
+ # @param tags [Hash] - optional
55
+ # @param verify_counterparty_balance [Boolean] - optional
56
+ # @param same_day [Boolean] - optional
57
+ def create_recurring_debit_ach_payment(account_id:, counterparty_id:, amount:, description:, schedule:, addenda: nil, idempotency_key: nil, tags: nil,
58
+ verify_counterparty_balance: nil, same_day: nil)
59
+ request = Unit::RecurringPayment::CreateRecurringDebitAchPaymentRequest.new(account_id, counterparty_id, amount, description, schedule, addenda, idempotency_key, tags,
60
+ verify_counterparty_balance, same_day)
61
+ Unit::Resource::RecurringPaymentResource.create_recurring_payment(request)
62
+ end
63
+
64
+ # Enable a recurring payment
65
+ # @see https://docs.unit.co/recurring-payments/#enable-recurring-payment
66
+ # @param recurring_payment_id [String]
67
+ def enable_recurring_payment(recurring_payment_id:)
68
+ Unit::Resource::RecurringPaymentResource.enable_recurring_payment(recurring_payment_id)
69
+ end
70
+
71
+ # Disable a recurring payment
72
+ # @see https://docs.unit.co/recurring-payments/#disable-recurring-payment
73
+ # @param recurring_payment_id [String]
74
+ def disable_recurring_payment(recurring_payment_id:)
75
+ Unit::Resource::RecurringPaymentResource.disable_recurring_payment(recurring_payment_id)
76
+ end
77
+
78
+ # List recurring payments
79
+ # @see https://docs.unit.co/recurring-payments/#list-recurring-payments
80
+ # @param limit [Integer] - optional
81
+ # @param offset [Integer] - optional
82
+ # @param account_id [String] - optional
83
+ # @param customer_id [String] - optional
84
+ # @param status [String] - optional
85
+ # @param type [String] - optional
86
+ # @param from_start_time [String] - optional
87
+ # @param to_start_time [String] - optional
88
+ # @param from_end_time [String] - optional
89
+ # @param to_end_time [String] - optional
90
+ # @param sort [String] - optional
91
+ def list_recurring_payment(limit: RECURRING_PAYMENT_LIMIT, offset: RECURRING_PAYMENT_OFFSET, account_id: nil, customer_id: nil, status: nil, type: nil,
92
+ from_start_time: nil, to_start_time: nil, from_end_time: nil, to_end_time: nil, sort: nil)
93
+ request = Unit::RecurringPayment::ListRecurringPaymentParams.new(limit, offset, account_id, customer_id, status, type,
94
+ from_start_time, to_start_time, from_end_time, to_end_time, sort)
95
+ Unit::Resource::RecurringPaymentResource.list_recurring_payment(request)
96
+ end
97
+
98
+ # Get a recurring payment
99
+ # @see https://docs.unit.co/recurring-payments/#get-specific-recurring-payment
100
+ # @param recurring_payment_id [String]
101
+ def get_recurring_payment(recurring_payment_id:)
102
+ Unit::Resource::RecurringPaymentResource.get_recurring_payment(recurring_payment_id)
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create an ach repayment
4
+ # @see https://docs.unit.co/repayments/#create-ach-repayment
5
+ module Unit
6
+ module Repayment
7
+ class CreateAchRepaymentRequest
8
+ attr_reader :account_id, :credit_account_id, :counterparty_id, :description,
9
+ :amount, :addenda, :tags, :same_day, :idempotency_key
10
+
11
+ # @param account_id [String]
12
+ # @param credit_account_id [String]
13
+ # @param counterparty_id [String]
14
+ # @param description [String]
15
+ # @param amount [Integer]
16
+ # @param addenda [String] - optional
17
+ # @param tags [Hash] - optional
18
+ # @param same_day [Boolean] - optional
19
+ # @param idempotency_key [String] - optional
20
+ def initialize(account_id, credit_account_id, counterparty_id, description, amount, addenda = nil, tags = nil,
21
+ idempotency_key = nil, same_day: false)
22
+ @account_id = account_id
23
+ @credit_account_id = credit_account_id
24
+ @counterparty_id = counterparty_id
25
+ @description = description
26
+ @amount = amount
27
+ @addenda = addenda
28
+ @tags = tags
29
+ @same_day = same_day
30
+ @idempotency_key = idempotency_key
31
+ end
32
+
33
+ def to_json_api
34
+ payload = {
35
+ data: {
36
+ type: "achRepayment",
37
+ attributes: {
38
+ description: description,
39
+ amount: amount,
40
+ addenda: addenda,
41
+ tags: tags,
42
+ sameDay: same_day,
43
+ idempotencyKey: idempotency_key
44
+ },
45
+ "relationships": {
46
+ "account": Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
47
+ "creditAccount": Unit::Types::Relationship.new("creditAccount", credit_account_id).to_hash,
48
+ "counterparty": Unit::Types::Relationship.new("counterparty", counterparty_id).to_hash
49
+ }
50
+ }
51
+ }
52
+ payload[:data][:attributes].compact!
53
+ payload.to_json
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a book repayment
4
+ # @see https://docs.unit.co/repayments/#book-repayment
5
+ module Unit
6
+ module Repayment
7
+ class CreateBookRepaymentRequest
8
+ attr_reader :account_id, :credit_account_id, :counterparty_account_id, :description, :amount, :transaction_summary_override,
9
+ :tags, :idempotency_key
10
+
11
+ # @param account_id [String]
12
+ # @param credit_account_id [String]
13
+ # @param counterparty_account_id [String]
14
+ # @param description [String]
15
+ # @param amount [Integer]
16
+ # @param transaction_summary_override [String]
17
+ # @param tags [Hash] - optional
18
+ # @param idempotency_key [String] - optional
19
+ def initialize(account_id, credit_account_id, counterparty_account_id, description, amount, transaction_summary_override, tags = nil, idempotency_key = nil)
20
+ @account_id = account_id
21
+ @credit_account_id = credit_account_id
22
+ @counterparty_account_id = counterparty_account_id
23
+ @description = description
24
+ @amount = amount
25
+ @transaction_summary_override = transaction_summary_override
26
+ @tags = tags
27
+ @idempotency_key = idempotency_key
28
+ end
29
+
30
+ def to_json_api
31
+ payload = {
32
+ data: {
33
+ type: "bookRepayment",
34
+ attributes: {
35
+ description: description,
36
+ amount: amount,
37
+ transactionSummaryOverride: transaction_summary_override,
38
+ tags: tags,
39
+ idempotencyKey: idempotency_key
40
+ },
41
+ "relationships": {
42
+ "account": Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
43
+ "creditAccount": Unit::Types::Relationship.new("creditAccount", credit_account_id).to_hash,
44
+ "counterpartyAccount": Unit::Types::Relationship.new("account", counterparty_account_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,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Params for listing repayments
4
+ # @see https://docs.unit.co/repayments/#list-repayments
5
+ module Unit
6
+ module Repayment
7
+ class ListRepaymentParams
8
+ attr_reader :limit, :offset, :account_id, :credit_account_id,
9
+ :customer_id, :status, :type
10
+
11
+ # @param limit [Integer] - optional
12
+ # @param offset [Integer] - optional
13
+ # @param account_id [String] - optional
14
+ # @param credit_account_id [String] - optional
15
+ # @param customer_id [String] - optional
16
+ # @param status [Array<String>] - optional
17
+ # @param type [Array<String>] - optional
18
+ def initialize(limit = REPAYMENT_LIMIT, offset = REPAYMENT_OFFSET, account_id = nil,
19
+ credit_account_id = nil, customer_id = nil, status = nil, type = nil)
20
+ @limit = limit
21
+ @offset = offset
22
+ @account_id = account_id
23
+ @credit_account_id = credit_account_id
24
+ @customer_id = customer_id
25
+ @status = status
26
+ @type = type
27
+ end
28
+
29
+ def to_hash
30
+ params = {
31
+ "page[limit]": limit,
32
+ "page[offset]": offset,
33
+ "filter[accountId]": account_id,
34
+ "filter[creditAccountId]": credit_account_id,
35
+ "filter[customerId]": customer_id
36
+ }
37
+ filters = %i[status type]
38
+ filters.each do |filter|
39
+ values = send(filter)
40
+ values&.each_with_index&.map do |val, index|
41
+ params.merge!({ "filter[#{filter}][#{index}]": val })
42
+ end
43
+ end
44
+ params.compact
45
+ end
46
+ end
47
+ end
48
+ end