unit_ruby_sdk 1.0.5 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +190 -19
- data/lib/unit/api_resources/application_form_resource.rb +40 -0
- data/lib/unit/api_resources/authorization_request_resource.rb +49 -0
- data/lib/unit/api_resources/authorization_resource.rb +31 -0
- data/lib/unit/api_resources/card_resource.rb +8 -0
- data/lib/unit/api_resources/event_resource.rb +40 -0
- data/lib/unit/api_resources/fee_resource.rb +32 -0
- data/lib/unit/api_resources/payment_resource.rb +17 -0
- data/lib/unit/api_resources/received_payment_resource.rb +47 -0
- data/lib/unit/api_resources/recurring_payment_resource.rb +55 -0
- data/lib/unit/api_resources/repayment_resource.rb +41 -0
- data/lib/unit/api_resources/reward_resource.rb +41 -0
- data/lib/unit/api_resources/webhook_resource.rb +65 -0
- data/lib/unit/models/application/application.rb +98 -10
- data/lib/unit/models/application/create_business_application_request.rb +34 -13
- data/lib/unit/models/application/create_individual_application_request.rb +12 -8
- data/lib/unit/models/application/create_sole_proprietor_application_request.rb +113 -0
- data/lib/unit/models/application/create_trust_application_request.rb +67 -0
- data/lib/unit/models/application/patch_trust_application_request.rb +31 -0
- data/lib/unit/models/application_form/application_form.rb +43 -0
- data/lib/unit/models/application_form/create_application_form_request.rb +48 -0
- data/lib/unit/models/application_form/list_application_form_params.rb +30 -0
- data/lib/unit/models/authorization/authorization.rb +42 -0
- data/lib/unit/models/authorization/get_request.rb +22 -0
- data/lib/unit/models/authorization/list_request.rb +67 -0
- data/lib/unit/models/authorization_request/approve_request.rb +37 -0
- data/lib/unit/models/authorization_request/authorization_request.rb +55 -0
- data/lib/unit/models/authorization_request/decline_request.rb +31 -0
- data/lib/unit/models/authorization_request/list_authorization_params.rb +44 -0
- data/lib/unit/models/card/card.rb +102 -4
- data/lib/unit/models/card/create_business_credit_card_request.rb +29 -0
- data/lib/unit/models/card/create_business_debit_card_request.rb +10 -6
- data/lib/unit/models/card/create_business_virtual_credit_card_request.rb +25 -0
- data/lib/unit/models/card/create_business_virtual_debit_card_request.rb +10 -6
- data/lib/unit/models/card/create_individual_debit_card_request.rb +7 -3
- data/lib/unit/models/card/create_individual_virtual_card_request.rb +6 -3
- data/lib/unit/models/card/patch_business_card_request.rb +50 -0
- data/lib/unit/models/card/patch_business_credit_card_request.rb +22 -0
- data/lib/unit/models/card/patch_business_virtual_card_request.rb +43 -0
- data/lib/unit/models/card/patch_business_virtual_credit_card_request.rb +20 -0
- data/lib/unit/models/customer/list_customer_params.rb +4 -2
- data/lib/unit/models/event/event.rb +37 -0
- data/lib/unit/models/event/list_event_params.rb +37 -0
- data/lib/unit/models/fee/create_fee_request.rb +43 -0
- data/lib/unit/models/fee/fee.rb +34 -0
- data/lib/unit/models/fee/reverse_fee_request.rb +43 -0
- data/lib/unit/models/payment/batch_release_request_builder.rb +21 -0
- data/lib/unit/models/payment/bulk_payment_request.rb +15 -0
- data/lib/unit/models/payment/create_ach_payment_inline_request.rb +29 -19
- data/lib/unit/models/payment/create_batch_release_request.rb +54 -0
- data/lib/unit/models/payment/create_book_payment_request.rb +24 -14
- data/lib/unit/models/payment/create_payment_linked_request.rb +31 -21
- data/lib/unit/models/payment/create_wire_payment_request.rb +22 -12
- data/lib/unit/models/payment/create_with_plaid_token_request.rb +32 -22
- data/lib/unit/models/payment/payment.rb +40 -12
- data/lib/unit/models/received_payment/list_payment_params.rb +51 -0
- data/lib/unit/models/received_payment/patch_payment_request.rb +31 -0
- data/lib/unit/models/received_payment/received_payment.rb +54 -0
- data/lib/unit/models/recurring_payment/create_recurring_credit_ach_payment_request.rb +52 -0
- data/lib/unit/models/recurring_payment/create_recurring_credit_book_payment_request.rb +54 -0
- data/lib/unit/models/recurring_payment/create_recurring_debit_ach_payment_request.rb +60 -0
- data/lib/unit/models/recurring_payment/list_recurring_payment_params.rb +60 -0
- data/lib/unit/models/recurring_payment/recurring_payment.rb +106 -0
- data/lib/unit/models/repayment/create_ach_repayment_request.rb +57 -0
- data/lib/unit/models/repayment/create_book_repayment_request.rb +53 -0
- data/lib/unit/models/repayment/list_repayment_params.rb +48 -0
- data/lib/unit/models/repayment/repayment.rb +67 -0
- data/lib/unit/models/reward/create_reward_request.rb +49 -0
- data/lib/unit/models/reward/get_request.rb +22 -0
- data/lib/unit/models/reward/list_reward_params.rb +65 -0
- data/lib/unit/models/reward/reward.rb +55 -0
- data/lib/unit/models/unit_response.rb +1 -1
- data/lib/unit/models/webhook/create_webhook_request.rb +49 -0
- data/lib/unit/models/webhook/list_webhook_params.rb +39 -0
- data/lib/unit/models/webhook/patch_webhook_request.rb +47 -0
- data/lib/unit/models/webhook/webhook.rb +80 -0
- data/lib/unit/types/application_form_prefill.rb +84 -0
- data/lib/unit/types/application_form_settings_override.rb +51 -0
- data/lib/unit/types/beneficial_owner.rb +15 -10
- data/lib/unit/types/beneficiary.rb +25 -0
- data/lib/unit/types/create_schedule.rb +38 -0
- data/lib/unit/types/evaluation_params.rb +4 -4
- data/lib/unit/types/grantor.rb +37 -0
- data/lib/unit/types/officer.rb +26 -13
- data/lib/unit/types/power_of_attorney_agent.rb +5 -12
- data/lib/unit/types/require_id_verification.rb +29 -0
- data/lib/unit/types/trust_contact.rb +34 -0
- data/lib/unit/types/trustee.rb +37 -0
- data/lib/unit/version.rb +1 -1
- data/lib/unit_ruby_sdk.rb +28 -0
- metadata +67 -2
@@ -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
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
module Repayment
|
5
|
+
REPAYMENT_LIMIT = 100
|
6
|
+
REPAYMENT_OFFSET = 0
|
7
|
+
|
8
|
+
autoload :CreateAchRepaymentRequest, "unit/models/repayment/create_ach_repayment_request"
|
9
|
+
autoload :CreateBookRepaymentRequest, "unit/models/repayment/create_book_repayment_request"
|
10
|
+
autoload :ListRepaymentParams, "unit/models/repayment/list_repayment_params"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# Get a repayment by calling Unit's API
|
14
|
+
# @see https://docs.unit.co/repayments#get-specific-repayment
|
15
|
+
# @param repayment_id [String]
|
16
|
+
def get_repayment(repayment_id:)
|
17
|
+
Unit::Resource::RepaymentResource.get(repayment_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a book repayment by calling Unit's API
|
21
|
+
# @see https://docs.unit.co/repayments#book-repayment
|
22
|
+
# @param account_id [String]
|
23
|
+
# @param credit_account_id [String]
|
24
|
+
# @param counterparty_account_id [String]
|
25
|
+
# @param description [String]
|
26
|
+
# @param amount [Integer]
|
27
|
+
# @param transaction_summary_override [String]
|
28
|
+
# @param tags [Array<String>] - optional
|
29
|
+
# @param idempotency_key [String] - optional
|
30
|
+
def create_book_repayment(account_id:, credit_account_id:, counterparty_account_id:, description:, amount:, transaction_summary_override:, tags: nil, idempotency_key: nil)
|
31
|
+
request = Unit::Repayment::CreateBookRepaymentRequest.new(account_id, credit_account_id, counterparty_account_id, description, amount, transaction_summary_override, tags, idempotency_key)
|
32
|
+
Unit::Resource::RepaymentResource.create(request)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Create an ach repayment by calling Unit's API
|
36
|
+
# @see https://docs.unit.co/repayments#create-ach-repayment
|
37
|
+
# @param account_id [String]
|
38
|
+
# @param credit_account_id [String]
|
39
|
+
# @param counterparty_id [String]
|
40
|
+
# @param description [String]
|
41
|
+
# @param amount [Integer]
|
42
|
+
# @param addenda [String] - optional
|
43
|
+
# @param tags [Hash] - optional
|
44
|
+
# @param same_day [Boolean] - optional
|
45
|
+
# @param idempotency_key [String] - optional
|
46
|
+
def create_ach_repayment(account_id:, credit_account_id:, counterparty_id:, description:, amount:, addenda: nil, tags: nil, idempotency_key: nil, same_day: false)
|
47
|
+
request = Unit::Repayment::CreateAchRepaymentRequest.new(account_id, credit_account_id, counterparty_id, description, amount, addenda, tags, idempotency_key, same_day: same_day)
|
48
|
+
Unit::Resource::RepaymentResource.create(request)
|
49
|
+
end
|
50
|
+
|
51
|
+
# List repayments by calling Unit's API
|
52
|
+
# @see https://docs.unit.co/repayments#list-repayments
|
53
|
+
# @param limit [Integer] - optional
|
54
|
+
# @param offset [Integer] - optional
|
55
|
+
# @param account_id [String] - optional
|
56
|
+
# @param credit_account_id [String] - optional
|
57
|
+
# @param customer_id [String] - optional
|
58
|
+
# @param status [Array<String>] - optional
|
59
|
+
# @param type [Array<String>] - optional
|
60
|
+
def list_repayments(limit: REPAYMENT_LIMIT, offset: REPAYMENT_OFFSET, account_id: nil,
|
61
|
+
credit_account_id: nil, customer_id: nil, status: nil, type: nil)
|
62
|
+
request = Unit::Repayment::ListRepaymentParams.new(limit, offset, account_id, credit_account_id, customer_id, status, type)
|
63
|
+
Unit::Resource::RepaymentResource.list(request)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Create a reward request
|
4
|
+
# @see https://docs.unit.co/rewards/#create-reward
|
5
|
+
module Unit
|
6
|
+
module Reward
|
7
|
+
class CreateRewardRequest
|
8
|
+
attr_reader :receiving_account_id, :funding_account_id, :rewarded_transaction_id, :amount, :description, :tags, :idempotency_key
|
9
|
+
|
10
|
+
# @param receiving_account_id [String]
|
11
|
+
# @param amount [Integer]
|
12
|
+
# @param description [String]
|
13
|
+
# @param tags [Hash]
|
14
|
+
# @param idempotency_key [String]
|
15
|
+
# @param funding_account_id [String] - optional
|
16
|
+
# @param rewarded_transaction_id [String] - optional
|
17
|
+
def initialize(receiving_account_id, amount, description, tags = nil, idempotency_key = nil, funding_account_id = nil, rewarded_transaction_id = nil)
|
18
|
+
@receiving_account_id = receiving_account_id
|
19
|
+
@amount = amount
|
20
|
+
@description = description
|
21
|
+
@tags = tags
|
22
|
+
@idempotency_key = idempotency_key
|
23
|
+
@funding_account_id = funding_account_id
|
24
|
+
@rewarded_transaction = rewarded_transaction_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_json_api
|
28
|
+
payload = {
|
29
|
+
data: {
|
30
|
+
type: "reward",
|
31
|
+
attributes: {
|
32
|
+
amount: amount,
|
33
|
+
description: description,
|
34
|
+
tags: tags,
|
35
|
+
idempotencyKey: idempotency_key
|
36
|
+
},
|
37
|
+
relationships: {
|
38
|
+
receivingAccount: Unit::Types::Relationship.new("depositAccount", receiving_account_id).to_hash
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
payload[:data][:relationships][:funding_account] = Unit::Types::Relationship.new("fundingAccount", funding_account_id).to_hash if funding_account_id
|
43
|
+
payload[:data][:relationships][:rewardedTransaction] = Unit::Types::Relationship.new("rewardedTransaction", rewarded_transaction).to_hash if rewarded_transaction_id
|
44
|
+
payload[:data][:attributes].compact!
|
45
|
+
payload.to_json
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Get a reward by id request
|
4
|
+
# @see https://docs.unit.co/rewards/#get-specific-reward
|
5
|
+
module Unit
|
6
|
+
module Reward
|
7
|
+
class GetRequest
|
8
|
+
attr_reader :reward_id, :include
|
9
|
+
|
10
|
+
# @param reward_id [String]
|
11
|
+
# @param include [Array<String>] - optional
|
12
|
+
def initialize(reward_id, include = nil)
|
13
|
+
@reward_id = reward_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,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# List reward params request
|
4
|
+
# @see https://docs.unit.co/rewards/#list-rewards
|
5
|
+
module Unit
|
6
|
+
module Reward
|
7
|
+
class ListRewardParams
|
8
|
+
attr_reader :limit, :offset, :transaction_id, :rewarded_transaction_id,
|
9
|
+
:receiving_account_id, :customer_id, :card_id, :status, :since,
|
10
|
+
:until_, :tags, :sort, :include
|
11
|
+
|
12
|
+
# @param limit [Integer] - optional
|
13
|
+
# @param offset [Integer] - optional
|
14
|
+
# @param transaction_id [String] - optional
|
15
|
+
# @param rewarded_transaction_id [String] - optional
|
16
|
+
# @param receiving_account_id [String] - optional
|
17
|
+
# @param customer_id [String] - optional
|
18
|
+
# @param card_id [String] - optional
|
19
|
+
# @param status [String] - optional
|
20
|
+
# @param since [String] - optional
|
21
|
+
# @param until_ [String] - optional
|
22
|
+
# @param tags [Hash] - optional
|
23
|
+
# @param sort [String] - optional
|
24
|
+
# @param include [Array<String>] - optional
|
25
|
+
def initialize(limit = REWARD_LIMIT, offset = REWARD_OFFSET, transaction_id = nil, rewarded_transaction_id = nil,
|
26
|
+
receiving_account_id = nil, customer_id = nil, card_id = nil, status = nil, since = nil,
|
27
|
+
until_ = nil, tags = nil, sort = nil, include = nil)
|
28
|
+
@limit = limit
|
29
|
+
@offset = offset
|
30
|
+
@transaction_id = transaction_id
|
31
|
+
@rewarded_transaction_id = rewarded_transaction_id
|
32
|
+
@receiving_account_id = receiving_account_id
|
33
|
+
@customer_id = customer_id
|
34
|
+
@card_id = card_id
|
35
|
+
@status = status
|
36
|
+
@since = since
|
37
|
+
@until_ = until_
|
38
|
+
@tags = tags
|
39
|
+
@sort = sort
|
40
|
+
@include = include
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_hash
|
44
|
+
params = {
|
45
|
+
"page[limit]": limit,
|
46
|
+
"page[offset]": offset,
|
47
|
+
"filter[transactionId]": transaction_id,
|
48
|
+
"filter[rewardedTransactionId]": rewarded_transaction_id,
|
49
|
+
"filter[receivingAccountId]": receiving_account_id,
|
50
|
+
"filter[customerId]": customer_id,
|
51
|
+
"filter[cardId]": card_id,
|
52
|
+
"filter[since]": since,
|
53
|
+
"filter[until]": until_,
|
54
|
+
"filter[tags]": tags,
|
55
|
+
"sort": sort,
|
56
|
+
"include": include&.join(",")
|
57
|
+
}
|
58
|
+
status&.each_with_index&.map do |val, index|
|
59
|
+
params.merge!({ "filter[status][#{index}]": val })
|
60
|
+
end
|
61
|
+
params.compact
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
module Reward
|
5
|
+
REWARD_LIMIT = 100
|
6
|
+
REWARD_OFFSET = 0
|
7
|
+
autoload :GetRequest, "unit/models/reward/get_request"
|
8
|
+
autoload :CreateRewardRequest, "unit/models/reward/create_reward_request"
|
9
|
+
autoload :ListRewardParams, "unit/models/reward/list_reward_params"
|
10
|
+
class << self
|
11
|
+
# Get a reward by id
|
12
|
+
# @see https://docs.unit.co/rewards/#get-specific-reward
|
13
|
+
# @param reward_id [String]
|
14
|
+
# @param include [Array<String>] - optional
|
15
|
+
def get_reward(reward_id:, include: nil)
|
16
|
+
request = GetRequest.new(reward_id, include)
|
17
|
+
Resource::RewardResource.get_reward(request)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a reward request
|
21
|
+
# @see https://docs.unit.co/rewards/#create-reward
|
22
|
+
# @param receiving_account_id [String]
|
23
|
+
# @param amount [Integer]
|
24
|
+
# @param description [String]
|
25
|
+
# @param tags [Hash]
|
26
|
+
# @param idempotency_key [String]
|
27
|
+
# @param funding_account_id [String] - optional
|
28
|
+
# @param rewarded_transaction_id [String] - optional
|
29
|
+
def create_reward(receiving_account_id:, amount:, description:, tags:, idempotency_key:, funding_account_id: nil, rewarded_transaction: nil)
|
30
|
+
request = CreateRewardRequest.new(receiving_account_id, amount, description, tags, idempotency_key, funding_account_id, rewarded_transaction)
|
31
|
+
Resource::RewardResource.create_reward(request)
|
32
|
+
end
|
33
|
+
|
34
|
+
# List reward params request
|
35
|
+
# @see https://docs.unit.co/rewards/#list-rewards
|
36
|
+
# @param limit [Integer] - optional
|
37
|
+
# @param offset [Integer] - optional
|
38
|
+
# @param transaction_id [String] - optional
|
39
|
+
# @param rewarded_transaction_id [String] - optional
|
40
|
+
# @param receiving_account_id [String] - optional
|
41
|
+
# @param customer_id [String] - optional
|
42
|
+
# @param card_id [String] - optional
|
43
|
+
# @param status [Array<String>] - optional
|
44
|
+
# @param since [String] - optional
|
45
|
+
# @param until_ [String] - optional
|
46
|
+
# @param tags [Hash] - optional
|
47
|
+
# @param sort [String] - optional
|
48
|
+
# @param include [Array<String>] - optional
|
49
|
+
def list_rewards(limit: REWARD_LIMIT, offset: REWARD_OFFSET, transaction_id: nil, rewarded_transaction_id: nil, receiving_account_id: nil, customer_id: nil, card_id: nil, status: nil, since: nil, until_: nil, tags: nil, sort: nil, include: nil)
|
50
|
+
request = ListRewardParams.new(limit, offset, transaction_id, rewarded_transaction_id, receiving_account_id, customer_id, card_id, status, since, until_, tags, sort, include)
|
51
|
+
Resource::RewardResource.list_rewards(request)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|