unit_ruby_sdk 1.0.5 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5668d5b6f37c4258503b7997aea3921af80a511c16c3b41a93dbb5088d1101b5
4
- data.tar.gz: 6e4d664998ceb9e4d33433357892b9e16e06bb59e5991b2d9e41a9ada74444e0
3
+ metadata.gz: d20a17ad0586962f7984a43e052bbe2f8a1637adf318b91cbb35c2bd65268efe
4
+ data.tar.gz: 113eeaae42a13b4d89d31b870c935fc36d6221c4a09c3e4e8770c19e6b96a724
5
5
  SHA512:
6
- metadata.gz: 89fc34d5d4563ce3ba91507f352aa29d402e8e6a91cf108f3429f3abdc3f3ac936a3e00f8fff5df002fab987188b20dc150f8fc8ab1c4a132049be202becc50e
7
- data.tar.gz: d93fed682b4d440b17ae9871f2323b68ffbd0a9660524e5e78b65d29d80f3f4e529fc5b55a800e2aa5fde4cbaf2915c8e0438da7f36260fe76b5dd211fb8bcc7
6
+ metadata.gz: '0178fda07e7f4f9b3011c8e5b1dfa7a5fc4efffdc9d77b50bfabdab34c174293a2ca4cc90b77cb521646bba08d34b52732509c1652f96f3eab8bd0d38e573976'
7
+ data.tar.gz: 8a2b410f41503b00a1cd23637e8f332d96b4116e7a06d980894adff0f8e5ebf9343652629b6177e1890077805b88bcaded6e5dd525590671bacbae77870dc5ab
data/README.md CHANGED
@@ -181,6 +181,22 @@ puts counterparty.id
181
181
  puts wire_payment.id
182
182
  ```
183
183
 
184
+ ### Creating a bulk payment
185
+ ```ruby
186
+ address = Unit::Types::Address.new('123 Main St', 'San Francisco', 'CA', '94205', 'US')
187
+ wire_counterparty = Unit::Types::WireCounterparty.new("Jane Doe", "27573", "812345678", address)
188
+ counterparty = Unit::Types::Counterparty.new("Jane Doe", "27573", "812345678", "Checking")
189
+ book_payment_request = Unit::Payment::CreateBookPaymentRequest.new(amount: 1000, description: "test payment", account_id: "27573", counterparty_account_id: "36981", tags: { "test": "test-tag" })
190
+ wire_payment_request = Unit::Payment::CreateWirePaymentRequest.new(amount: 1000, description: "test payment", account_id: "27573", counterparty: wire_counterparty, tags: { "test": "test-tag" })
191
+ ach_payment_inline_request = Unit::Payment::CreateAchPaymentInlineRequest.new(amount: 1000, direction: "Credit", counterparty: counterparty, description: "test payment", account_id: "27573", tags: { "test": "test-tag" })
192
+ ach_payment_linked_request = Unit::Payment::CreatePaymentLinkedRequest.new(amount: 1000, direction: "Credit", description: "test payment", account_id: "27573", counterparty_id: "313118", tags: { "test": "test-tag" })
193
+ ach_payment_plaid_token_request = Unit::Payment::CreateWithPlaidTokenRequest.new(amount: 1000, direction: "Credit", description: "test payment", account_id: "27573", plaid_processor_token: "processor-sandbox-fc8b9c23-b400-40f9-8ee8-c2cabd719721", tags: { "test": "test-tag" })
194
+
195
+ response = Unit::Payment.create_bulk_payment(
196
+ requests: [book_payment_request, wire_payment_request, ach_payment_inline_request, ach_payment_linked_request, ach_payment_plaid_token_request])
197
+ bulk_payment = response.data
198
+ puts bulk_payment.id
199
+ ```
184
200
  ### Logging Errors
185
201
 
186
202
  ```ruby
@@ -19,6 +19,14 @@ module Unit
19
19
  response_handler(response)
20
20
  end
21
21
 
22
+ # Create a new bulk payment by calling Unit's API
23
+ # @param request [BulkPaymentRequest]
24
+ # @return [UnitResponse, UnitError]
25
+ def create_bulk_payment(request)
26
+ response = HttpHelper.post("#{api_url}/payments/bulk", body: request, headers: headers)
27
+ response_handler(response)
28
+ end
29
+
22
30
  # Update a payment by calling Unit's API
23
31
  # @param request [PatchBookPaymentRequest, PatchAchPaymentRequest]
