unit_ruby_sdk 1.0.0 → 1.0.3
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.
- checksums.yaml +4 -4
- data/README.md +23 -0
- data/lib/unit/api_resources/check_deposit_resource.rb +81 -0
- data/lib/unit/api_resources/counterparty_resource.rb +65 -0
- data/lib/unit/models/account/account.rb +2 -2
- data/lib/unit/models/check_deposit/check_deposit.rb +107 -0
- data/lib/unit/models/check_deposit/create_check_deposit_request.rb +43 -0
- data/lib/unit/models/check_deposit/get_image_request.rb +19 -0
- data/lib/unit/models/check_deposit/get_request.rb +22 -0
- data/lib/unit/models/check_deposit/list_deposit_params.rb +42 -0
- data/lib/unit/models/check_deposit/patch_deposit_request.rb +29 -0
- data/lib/unit/models/check_deposit/upload_image_request.rb +22 -0
- data/lib/unit/models/counterparty/counterparty.rb +93 -0
- data/lib/unit/models/counterparty/create_counterparty_request.rb +56 -0
- data/lib/unit/models/counterparty/create_with_plaid_token_request.rb +53 -0
- data/lib/unit/models/counterparty/list_counterparty_params.rb +45 -0
- data/lib/unit/models/counterparty/update_counterparty_request.rb +40 -0
- data/lib/unit/utils/http_helper.rb +9 -8
- data/lib/unit/version.rb +1 -1
- data/lib/unit_ruby_sdk.rb +5 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf85eb968fc7cac1337e5093a9c5998a98997ad7f37956e79c45498785b08ffb
|
4
|
+
data.tar.gz: e60405762229150510a2e82b76d25aecc547c009c287ca694ef95611e2319c28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91ea490c2a75df07cf37281fc32aef9965767fbbcbe12b035a8caf500e3fd08bd23dc2b8eb5c522eef2491885a13c4053ad9c3b0c906925ea077c42ab27c4452
|
7
|
+
data.tar.gz: 4c687d3bd7a49d5c0bf4c113b20aabf42e1fcfec5381165ced6fb5f45825565bd5ab058529c97224d6d3680df936663589f02011de0b2b636429af8174b37d29
|
data/README.md
CHANGED
@@ -110,6 +110,29 @@ card = response.data
|
|
110
110
|
puts card.id
|
111
111
|
```
|
112
112
|
|
113
|
+
### Creating a check deposit
|
114
|
+
```ruby
|
115
|
+
response = Unit::CheckDeposit.create_deposit(
|
116
|
+
account_id: account_id,
|
117
|
+
amount: 50_000,
|
118
|
+
description: "test check deposit"
|
119
|
+
)
|
120
|
+
deposit = response.data
|
121
|
+
puts deposit.id
|
122
|
+
```
|
123
|
+
|
124
|
+
### Creating a counterparty with a plaid token
|
125
|
+
```ruby
|
126
|
+
response = Unit::Counterparty.create_with_plaid_token(
|
127
|
+
customer_id: "823139",
|
128
|
+
type: "Business",
|
129
|
+
name: "Jo Joel",
|
130
|
+
plaid_processor_token: "processor-sandbox-plaid-token")
|
131
|
+
|
132
|
+
counterparty = response.data
|
133
|
+
puts counterparty.id
|
134
|
+
```
|
135
|
+
|
113
136
|
### Logging Errors
|
114
137
|
|
115
138
|
```ruby
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base_resource"
|
4
|
+
require_relative "../utils/http_helper"
|
5
|
+
require "json"
|
6
|
+
# class for creating requests for check deposits to Unit API and parsing responses
|
7
|
+
# @see https://docs.unit.co/check-deposits
|
8
|
+
module Unit
|
9
|
+
module Resource
|
10
|
+
class CheckDepositResource < Unit::Resource::BaseResource
|
11
|
+
class << self
|
12
|
+
# Create a check deposit by calling Unit's API
|
13
|
+
# @param request [CreateCheckDepositRequest]
|
14
|
+
# @return [UnitResponse, UnitError]
|
15
|
+
def create_deposit(request)
|
16
|
+
payload = request.to_json_api
|
17
|
+
response = HttpHelper.post("#{api_url}/check-deposits", body: payload, headers: headers)
|
18
|
+
response_handler(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get a check deposit by id by calling Unit's API
|
22
|
+
# @param params [GetRequest]
|
23
|
+
# @return [UnitResponse, UnitError]
|
24
|
+
def get(params)
|
25
|
+
payload = params.to_hash
|
26
|
+
response = HttpHelper.get("#{api_url}/check-deposits/#{params.deposit_id}", params: payload, headers: headers)
|
27
|
+
response_handler(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get a list of check deposits by calling Unit's API
|
31
|
+
# @param params [ListDepositRequest]
|
32
|
+
# @return [UnitResponse, UnitError]
|
33
|
+
def list(params = nil)
|
34
|
+
response = HttpHelper.get("#{api_url}/check-deposits", params: params.to_hash, headers: headers)
|
35
|
+
response_handler(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Update a check deposit by id by calling Unit's API
|
39
|
+
# @param request [PatchCheckDepositRequest]
|
40
|
+
# @return [UnitResponse, UnitError]
|
41
|
+
def update(request)
|
42
|
+
payload = request.to_json_api
|
43
|
+
response = HttpHelper.patch("#{api_url}/check-deposits/#{request.deposit_id}", body: payload, headers: headers)
|
44
|
+
response_handler(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Upload a check deposit image by calling Unit's API
|
48
|
+
# @param request [UploadImageRequest]
|
49
|
+
# @return [UnitResponse, UnitError]
|
50
|
+
def upload(request)
|
51
|
+
side = request.is_front_side ? "/front" : "/back"
|
52
|
+
|
53
|
+
headers_updated = headers.clone
|
54
|
+
|
55
|
+
headers_updated["Content-Type"] = "image/jpeg"
|
56
|
+
|
57
|
+
response = HttpHelper.put("#{api_url}/check-deposits/#{request.deposit_id}#{side}", body: request.file_content, headers: headers_updated)
|
58
|
+
|
59
|
+
response_handler(response)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get a check deposit image by calling Unit's API
|
63
|
+
# @param request [GetImageRequest]
|
64
|
+
# @return [UnitResponse, UnitError]
|
65
|
+
def get_image(request)
|
66
|
+
side = request.is_front_side ? "front" : "back"
|
67
|
+
response = HttpHelper.get("#{api_url}/check-deposits/#{request.deposit_id}/#{side}", headers: headers, response_type: "image")
|
68
|
+
file_response_handler(response)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Confirm a check deposit by calling Unit's API
|
72
|
+
# @param deposit_id [String]
|
73
|
+
# @return [UnitResponse, UnitError]
|
74
|
+
def confirm_details(deposit_id)
|
75
|
+
response = HttpHelper.post("#{api_url}/check-deposits/#{deposit_id}/confirm", headers: headers)
|
76
|
+
response_handler(response)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base_resource"
|
4
|
+
require_relative "../utils/http_helper"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
# class for creating requests for counterparties to Unit API and parsing responses
|
8
|
+
# @see https://docs.unit.co/payments-counterparties
|
9
|
+
module Unit
|
10
|
+
module Resource
|
11
|
+
class CounterpartyResource < Unit::Resource::BaseResource
|
12
|
+
class << self
|
13
|
+
# Create a counterparty by calling Unit's API
|
14
|
+
# @param request [CreateCounterpartyRequest, CreateWithPlaidTokenRequest]
|
15
|
+
# @return [UnitResponse, UnitError]
|
16
|
+
def create_counterparty(request)
|
17
|
+
payload = request.to_json_api
|
18
|
+
response = HttpHelper.post("#{api_url}/counterparties", body: payload, headers: headers)
|
19
|
+
response_handler(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Update counterparty by calling Unit's API
|
23
|
+
# @param request [UpdateCounterpartyRequest]
|
24
|
+
# @return [UnitResponse, UnitError]
|
25
|
+
def update_counterparty(request)
|
26
|
+
payload = request.to_json_api
|
27
|
+
response = HttpHelper.patch("#{api_url}/counterparties/#{request.counterparty_id}", body: payload, headers: headers)
|
28
|
+
response_handler(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Delete counterparty by calling Unit's API
|
32
|
+
# @param counterparty_id String
|
33
|
+
# @return [UnitResponse, UnitError]
|
34
|
+
def delete(counterparty_id)
|
35
|
+
response = HttpHelper.delete("#{api_url}/counterparties/#{counterparty_id}", headers: headers, response_type: "delete")
|
36
|
+
file_response_handler(response)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get counterparty by id by calling Unit's API
|
40
|
+
# @param counterparty_id String
|
41
|
+
# @return [UnitResponse, UnitError]
|
42
|
+
def get_counterparty(counterparty_id)
|
43
|
+
response = HttpHelper.get("#{api_url}/counterparties/#{counterparty_id}", headers: headers)
|
44
|
+
response_handler(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get counterparty balance
|
48
|
+
# @param counterparty_id String
|
49
|
+
# @return [UnitResponse, UnitError]
|
50
|
+
def get_counterparty_balance(counterparty_id)
|
51
|
+
response = HttpHelper.get("#{api_url}/counterparties/#{counterparty_id}/balance", headers: headers)
|
52
|
+
response_handler(response)
|
53
|
+
end
|
54
|
+
|
55
|
+
# List counterparties
|
56
|
+
# @param params [ListCounterpartyParams]
|
57
|
+
# @return [UnitResponse, UnitError]
|
58
|
+
def list(params = nil)
|
59
|
+
response = HttpHelper.get("#{api_url}/counterparties", params: params.to_hash, headers: headers)
|
60
|
+
response_handler(response)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -34,8 +34,8 @@ module Unit
|
|
34
34
|
# @param reason [String]
|
35
35
|
# @param fraud_reason [String] - optional
|
36
36
|
# @return [UnitResponse, UnitError]
|
37
|
-
def close_deposit_account(account_id:, reason:)
|
38
|
-
request = CloseDepositAccountRequest.new(account_id, reason)
|
37
|
+
def close_deposit_account(account_id:, reason:, fraud_reason: nil)
|
38
|
+
request = CloseDepositAccountRequest.new(account_id, reason, fraud_reason)
|
39
39
|
Unit::Resource::AccountResource.close_account(request)
|
40
40
|
end
|
41
41
|
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
module CheckDeposit
|
5
|
+
CHECK_DEPOSIT_LIMIT = 100
|
6
|
+
CHECK_DEPOSIT_OFFSET = 0
|
7
|
+
|
8
|
+
autoload :CreateCheckDepositRequest, "unit/models/check_deposit/create_check_deposit_request"
|
9
|
+
autoload :GetRequest, "unit/models/check_deposit/get_request"
|
10
|
+
autoload :ListDepositParams, "unit/models/check_deposit/list_deposit_params"
|
11
|
+
autoload :UploadImageRequest, "unit/models/check_deposit/upload_image_request"
|
12
|
+
autoload :GetImageRequest, "unit/models/check_deposit/get_image_request"
|
13
|
+
autoload :PatchDepositRequest, "unit/models/check_deposit/patch_deposit_request"
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# Create a check deposit
|
17
|
+
# @see https://docs.unit.co/check-deposits#create-check-deposit
|
18
|
+
# @param account_id [String]
|
19
|
+
# @param amount [Integer]
|
20
|
+
# @param description [String]
|
21
|
+
# @param tags [Hash] - optional
|
22
|
+
# @param idempotency_key [String] - optional
|
23
|
+
def create_deposit(account_id:, amount:, description:, tags: nil, idempotency_key: nil)
|
24
|
+
request = CreateCheckDepositRequest.new(account_id, amount, description, tags, idempotency_key)
|
25
|
+
Unit::Resource::CheckDepositResource.create_deposit(request)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get a check deposit by calling Unit's API
|
29
|
+
# @see https://docs.unit.co/check-deposits#get-specific-check-deposit
|
30
|
+
# @param deposit_id [String]
|
31
|
+
# @param include [Array<String>] - optional
|
32
|
+
def get_deposit(deposit_id:, include: nil)
|
33
|
+
request = GetRequest.new(deposit_id, include)
|
34
|
+
Unit::Resource::CheckDepositResource.get(request)
|
35
|
+
end
|
36
|
+
|
37
|
+
# List check deposits
|
38
|
+
# @see https://docs.unit.co/check-deposits#list-check-deposits
|
39
|
+
# @param limit [Integer] - optional
|
40
|
+
# @param offset [Integer] - optional
|
41
|
+
# @param account_id [String] - optional
|
42
|
+
# @param customer_id [String] - optional
|
43
|
+
# @param tags [Hash] - optional
|
44
|
+
# @param sort [String] - optional
|
45
|
+
# @param include [Array<String>] - optional
|
46
|
+
def list_deposit(limit: CHECK_DEPOSIT_LIMIT, offset: CHECK_DEPOSIT_OFFSET, account_id: nil,
|
47
|
+
customer_id: nil, tags: nil, sort: nil, include: nil)
|
48
|
+
request = ListDepositParams.new(limit, offset, account_id, customer_id, tags, sort, include)
|
49
|
+
Unit::Resource::CheckDepositResource.list(request)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Upload an image front side for a check deposit
|
53
|
+
# @see https://docs.unit.co/check-deposits#upload-front-side-image
|
54
|
+
# @param deposit_id [String]
|
55
|
+
# @param file_content [String]
|
56
|
+
# @param is_front_side [Boolean] - optional
|
57
|
+
def upload_image_front(deposit_id:, file_content:, is_front_side: true)
|
58
|
+
request = UploadImageRequest.new(deposit_id, file_content, is_front_side: is_front_side)
|
59
|
+
Unit::Resource::CheckDepositResource.upload(request)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Upload an image back side for a check deposit
|
63
|
+
# @see https://docs.unit.co/check-deposits#upload-back-side-image
|
64
|
+
# @param deposit_id [String]
|
65
|
+
# @param file_content [String]
|
66
|
+
# @param is_front_side [Boolean] - optional
|
67
|
+
def upload_image_back(deposit_id:, file_content:, is_front_side: false)
|
68
|
+
request = UploadImageRequest.new(deposit_id, file_content, is_front_side: is_front_side)
|
69
|
+
Unit::Resource::CheckDepositResource.upload(request)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Get a check deposit image front side
|
73
|
+
# @see https://docs.unit.co/check-deposits#get-specific-check-deposit-front-image
|
74
|
+
# @param deposit_id [String]
|
75
|
+
# @param is_front_side [Boolean] - optional
|
76
|
+
def get_image_front(deposit_id:, is_front_side: true)
|
77
|
+
request = GetImageRequest.new(deposit_id, is_front_side: is_front_side)
|
78
|
+
Unit::Resource::CheckDepositResource.get_image(request)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Get a check deposit image back side
|
82
|
+
# @see https://docs.unit.co/check-deposits#get-specific-check-deposit-back-image
|
83
|
+
# @param deposit_id [String]
|
84
|
+
# @param is_front_side [Boolean] - optional
|
85
|
+
def get_image_back(deposit_id:, is_front_side: false)
|
86
|
+
request = GetImageRequest.new(deposit_id, is_front_side: is_front_side)
|
87
|
+
Unit::Resource::CheckDepositResource.get_image(request)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Update a check deposit
|
91
|
+
# @see https://docs.unit.co/check-deposits#update-check-deposit
|
92
|
+
# @param deposit_id [String]
|
93
|
+
# @param tags [Hash] - optional
|
94
|
+
def update_deposit(deposit_id:, tags:)
|
95
|
+
request = PatchDepositRequest.new(deposit_id, tags)
|
96
|
+
Unit::Resource::CheckDepositResource.update(request)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Confirm check deposit details
|
100
|
+
# @see https://docs.unit.co/check-deposits#confirm-check-deposit-details
|
101
|
+
# @param deposit_id [String]
|
102
|
+
def confirm_details(deposit_id:)
|
103
|
+
Unit::Resource::CheckDepositResource.confirm_details(deposit_id)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create check deposit
|
4
|
+
# @see https://docs.unit.co/check-deposits#create-check-deposit
|
5
|
+
module Unit
|
6
|
+
module CheckDeposit
|
7
|
+
class CreateCheckDepositRequest
|
8
|
+
attr_reader :account_id, :amount, :description, :tags, :idempotency_key
|
9
|
+
|
10
|
+
# @param account_id [String]
|
11
|
+
# @param amount [Integer]
|
12
|
+
# @param description [String]
|
13
|
+
# @param tags [Hash] - optional
|
14
|
+
# @param idempotency_key [String] - optional
|
15
|
+
def initialize(account_id, amount, description, tags = nil, idempotency_key = nil)
|
16
|
+
@account_id = account_id
|
17
|
+
@amount = amount
|
18
|
+
@description = description
|
19
|
+
@tags = tags
|
20
|
+
@idempotency_key = idempotency_key
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_json_api
|
24
|
+
payload = {
|
25
|
+
"data": {
|
26
|
+
"type": "checkDeposit",
|
27
|
+
"attributes": {
|
28
|
+
amount: amount,
|
29
|
+
description: description,
|
30
|
+
tags: tags,
|
31
|
+
idempotency_key: idempotency_key
|
32
|
+
},
|
33
|
+
"relationships": {
|
34
|
+
"account": Unit::Types::Relationship.new("account", account_id).to_hash
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
payload[:data][:attributes].compact!
|
39
|
+
payload.to_json
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to get a check deposit image
|
4
|
+
# @see https://docs.unit.co/check-deposits#get-specific-check-deposit-front-image
|
5
|
+
# @see https://docs.unit.co/check-deposits#get-specific-check-deposit-back-image
|
6
|
+
module Unit
|
7
|
+
module CheckDeposit
|
8
|
+
class GetImageRequest
|
9
|
+
attr_reader :deposit_id, :is_front_side
|
10
|
+
|
11
|
+
# @param deposit_id [String]
|
12
|
+
# @param is_front_side [Boolean] - optional
|
13
|
+
def initialize(deposit_id, is_front_side: true)
|
14
|
+
@deposit_id = deposit_id
|
15
|
+
@is_front_side = is_front_side
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to get check deposit by id
|
4
|
+
# @see https://docs.unit.co/check-deposits#get-specific-check-deposit
|
5
|
+
module Unit
|
6
|
+
module CheckDeposit
|
7
|
+
class GetRequest
|
8
|
+
attr_reader :deposit_id, :include
|
9
|
+
|
10
|
+
# @param deposit_id [String]
|
11
|
+
# @param include [Array<String>] - optional
|
12
|
+
def initialize(deposit_id, include = nil)
|
13
|
+
@deposit_id = deposit_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,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to list check deposits
|
4
|
+
# @see https://docs.unit.co/check-deposits#list-check-deposits
|
5
|
+
module Unit
|
6
|
+
module CheckDeposit
|
7
|
+
class ListDepositParams
|
8
|
+
attr_reader :limit, :offset, :account_id, :customer_id, :tags, :sort, :include
|
9
|
+
|
10
|
+
# @param limit [Integer] - optional
|
11
|
+
# @param offset [Integer] - optional
|
12
|
+
# @param account_id [String] - optional
|
13
|
+
# @param customer_id [String] - optional
|
14
|
+
# @param tags [Hash] - optional
|
15
|
+
# @param sort [String] - optional
|
16
|
+
# @param include [Array<String>] - optional
|
17
|
+
def initialize(limit = CHECK_DEPOSIT_LIMIT, offset = CHECK_DEPOSIT_OFFSET, account_id = nil,
|
18
|
+
customer_id = nil, tags = nil, sort = nil, include = nil)
|
19
|
+
@limit = limit
|
20
|
+
@offset = offset
|
21
|
+
@account_id = account_id
|
22
|
+
@customer_id = customer_id
|
23
|
+
@tags = tags
|
24
|
+
@sort = sort
|
25
|
+
@include = include
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_hash
|
29
|
+
params = {
|
30
|
+
"page[limit]": limit,
|
31
|
+
"page[offset]": offset,
|
32
|
+
"filter[accountId]": account_id,
|
33
|
+
"filter[customerId]": customer_id,
|
34
|
+
"filter[tags]": tags,
|
35
|
+
"sort": sort,
|
36
|
+
"include": include&.join(",")
|
37
|
+
}
|
38
|
+
params.compact
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to update check deposit
|
4
|
+
# @see https://docs.unit.co/check-deposits#update-check-deposit
|
5
|
+
module Unit
|
6
|
+
module CheckDeposit
|
7
|
+
class PatchDepositRequest
|
8
|
+
attr_reader :deposit_id, :tags
|
9
|
+
|
10
|
+
# @param deposit_id [String]
|
11
|
+
# @param tags [Hash] - optional
|
12
|
+
def initialize(deposit_id, tags)
|
13
|
+
@deposit_id = deposit_id
|
14
|
+
@tags = tags
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_json_api
|
18
|
+
payload = {
|
19
|
+
data: {
|
20
|
+
type: "checkDeposit",
|
21
|
+
attributes: { tags: tags }
|
22
|
+
}
|
23
|
+
}
|
24
|
+
payload[:data][:attributes].compact!
|
25
|
+
payload.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to upload a check deposit image
|
4
|
+
# @see https://docs.unit.co/check-deposits#upload-front-side-image
|
5
|
+
# @see https://docs.unit.co/check-deposits#upload-back-side-image
|
6
|
+
|
7
|
+
module Unit
|
8
|
+
module CheckDeposit
|
9
|
+
class UploadImageRequest
|
10
|
+
attr_reader :deposit_id, :file_content, :is_front_side
|
11
|
+
|
12
|
+
# @param deposit_id [String]
|
13
|
+
# @param file_content [String]
|
14
|
+
# @param is_front_side [Boolean] - optional
|
15
|
+
def initialize(deposit_id, file_content, is_front_side: true)
|
16
|
+
@deposit_id = deposit_id
|
17
|
+
@file_content = file_content
|
18
|
+
@is_front_side = is_front_side
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
module Counterparty
|
5
|
+
COUNTER_PARTY_LIMIT = 100
|
6
|
+
COUNTER_PARTY_OFFSET = 0
|
7
|
+
|
8
|
+
autoload :CreateCounterpartyRequest, "unit/models/counterparty/create_counterparty_request"
|
9
|
+
autoload :CreateWithPlaidTokenRequest, "unit/models/counterparty/create_with_plaid_token_request"
|
10
|
+
autoload :ListCounterpartyParams, "unit/models/counterparty/list_counterparty_params"
|
11
|
+
autoload :UpdateCounterpartyRequest, "unit/models/counterparty/update_counterparty_request"
|
12
|
+
|
13
|
+
class << self
|
14
|
+
# Create counterparty by calling Unit's API
|
15
|
+
# @see https://docs.unit.co/payments-counterparties/#create-counterparty
|
16
|
+
# @param customer_id [String]
|
17
|
+
# @param name [String]
|
18
|
+
# @param routing_number [String]
|
19
|
+
# @param account_number [String]
|
20
|
+
# @param account_type [String]
|
21
|
+
# @param type [String]
|
22
|
+
# @param tags [Hash] - optional
|
23
|
+
# @param permissions [String] - optional
|
24
|
+
# @param idempotency_key [String] - optional
|
25
|
+
def create_counterparty(customer_id:, name:, routing_number:, account_number:, account_type:, type:, tags: nil, permissions: nil, idempotency_key: nil)
|
26
|
+
request = CreateCounterpartyRequest.new(customer_id, name, routing_number, account_number, account_type, type, tags, permissions, idempotency_key)
|
27
|
+
Unit::Resource::CounterpartyResource.create_counterparty(request)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create counterparty with plaid token
|
31
|
+
# @see https://docs.unit.co/payments-counterparties/#create-counterparty-with-plaid-token
|
32
|
+
# @param customer_id [String]
|
33
|
+
# @param type [String]
|
34
|
+
# @param name [String]
|
35
|
+
# @param plaid_processor_token [String]
|
36
|
+
# @param verify_name [Boolean] - optional
|
37
|
+
# @param permissions [String] - optional
|
38
|
+
# @param tags [Hash] - optional
|
39
|
+
# @param idempotency_key [String] - optional
|
40
|
+
def create_with_plaid_token(customer_id:, type:, name:, plaid_processor_token:, verify_name: nil, permissions: nil, tags: nil, idempotency_key: nil)
|
41
|
+
request = CreateWithPlaidTokenRequest.new(customer_id, type, name, plaid_processor_token, verify_name, permissions, tags, idempotency_key)
|
42
|
+
Unit::Resource::CounterpartyResource.create_counterparty(request)
|
43
|
+
end
|
44
|
+
|
45
|
+
# List counterparties
|
46
|
+
# @see https://docs.unit.co/payments-counterparties/#list-counterparties
|
47
|
+
# @param limit [Integer] - optional
|
48
|
+
# @param offset [Integer] - optional
|
49
|
+
# @param customer_id [String] - optional
|
50
|
+
# @param account_number [String] - optional
|
51
|
+
# @param routing_number [String] - optional
|
52
|
+
# @param tags [Hash] - optional
|
53
|
+
# @param permissions [Array<String>] - optional
|
54
|
+
def list_counterparty(limit: COUNTER_PARTY_LIMIT, offset: COUNTER_PARTY_OFFSET, customer_id: nil, account_number: nil, routing_number: nil, tags: nil, permissions: nil)
|
55
|
+
params = ListCounterpartyParams.new(limit, offset, customer_id, account_number, routing_number, tags, permissions)
|
56
|
+
Unit::Resource::CounterpartyResource.list(params)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get counterparty by id
|
60
|
+
# @param counterparty_id [String]
|
61
|
+
# @see https://docs.unit.co/payments-counterparties/#get-one-counterparty
|
62
|
+
def get_counterparty(counterparty_id:)
|
63
|
+
Unit::Resource::CounterpartyResource.get_counterparty(counterparty_id)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Get counterparty balance
|
67
|
+
# @param counterparty_id [String]
|
68
|
+
# @see https://docs.unit.co/payments-counterparties/#get-counterparty-balance
|
69
|
+
def get_counterparty_balance(counterparty_id:)
|
70
|
+
Unit::Resource::CounterpartyResource.get_counterparty_balance(counterparty_id)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Update counterparty
|
74
|
+
# @see https://docs.unit.co/payments-counterparties/#list-counterparties
|
75
|
+
# @param counterparty_id [String]
|
76
|
+
# @param plaid_processor_token [String]
|
77
|
+
# @param verify_name [Boolean] - optional
|
78
|
+
# @param permissions [String] - optional
|
79
|
+
# @param tags [Hash] - optional
|
80
|
+
def update_counterparty(counterparty_id:, plaid_processor_token: nil, verify_name: nil, permissions: nil, tags: nil)
|
81
|
+
request = UpdateCounterpartyRequest.new(counterparty_id, plaid_processor_token, verify_name, permissions, tags)
|
82
|
+
Unit::Resource::CounterpartyResource.update_counterparty(request)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Delete counterparty
|
86
|
+
# @param counterparty_id [String]
|
87
|
+
# @see https://docs.unit.co/payments-counterparties/#get-one-counterparty
|
88
|
+
def delete_counterparty(counterparty_id:)
|
89
|
+
Unit::Resource::CounterpartyResource.delete(counterparty_id)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a counterparty
|
4
|
+
# @see https://docs.unit.co/payments-counterparties/#create-counterparty
|
5
|
+
module Unit
|
6
|
+
module Counterparty
|
7
|
+
class CreateCounterpartyRequest
|
8
|
+
attr_reader :customer_id, :name, :routing_number, :account_number, :account_type,
|
9
|
+
:type, :tags, :permissions, :idempotency_key
|
10
|
+
|
11
|
+
# @param customer_id [String]
|
12
|
+
# @param name [String]
|
13
|
+
# @param routing_number [String]
|
14
|
+
# @param account_number [String]
|
15
|
+
# @param account_type [String]
|
16
|
+
# @param type [String]
|
17
|
+
# @param tags [Hash] - optional
|
18
|
+
# @param permissions [String] - optional
|
19
|
+
# @param idempotency_key [String] - optional
|
20
|
+
def initialize(customer_id, name, routing_number, account_number, account_type, type, tags = nil, permissions = nil, idempotency_key = nil)
|
21
|
+
@customer_id = customer_id
|
22
|
+
@name = name
|
23
|
+
@routing_number = routing_number
|
24
|
+
@account_number = account_number
|
25
|
+
@account_type = account_type
|
26
|
+
@type = type
|
27
|
+
@tags = tags
|
28
|
+
@permissions = permissions
|
29
|
+
@idempotency_key = idempotency_key
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_json_api
|
33
|
+
payload = {
|
34
|
+
"data": {
|
35
|
+
"type": "achCounterparty",
|
36
|
+
"attributes": {
|
37
|
+
name: name,
|
38
|
+
routingNumber: routing_number,
|
39
|
+
accountNumber: account_number,
|
40
|
+
accountType: account_type,
|
41
|
+
type: type,
|
42
|
+
tags: tags,
|
43
|
+
permissions: permissions,
|
44
|
+
idempotencyKey: idempotency_key
|
45
|
+
},
|
46
|
+
"relationships": {
|
47
|
+
customer: Unit::Types::Relationship.new("customer", customer_id).to_hash
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
payload[:data][:attributes].compact!
|
52
|
+
payload.to_json
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a counterparty with plaid token
|
4
|
+
# @see https://docs.unit.co/payments-counterparties/#create-counterparty-with-plaid-token
|
5
|
+
module Unit
|
6
|
+
module Counterparty
|
7
|
+
class CreateWithPlaidTokenRequest
|
8
|
+
attr_reader :customer_id, :type, :name, :plaid_processor_token,
|
9
|
+
:verify_name, :permissions, :tags, :idempotency_key
|
10
|
+
|
11
|
+
# @param customer_id [String]
|
12
|
+
# @param type [String]
|
13
|
+
# @param name [String]
|
14
|
+
# @param plaid_processor_token [String]
|
15
|
+
# @param verify_name [Boolean] - optional
|
16
|
+
# @param permissions [String] - optional
|
17
|
+
# @param tags [Hash] - optional
|
18
|
+
# @param idempotency_key [String] - optional
|
19
|
+
def initialize(customer_id, type, name, plaid_processor_token, verify_name = nil, permissions = nil, tags = nil, idempotency_key = nil)
|
20
|
+
@customer_id = customer_id
|
21
|
+
@type = type
|
22
|
+
@name = name
|
23
|
+
@plaid_processor_token = plaid_processor_token
|
24
|
+
@verify_name = verify_name
|
25
|
+
@permissions = permissions
|
26
|
+
@tags = tags
|
27
|
+
@idempotency_key = idempotency_key
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_json_api
|
31
|
+
payload = {
|
32
|
+
"data": {
|
33
|
+
"type": "achCounterparty",
|
34
|
+
"attributes": {
|
35
|
+
type: type,
|
36
|
+
name: name,
|
37
|
+
plaidProcessorToken: plaid_processor_token,
|
38
|
+
verifyName: verify_name,
|
39
|
+
permissions: permissions,
|
40
|
+
tags: tags,
|
41
|
+
idempotencyKey: idempotency_key
|
42
|
+
},
|
43
|
+
"relationships": {
|
44
|
+
customer: Unit::Types::Relationship.new("customer", customer_id).to_hash
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
payload[:data][:attributes].compact!
|
49
|
+
payload.to_json
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to list counterparties
|
4
|
+
# @see https://docs.unit.co/payments-counterparties/#list-counterparties
|
5
|
+
module Unit
|
6
|
+
module Counterparty
|
7
|
+
class ListCounterpartyParams
|
8
|
+
attr_reader :limit, :offset, :customer_id, :account_number, :routing_number, :tags, :permissions
|
9
|
+
|
10
|
+
# @param limit [Integer] - optional
|
11
|
+
# @param offset [Integer] - optional
|
12
|
+
# @param customer_id [String] - optional
|
13
|
+
# @param account_number [String] - optional
|
14
|
+
# @param routing_number [String] - optional
|
15
|
+
# @param tags [Hash] - optional
|
16
|
+
# @param permissions [Array<String>] - optional
|
17
|
+
def initialize(limit = COUNTER_PARTY_LIMIT, offset = COUNTER_PARTY_OFFSET, customer_id = nil,
|
18
|
+
account_number = nil, routing_number = nil, tags = nil, permissions = nil)
|
19
|
+
@limit = limit
|
20
|
+
@offset = offset
|
21
|
+
@customer_id = customer_id
|
22
|
+
@account_number = account_number
|
23
|
+
@routing_number = routing_number
|
24
|
+
@tags = tags
|
25
|
+
@permissions = permissions
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_hash
|
29
|
+
params =
|
30
|
+
{
|
31
|
+
"page[limit]": limit,
|
32
|
+
"page[offset]": offset,
|
33
|
+
"filter[customerId]": customer_id,
|
34
|
+
"filter[accountNumber]": account_number,
|
35
|
+
"filter[routingNumber]": routing_number,
|
36
|
+
"filter[tags]": tags
|
37
|
+
}
|
38
|
+
permissions&.each_with_index&.map do |val, index|
|
39
|
+
params.merge!({ "filter[permissions][#{index}]": val })
|
40
|
+
end
|
41
|
+
params.compact
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to update a counterparty
|
4
|
+
# @see https://docs.unit.co/payments-counterparties/#list-counterparties
|
5
|
+
module Unit
|
6
|
+
module Counterparty
|
7
|
+
class UpdateCounterpartyRequest
|
8
|
+
attr_reader :counterparty_id, :plaid_processor_token, :verify_name, :permissions, :tags
|
9
|
+
|
10
|
+
# @param counterparty_id [String]
|
11
|
+
# @param plaid_processor_token [String]
|
12
|
+
# @param verify_name [Boolean] - optional
|
13
|
+
# @param permissions [String] - optional
|
14
|
+
# @param tags [Hash] - optional
|
15
|
+
def initialize(counterparty_id, plaid_processor_token, verify_name = nil, permissions = nil, tags = nil)
|
16
|
+
@counterparty_id = counterparty_id
|
17
|
+
@plaid_processor_token = plaid_processor_token
|
18
|
+
@verify_name = verify_name
|
19
|
+
@permissions = permissions
|
20
|
+
@tags = tags
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_json_api
|
24
|
+
payload = {
|
25
|
+
"data": {
|
26
|
+
"type": "counterparty",
|
27
|
+
attributes: {
|
28
|
+
plaidProcessorToken: plaid_processor_token,
|
29
|
+
verifyName: verify_name,
|
30
|
+
permissions: permissions,
|
31
|
+
tags: tags
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
payload[:data][:attributes].compact!
|
36
|
+
payload.to_json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -6,8 +6,9 @@ require "json"
|
|
6
6
|
|
7
7
|
module HttpHelper
|
8
8
|
VALUES = [:"filter[searchRadius]"].freeze
|
9
|
-
|
10
|
-
|
9
|
+
RESPONSE_TYPES = %w[delete image].freeze
|
10
|
+
def self.get(url, headers:, params: nil, response_type: nil)
|
11
|
+
make_request(Net::HTTP::Get, url, headers, params: params, response_type: response_type)
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.post(url, headers:, body: nil)
|
@@ -22,11 +23,11 @@ module HttpHelper
|
|
22
23
|
make_request(Net::HTTP::Patch, url, headers, body: body)
|
23
24
|
end
|
24
25
|
|
25
|
-
def self.delete(url, headers:, body: nil)
|
26
|
-
make_request(Net::HTTP::Delete, url, headers, body: body)
|
26
|
+
def self.delete(url, headers:, body: nil, response_type: nil)
|
27
|
+
make_request(Net::HTTP::Delete, url, headers, body: body, response_type: response_type)
|
27
28
|
end
|
28
29
|
|
29
|
-
def self.make_request(net_http, url, headers, body: nil, params: nil)
|
30
|
+
def self.make_request(net_http, url, headers, body: nil, params: nil, response_type: nil)
|
30
31
|
uri = params.nil? ? URI(url) : URI("#{url}?#{encode(params)}")
|
31
32
|
host = uri.host.to_s
|
32
33
|
port = uri.port
|
@@ -36,13 +37,13 @@ module HttpHelper
|
|
36
37
|
request = net_http.new uri, headers
|
37
38
|
request.body = body unless body.nil?
|
38
39
|
response = http.request request
|
39
|
-
response.body = response_check(response)
|
40
|
+
response.body = response_check(response, response_type)
|
40
41
|
response
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
|
-
def self.response_check(response)
|
45
|
-
if response.body.include?("html") || response.body.include?("PDF")
|
45
|
+
def self.response_check(response, response_type = nil)
|
46
|
+
if RESPONSE_TYPES.include?(response_type) || response.body.include?("html") || response.body.include?("PDF")
|
46
47
|
response.body
|
47
48
|
else
|
48
49
|
JSON.parse(response.body)
|
data/lib/unit/version.rb
CHANGED
data/lib/unit_ruby_sdk.rb
CHANGED
@@ -12,6 +12,9 @@ module Unit
|
|
12
12
|
autoload :Card, "unit/models/card/card"
|
13
13
|
autoload :Statement, "unit/models/statement/statement"
|
14
14
|
autoload :AtmLocation, "unit/models/atm_location/atm_location"
|
15
|
+
autoload :CheckDeposit, "unit/models/check_deposit/check_deposit"
|
16
|
+
autoload :Counterparty, "unit/models/counterparty/counterparty"
|
17
|
+
|
15
18
|
module Resource
|
16
19
|
autoload :ApplicationResource, "unit/api_resources/application_resource"
|
17
20
|
autoload :CustomerResource, "unit/api_resources/customer_resource"
|
@@ -22,6 +25,8 @@ module Unit
|
|
22
25
|
autoload :CardResource, "unit/api_resources/card_resource"
|
23
26
|
autoload :StatementResource, "unit/api_resources/statement_resource"
|
24
27
|
autoload :AtmLocationResource, "unit/api_resources/atm_location_resource"
|
28
|
+
autoload :CheckDepositResource, "unit/api_resources/check_deposit_resource"
|
29
|
+
autoload :CounterpartyResource, "unit/api_resources/counterparty_resource"
|
25
30
|
end
|
26
31
|
|
27
32
|
module Types
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unit_ruby_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Unit
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot_rails
|
@@ -100,6 +100,8 @@ files:
|
|
100
100
|
- lib/unit/api_resources/atm_location_resource.rb
|
101
101
|
- lib/unit/api_resources/base_resource.rb
|
102
102
|
- lib/unit/api_resources/card_resource.rb
|
103
|
+
- lib/unit/api_resources/check_deposit_resource.rb
|
104
|
+
- lib/unit/api_resources/counterparty_resource.rb
|
103
105
|
- lib/unit/api_resources/customer_resource.rb
|
104
106
|
- lib/unit/api_resources/payment_resource.rb
|
105
107
|
- lib/unit/api_resources/statement_resource.rb
|
@@ -136,6 +138,18 @@ files:
|
|
136
138
|
- lib/unit/models/card/create_individual_virtual_card_request.rb
|
137
139
|
- lib/unit/models/card/list_card_params.rb
|
138
140
|
- lib/unit/models/card/replace_card_request.rb
|
141
|
+
- lib/unit/models/check_deposit/check_deposit.rb
|
142
|
+
- lib/unit/models/check_deposit/create_check_deposit_request.rb
|
143
|
+
- lib/unit/models/check_deposit/get_image_request.rb
|
144
|
+
- lib/unit/models/check_deposit/get_request.rb
|
145
|
+
- lib/unit/models/check_deposit/list_deposit_params.rb
|
146
|
+
- lib/unit/models/check_deposit/patch_deposit_request.rb
|
147
|
+
- lib/unit/models/check_deposit/upload_image_request.rb
|
148
|
+
- lib/unit/models/counterparty/counterparty.rb
|
149
|
+
- lib/unit/models/counterparty/create_counterparty_request.rb
|
150
|
+
- lib/unit/models/counterparty/create_with_plaid_token_request.rb
|
151
|
+
- lib/unit/models/counterparty/list_counterparty_params.rb
|
152
|
+
- lib/unit/models/counterparty/update_counterparty_request.rb
|
139
153
|
- lib/unit/models/customer/add_authorized_users_request.rb
|
140
154
|
- lib/unit/models/customer/archive_customer_request.rb
|
141
155
|
- lib/unit/models/customer/customer.rb
|