24
32
  # @return [UnitResponse, UnitError]
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ # class for serializing payment requests
6
+ module Unit
7
+ module Payment
8
+ class BulkPaymentRequest
9
+ def self.serialize(requests)
10
+ payload = requests.map(&:change_attributes)
11
+ { "data": payload }.to_json
12
+ end
13
+ end
14
+ end
15
+ end
@@ -18,8 +18,8 @@ module Unit
18
18
  # @param tags [Hash] - optional
19
19
  # @param same_day [Boolean] - optional
20
20
  # @param sec_code [String] - optional
21
- def initialize(account_id, amount, direction, counterparty, description,
22
- addenda = nil, idempotency_key = nil, tags = nil, same_day = nil, sec_code = nil)
21
+ def initialize(account_id:, amount:, direction:, counterparty:, description:,
22
+ addenda: nil, idempotency_key: nil, tags: nil, same_day: nil, sec_code: nil)
23
23
  @account_id = account_id
24
24
  @amount = amount
25
25
  @direction = direction
@@ -34,27 +34,37 @@ module Unit
34
34
 
35
35
  def to_json_api
36
36
  payload = {
37
- "data": {
38
- "type": "achPayment",
39
- "attributes": {
40
- amount: amount,
41
- direction: direction,
42
- counterparty: counterparty.represent,
43
- description: description,
44
- addenda: addenda,
45
- idempotencyKey: idempotency_key,
46
- tags: tags,
47
- sameDay: same_day,
48
- secCode: sec_code
49
- },
50
- "relationships": {
51
- "account": Unit::Types::Relationship.new("account", account_id).to_hash
52
- }
53
- }
37
+ "data": to_hash
54
38
  }
55
39
  payload[:data][:attributes].compact!
56
40
  payload.to_json
57
41
  end
42
+
43
+ def to_hash
44
+ {
45
+ "type": "achPayment",
46
+ "attributes": {
47
+ amount: amount,
48
+ direction: direction,
49
+ counterparty: counterparty.represent,
50
+ description: description,
51
+ addenda: addenda,
52
+ idempotencyKey: idempotency_key,
53
+ tags: tags,
54
+ sameDay: same_day,
55
+ secCode: sec_code
56
+ },
57
+ "relationships": {
58
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash
59
+ }
60
+ }
61
+ end
62
+
63
+ def change_attributes
64
+ payload = to_hash
65
+ payload[:attributes].compact!
66
+ payload
67
+ end
58
68
  end
59
69
  end
60
70
  end
@@ -14,8 +14,8 @@ module Unit
14
14
  # @param transaction_summary_override [String] - optional
15
15
  # @param idempotency_key [String] - optional
16
16
  # @param tags [Hash] - optional
17
- def initialize(amount, description, account_id, counterparty_account_id, transaction_summary_override = nil,
18
- idempotency_key = nil, tags = nil)
17
+ def initialize(amount:, description:, account_id:, counterparty_account_id:, transaction_summary_override: nil,
18
+ idempotency_key: nil, tags: nil)
19
19
  @amount = amount
20
20
  @description = description
21
21
  @account_id = account_id
@@ -27,22 +27,32 @@ module Unit
27
27
 
28
28
  def to_json_api
29
29
  payload = {
30
- data: {
31
- type: "bookPayment",
32
- attributes: {
33
- amount: amount,
34
- description: description,
35
- transactionSummaryOverride: transaction_summary_override,
36
- idempotencyKey: idempotency_key,
37
- tags: tags
38
- },
39
- relationships: { account: Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
40
- counterpartyAccount: Unit::Types::Relationship.new("depositAccount", counterparty_account_id).to_hash }
41
- }
30
+ data: to_hash
42
31
  }
43
32
  payload[:data][:attributes].compact!
44
33
  payload.to_json
45
34
  end
35
+
36
+ def to_hash
37
+ {
38
+ type: "bookPayment",
39
+ attributes: {
40
+ amount: amount,
41
+ description: description,
42
+ transactionSummaryOverride: transaction_summary_override,
43
+ idempotencyKey: idempotency_key,
44
+ tags: tags
45
+ },
46
+ relationships: { account: Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
47
+ counterpartyAccount: Unit::Types::Relationship.new("depositAccount", counterparty_account_id).to_hash }
48
+ }
49
+ end
50
+
51
+ def change_attributes
52
+ payload = to_hash
53
+ payload[:attributes].compact!
54
+ payload
55
+ end
46
56
  end
47
57
  end
48
58
  end
@@ -20,9 +20,9 @@ module Unit
20
20
  # @param verify_counterparty_balance [Boolean] - optional
21
21
  # @param same_day [Boolean] - optional
22
22
  # @param sec_code [String] - optional
23
- def initialize(account_id, counterparty_id, amount, direction, description,
24
- addenda = nil, idempotency_key = nil, tags = nil, verify_counterparty_balance = nil,
25
- same_day = nil, sec_code = nil)
23
+ def initialize(account_id:, counterparty_id:, amount:, direction:, description:,
24
+ addenda: nil, idempotency_key: nil, tags: nil, verify_counterparty_balance: nil,
25
+ same_day: nil, sec_code: nil)
26
26
  @account_id = account_id
27
27
  @counterparty_id = counterparty_id
28
28
  @amount = amount
@@ -38,28 +38,38 @@ module Unit
38
38
 
39
39
  def to_json_api
40
40
  payload = {
41
- "data": {
42
- "type": "achPayment",
43
- "attributes": {
44
- amount: amount,
45
- direction: direction,
46
- description: description,
47
- addenda: addenda,
48
- idempotencyKey: idempotency_key,
49
- tags: tags,
50
- verifyCounterpartyBalance: verify_counterparty_balance,
51
- sameDay: same_day,
52
- secCode: sec_code
53
- },
54
- "relationships": {
55
- "account": Unit::Types::Relationship.new("account", account_id).to_hash,
56
- "counterparty": Unit::Types::Relationship.new("counterparty", counterparty_id).to_hash
57
- }
58
- }
41
+ "data": to_hash
59
42
  }
60
43
  payload[:data][:attributes].compact!
61
44
  payload.to_json
62
45
  end
46
+
47
+ def to_hash
48
+ {
49
+ "type": "achPayment",
50
+ "attributes": {
51
+ amount: amount,
52
+ direction: direction,
53
+ description: description,
54
+ addenda: addenda,
55
+ idempotencyKey: idempotency_key,
56
+ tags: tags,
57
+ verifyCounterpartyBalance: verify_counterparty_balance,
58
+ sameDay: same_day,
59
+ secCode: sec_code
60
+ },
61
+ "relationships": {
62
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash,
63
+ "counterparty": Unit::Types::Relationship.new("counterparty", counterparty_id).to_hash
64
+ }
65
+ }
66
+ end
67
+
68
+ def change_attributes
69
+ payload = to_hash
70
+ payload[:attributes].compact!
71
+ payload
72
+ end
63
73
  end
64
74
  end
65
75
  end
@@ -13,7 +13,7 @@ module Unit
13
13
  # @param counterparty [WireCounterparty]
14
14
  # @param idempotency_key [String] - optional
15
15
  # @param tags [Hash] - optional
16
- def initialize(account_id, amount, description, counterparty, idempotency_key = nil, tags = nil)
16
+ def initialize(account_id:, amount:, description:, counterparty:, idempotency_key: nil, tags: nil)
17
17
  @account_id = account_id
18
18
  @amount = amount
19
19
  @description = description
@@ -24,21 +24,31 @@ module Unit
24
24
 
25
25
  def to_json_api
26
26
  payload = {
27
- data: {
28
- type: "wirePayment",
29
- attributes: {
30
- amount: amount,
31
- description: description,
32
- counterparty: counterparty.represent,
33
- idempotencyKey: idempotency_key,
34
- tags: tags
35
- },
36
- relationships: { account: Unit::Types::Relationship.new("account", account_id).to_hash }
37
- }
27
+ data: to_hash
38
28
  }
39
29
  payload[:data][:attributes].compact!
40
30
  payload.to_json
41
31
  end
32
+
33
+ def to_hash
34
+ {
35
+ type: "wirePayment",
36
+ attributes: {
37
+ amount: amount,
38
+ description: description,
39
+ counterparty: counterparty.represent,
40
+ idempotencyKey: idempotency_key,
41
+ tags: tags
42
+ },
43
+ relationships: { account: Unit::Types::Relationship.new("account", account_id).to_hash }
44
+ }
45
+ end
46
+
47
+ def change_attributes
48
+ payload = to_hash
49
+ payload[:attributes].compact!
50
+ payload
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -22,9 +22,9 @@ module Unit
22
22
  # @param verify_counterparty_balance [Boolean] - optional
23
23
  # @param same_day [Boolean] - optional
24
24
  # @param sec_code [String] - optional
25
- def initialize(account_id, amount, direction, description, plaid_processor_token,
26
- addenda = nil, idempotency_key = nil, counterparty_name = nil, tags = nil,
27
- verify_counterparty_balance = nil, same_day = nil, sec_code = nil)
25
+ def initialize(account_id:, amount:, direction:, description:, plaid_processor_token:,
26
+ addenda: nil, idempotency_key: nil, counterparty_name: nil, tags: nil,
27
+ verify_counterparty_balance: nil, same_day: nil, sec_code: nil)
28
28
  @account_id = account_id
29
29
  @amount = amount
30
30
  @direction = direction
@@ -41,29 +41,39 @@ module Unit
41
41
 
42
42
  def to_json_api
43
43
  payload = {
44
- "data": {
45
- "type": "achPayment",
46
- "attributes": {
47
- amount: amount,
48
- direction: direction,
49
- description: description,
50
- plaidProcessorToken: plaid_processor_token,
51
- addenda: addenda,
52
- idempotencyKey: idempotency_key,
53
- counterpartyName: counterparty_name,
54
- tags: tags,
55
- verifyCounterpartyBalance: verify_counterparty_balance,
56
- sameDay: same_day,
57
- secCode: sec_code
58
- },
59
- "relationships": {
60
- "account": Unit::Types::Relationship.new("account", account_id).to_hash
61
- }
62
- }
44
+ "data": to_hash
63
45
  }
64
46
  payload[:data][:attributes].compact!
65
47
  payload.to_json
66
48
  end
49
+
50
+ def to_hash
51
+ {
52
+ "type": "achPayment",
53
+ "attributes": {
54
+ amount: amount,
55
+ direction: direction,
56
+ description: description,
57
+ plaidProcessorToken: plaid_processor_token,
58
+ addenda: addenda,
59
+ idempotencyKey: idempotency_key,
60
+ counterpartyName: counterparty_name,
61
+ tags: tags,
62
+ verifyCounterpartyBalance: verify_counterparty_balance,
63
+ sameDay: same_day,
64
+ secCode: sec_code
65
+ },
66
+ "relationships": {
67
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash
68
+ }
69
+ }
70
+ end
71
+
72
+ def change_attributes
73
+ payload = to_hash
74
+ payload[:attributes].compact!
75
+ payload
76
+ end
67
77
  end
68
78
  end
69
79
  end
@@ -13,6 +13,7 @@ module Unit
13
13
  autoload :CreateWirePaymentRequest, "unit/models/payment/create_wire_payment_request"
14
14
  autoload :ListPaymentParams, "unit/models/payment/list_payment_params"
15
15
  autoload :GetRequest, "unit/models/payment/get_request"
16
+ autoload :BulkPaymentRequest, "unit/models/payment/bulk_payment_request"
16
17
  class << self
17
18
  # Create a new book payment by calling Unit's API
18
19
  # @see https://docs.unit.co/book-payments#book-payments
@@ -26,8 +27,9 @@ module Unit
26
27
  # @return [UnitResponse, UnitError]
27
28
  def create_book_payment(amount:, description:, account_id:, counterparty_account_id:, transaction_summary_override: nil,
28
29
  idempotency_key: nil, tags: nil)
29
- request = Unit::Payment::CreateBookPaymentRequest.new(amount, description, account_id, counterparty_account_id, transaction_summary_override,
30
- idempotency_key, tags)
30
+ request = Unit::Payment::CreateBookPaymentRequest.new(amount: amount, description: description, account_id: account_id, counterparty_account_id: counterparty_account_id, transaction_summary_override: transaction_summary_override,
31
+ idempotency_key: idempotency_key, tags: tags)
32
+
31
33
  Unit::Resource::PaymentResource.create_payment(request)
32
34
  end
33
35
 
@@ -56,8 +58,8 @@ module Unit
56
58
  def create_ach_payment_inline(account_id:, amount:, direction:, counterparty:,
57
59
  description:, addenda: nil, idempotency_key: nil, tags: nil,
58
60
  same_day: nil, sec_code: nil)
59
- request = Unit::Payment::CreateAchPaymentInlineRequest.new(account_id, amount, direction, counterparty, description,
60
- addenda, idempotency_key, tags, same_day, sec_code)
61
+ request = Unit::Payment::CreateAchPaymentInlineRequest.new(account_id: account_id, amount: amount, direction: direction, counterparty: counterparty, description: description, addenda: addenda, idempotency_key: idempotency_key,
62
+ tags: tags, same_day: same_day, sec_code: sec_code)
61
63
  Unit::Resource::PaymentResource.create_payment(request)
62
64
  end
63
65
 
@@ -77,9 +79,8 @@ module Unit
77
79
  def create_ach_payment_linked(account_id:, counterparty_id:, amount:, direction:,
78
80
  description:, addenda: nil, idempotency_key: nil, tags: nil,
79
81
  verify_counterparty_balance: nil, same_day: nil, sec_code: nil)
80
- request = Unit::Payment::CreatePaymentLinkedRequest.new(account_id, counterparty_id, amount, direction,
81
- description, addenda, idempotency_key, tags,
82
- verify_counterparty_balance, same_day, sec_code)
82
+ request = Unit::Payment::CreatePaymentLinkedRequest.new(account_id: account_id, counterparty_id: counterparty_id, amount: amount, direction: direction, description: description, addenda: addenda, idempotency_key: idempotency_key,
83
+ tags: tags, verify_counterparty_balance: verify_counterparty_balance, same_day: same_day, sec_code: sec_code)
83
84
  Unit::Resource::PaymentResource.create_payment(request)
84
85
  end
85
86
 
@@ -100,9 +101,8 @@ module Unit
100
101
  def create_ach_payment_with_plaid_token(account_id:, amount:, direction:, description:, plaid_processor_token:,
101
102
  addenda: nil, idempotency_key: nil, counterparty_name: nil, tags: nil,
102
103
  verify_counterparty_balance: nil, same_day: nil, sec_code: nil)
103
- request = Unit::Payment::CreateWithPlaidTokenRequest.new(account_id, amount, direction, description, plaid_processor_token,
104
- addenda, idempotency_key, counterparty_name, tags,
105
- verify_counterparty_balance, same_day, sec_code)
104
+ request = Unit::Payment::CreateWithPlaidTokenRequest.new(account_id: account_id, amount: amount, direction: direction, description: description, plaid_processor_token: plaid_processor_token, addenda: addenda, idempotency_key: idempotency_key,
105
+ counterparty_name: counterparty_name, tags: tags, verify_counterparty_balance: verify_counterparty_balance, same_day: same_day, sec_code: sec_code)
106
106
  Unit::Resource::PaymentResource.create_payment(request)
107
107
  end
108
108
 
@@ -131,7 +131,7 @@ module Unit
131
131
  # @param idempotency_key [String] - optional
132
132
  # @param tags [Hash] - optional
133
133
  def create_wire_payment(account_id:, amount:, description:, counterparty:, idempotency_key: nil, tags: nil)
134
- request = Unit::Payment::CreateWirePaymentRequest.new(account_id, amount, description, counterparty, idempotency_key, tags)
134
+ request = Unit::Payment::CreateWirePaymentRequest.new(account_id: account_id, amount: amount, description: description, counterparty: counterparty, idempotency_key: idempotency_key, tags: tags)
135
135
  Unit::Resource::PaymentResource.create_payment(request)
136
136
  end
137
137
 
@@ -173,6 +173,14 @@ module Unit
173
173
  request = Unit::Payment::GetRequest.new(payment_id, include)
174
174
  Unit::Resource::PaymentResource.get_payment(request)
175
175
  end
176
+
177
+ # Create a bulk payment by calling Unit's API
178
+ # @see https://docs.unit.co/payments/#bulk-payments
179
+ # @param requests [Array<CreateAchPaymentInlineRequest, CreatePaymentLinkedRequest, CreateBookPaymentRequest, CreateWithPlaidTokenRequest, CreateWirePaymentRequest>]
180
+ def create_bulk_payment(requests:)
181
+ request = Unit::Payment::BulkPaymentRequest.serialize(requests)
182
+ Unit::Resource::PaymentResource.create_bulk_payment(request)
183
+ end
176
184
  end
177
185
  end
178
186
  end
data/lib/unit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Unit
4
- VERSION = "1.0.5"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unit_ruby_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unit
@@ -163,6 +163,7 @@ files:
163
163
  - lib/unit/models/customer/patch_business_customer_request.rb
164
164
  - lib/unit/models/customer/patch_individual_customer_request.rb
165
165
  - lib/unit/models/customer/remove_authorized_users_request.rb
166
+ - lib/unit/models/payment/bulk_payment_request.rb
166
167
  - lib/unit/models/payment/create_ach_payment_inline_request.rb
167
168
  - lib/unit/models/payment/create_book_payment_request.rb
168
169
  - lib/unit/models/payment/create_payment_linked_request.rb