unit_ruby_sdk 0.1.3 → 0.1.4
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 +24 -0
- data/lib/unit/api_resources/api_token_resource.rb +59 -0
- data/lib/unit/api_resources/payment_resource.rb +32 -0
- data/lib/unit/api_resources/transaction_resource.rb +40 -0
- data/lib/unit/models/account/deposit/balance_history_request.rb +1 -1
- data/lib/unit/models/api_token/api_token.rb +89 -0
- data/lib/unit/models/api_token/customer/create_customer_token_request.rb +41 -0
- data/lib/unit/models/api_token/customer/create_customer_token_verification.rb +37 -0
- data/lib/unit/models/api_token/customer/create_token_using_jwt_request.rb +30 -0
- data/lib/unit/models/api_token/org/create_api_token_request.rb +40 -0
- data/lib/unit/models/application/list_application_params.rb +1 -1
- data/lib/unit/models/customer/list_customer_params.rb +1 -1
- data/lib/unit/models/payment/create_book_payment_request.rb +49 -0
- data/lib/unit/models/payment/patch_book_payment_request.rb +31 -0
- data/lib/unit/models/payment/payment.rb +37 -0
- data/lib/unit/models/transaction/get_transaction_params.rb +28 -0
- data/lib/unit/models/transaction/list_transaction_params.rb +70 -0
- data/lib/unit/models/transaction/patch_tags_request.rb +33 -0
- data/lib/unit/models/transaction/transaction.rb +60 -0
- data/lib/unit/types/restricted_resource.rb +23 -0
- data/lib/unit/utils/http_helper.rb +1 -1
- data/lib/unit/version.rb +1 -1
- data/lib/unit_ruby_sdk.rb +7 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14fc2502ef67bd580d1fb1d8ed06af33d22d99161bce1fa79ea98ac7acc9dad6
|
4
|
+
data.tar.gz: c0df3342ca09be9cb8f3ded2ff6717f188620716b0a8118b7850a19143b0ab4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1270a0a50b9e23a8608716098ea341708a18233d290e124416aed5be9a564a28e4c4d7b4f1c59a8224e74ae54746dc51c3908bdf1bb790df79dc810ba173602f
|
7
|
+
data.tar.gz: 5f4fac2c94ec93621ca4541ebc9c80a1bc0f2c0590f8503a1133d7b4fe437b783c0488ea42665f771d212c7959ac91837229f7917eec148ea7246e272a78a066
|
data/README.md
CHANGED
@@ -58,6 +58,30 @@ customer = Unit::Customer.list_customers.first
|
|
58
58
|
puts customer.id
|
59
59
|
```
|
60
60
|
|
61
|
+
###
|
62
|
+
### Creating a Payment
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require 'unit_ruby_sdk'
|
66
|
+
|
67
|
+
response = Unit::Payment.create_book_payment(
|
68
|
+
amount: 10000,
|
69
|
+
description: 'Payment for order #123',
|
70
|
+
relationships: { account: Unit::Types::Relationship.new("depositAccount", "12345").to_hash,
|
71
|
+
counterpartyAccount: Unit::Types::Relationship.new("depositAccount", "36221").to_hash }
|
72
|
+
)
|
73
|
+
payment = response.data
|
74
|
+
puts payment.id
|
75
|
+
```
|
76
|
+
|
77
|
+
### Get a transaction by id
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
response = Unit::Transaction.get_transaction(transaction_id: '12345', account_id: '72345')
|
81
|
+
transaction = response.data
|
82
|
+
puts transaction.id
|
83
|
+
```
|
84
|
+
|
61
85
|
### Logging Errors
|
62
86
|
|
63
87
|
```ruby
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base_resource"
|
4
|
+
require_relative "../utils/http_helper"
|
5
|
+
|
6
|
+
# class for creating new API tokens' requests
|
7
|
+
# @see https://docs.unit.co/org-api-tokens
|
8
|
+
# @see https://docs.unit.co/customer-api-tokens
|
9
|
+
module Unit
|
10
|
+
module Resource
|
11
|
+
class ApiTokenResource < Unit::Resource::BaseResource
|
12
|
+
class << self
|
13
|
+
# Create a new Org API api_token by calling Unit's API
|
14
|
+
# @param request [CreateApiTokenRequest]
|
15
|
+
# @return [UnitResponse, UnitError]
|
16
|
+
def create_org_api_token(request)
|
17
|
+
payload = request.to_json_api
|
18
|
+
response = HttpHelper.post("#{api_url}/users/#{request.user_id}/api-tokens", body: payload, headers: headers)
|
19
|
+
response_handler(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get Org API tokens by calling Unit's API
|
23
|
+
# @param user_id [String]
|
24
|
+
# @return [UnitResponse, UnitError]
|
25
|
+
def list_org_tokens(user_id)
|
26
|
+
response = HttpHelper.get("#{api_url}/users/#{user_id}/api-tokens", headers: headers)
|
27
|
+
response_handler(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Revoke Org API api_token by calling Unit's API
|
31
|
+
# @param user_id [String]
|
32
|
+
# @param token_id [String]
|
33
|
+
# @return [UnitResponse, UnitError]
|
34
|
+
def revoke_org_token(user_id, token_id)
|
35
|
+
response = HttpHelper.delete("#{api_url}/users/#{user_id}/api-tokens/#{token_id}", headers: headers)
|
36
|
+
response_handler(response)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create customer token by calling Unit's API
|
40
|
+
# @param [CreateCustomerTokenRequest, CreateCustomerTokenUsingJwtRequest] request
|
41
|
+
# @return [UnitResponse, UnitError]
|
42
|
+
def create_customer_token(request)
|
43
|
+
payload = request.to_json_api
|
44
|
+
response = HttpHelper.post("#{api_url}/customers/#{request.customer_id}/token", headers: headers, body: payload)
|
45
|
+
response_handler(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create customer token verification by calling Unit's API
|
49
|
+
# @param [CreateCustomerTokenVerification] request
|
50
|
+
# @return [UnitResponse, UnitError]
|
51
|
+
def create_token_verification(request)
|
52
|
+
payload = request.to_json_api
|
53
|
+
response = HttpHelper.post("#{api_url}/customers/#{request.customer_id}/token/verification", body: payload, headers: headers)
|
54
|
+
response_handler(response)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base_resource"
|
4
|
+
require_relative "../utils/http_helper"
|
5
|
+
|
6
|
+
# class for creating requests for book payments to Unit API and parsing responses
|
7
|
+
# @see https://docs.unit.co/book-payments#book-payments
|
8
|
+
module Unit
|
9
|
+
module Resource
|
10
|
+
class PaymentResource < Unit::Resource::BaseResource
|
11
|
+
class << self
|
12
|
+
# Create a new book payment by calling Unit's API
|
13
|
+
# @param request [CreatePaymentRequest]
|
14
|
+
# @return [UnitResponse, UnitError]
|
15
|
+
def create_payment(request)
|
16
|
+
payload = request.to_json_api
|
17
|
+
response = HttpHelper.post("#{api_url}/payments", body: payload, headers: headers)
|
18
|
+
response_handler(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Update a book payment by calling Unit's API
|
22
|
+
# @param request [PatchBookPaymentRequest]
|
23
|
+
# @return [UnitResponse, UnitError]
|
24
|
+
def update_payment(request)
|
25
|
+
payload = request.to_json_api
|
26
|
+
response = HttpHelper.patch("#{api_url}/payments/#{request.payment_id}", body: payload, headers: headers)
|
27
|
+
response_handler(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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 transactions to Unit API and parsing responses
|
8
|
+
# @see https://docs.unit.co/transactions
|
9
|
+
module Unit
|
10
|
+
module Resource
|
11
|
+
class TransactionResource < Unit::Resource::BaseResource
|
12
|
+
class << self
|
13
|
+
# Get a transaction by id by calling Unit's API
|
14
|
+
# @param params [GetTransactionParams]
|
15
|
+
# @return [UnitResponse, UnitError]
|
16
|
+
def get_transaction(params)
|
17
|
+
response = HttpHelper.get("#{api_url}/accounts/#{params.account_id}/transactions/#{params.transaction_id}", params: params.to_hash, headers: headers)
|
18
|
+
response_handler(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get transactions by calling Unit's API
|
22
|
+
# @param params [ListTransactionParams]
|
23
|
+
# @return [UnitResponse, UnitError]
|
24
|
+
def list_transactions(params = nil)
|
25
|
+
response = HttpHelper.get("#{api_url}/transactions", params: params.to_hash, headers: headers)
|
26
|
+
response_handler(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Update a transaction by calling Unit's API
|
30
|
+
# @param request [PatchTagsRequest]
|
31
|
+
# @return [UnitResponse, UnitError]
|
32
|
+
def update_tags(request)
|
33
|
+
payload = request.to_json_api
|
34
|
+
response = HttpHelper.patch("#{api_url}/accounts/#{request.account_id}/transactions/#{request.transaction_id}", body: payload, headers: headers)
|
35
|
+
response_handler(response)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
module ApiToken
|
5
|
+
module Org
|
6
|
+
autoload :CreateApiTokenRequest, "unit/models/api_token/org/create_api_token_request"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Create a new Org API api_token by calling Unit's API
|
10
|
+
# @see https://docs.unit.co/org-api-tokens#create-org-api-token
|
11
|
+
# @param user_id [String]
|
12
|
+
# @param description [String]
|
13
|
+
# @param scope [Array<String>]
|
14
|
+
# @param expiration [Datetime]
|
15
|
+
# @param source_ip [String] - optional
|
16
|
+
# @param resources [Array<RestrictedResource>] - optional
|
17
|
+
# @return [UnitResponse, UnitError]
|
18
|
+
def create_api_token(user_id:, description:, scope:, expiration:, source_ip: nil, resources: nil)
|
19
|
+
request = CreateApiTokenRequest.new(user_id, description, scope, expiration, source_ip, resources)
|
20
|
+
Unit::Resource::ApiTokenResource.create_org_api_token(request)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get Org API tokens by calling Unit's API
|
24
|
+
# @see https://docs.unit.co/org-api-tokens#list-org-api-tokens
|
25
|
+
# @param user_id [String]
|
26
|
+
# @return [UnitResponse, UnitError]
|
27
|
+
def list_tokens(user_id:)
|
28
|
+
Unit::Resource::ApiTokenResource.list_org_tokens(user_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Revoke Org API api_token by calling Unit's API
|
32
|
+
# @see https://docs.unit.co/org-api-tokens#revoke-org-api-token
|
33
|
+
# @param user_id [String]
|
34
|
+
# @param token_id [String]
|
35
|
+
# @return [UnitResponse, UnitError]
|
36
|
+
def revoke_token(user_id:, token_id:)
|
37
|
+
Unit::Resource::ApiTokenResource.revoke_org_token(user_id, token_id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Customer
|
43
|
+
autoload :CreateCustomerTokenRequest, "unit/models/api_token/customer/create_customer_token_request"
|
44
|
+
autoload :CreateTokenUsingJwtRequest, "unit/models/api_token/customer/create_token_using_jwt_request"
|
45
|
+
autoload :CreateCustomerTokenVerification, "unit/models/api_token/customer/create_customer_token_verification"
|
46
|
+
|
47
|
+
class << self
|
48
|
+
# Create customer token by calling Unit's API
|
49
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-create-customer-bearer-token
|
50
|
+
# @param customer_id [String]
|
51
|
+
# @param scope [Array<String>]
|
52
|
+
# @param verification_token [String]
|
53
|
+
# @param verification_code [String] - optional
|
54
|
+
# @param expires_in [Integer] - optional
|
55
|
+
# @param resources [Array<RestrictedResource>] - optional
|
56
|
+
# @return [UnitResponse, UnitError]
|
57
|
+
def create_customer_token(customer_id:, scope:, verification_token:, verification_code: nil, expires_in: nil,
|
58
|
+
resources: nil)
|
59
|
+
request = CreateCustomerTokenRequest.new(customer_id, scope, verification_token, verification_code, expires_in, resources)
|
60
|
+
Unit::Resource::ApiTokenResource.create_customer_token(request)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create customer token using JWT by calling Unit's API
|
64
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-create-customer-bearer-token-jwt
|
65
|
+
# @param customer_id [String]
|
66
|
+
# @param scope [Array<String>]
|
67
|
+
# @param jwt_token [String] - optional
|
68
|
+
# @return [UnitResponse, UnitError]
|
69
|
+
def create_customer_token_with_jwt(customer_id:, scope:, jwt_token: nil)
|
70
|
+
request = CreateTokenUsingJwtRequest.new(customer_id, scope, jwt_token)
|
71
|
+
Unit::Resource::ApiTokenResource.create_customer_token(request)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Create customer token verification by calling Unit's API
|
75
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-customer-token-verification
|
76
|
+
# @param customer_id [String]
|
77
|
+
# @param channel [String]
|
78
|
+
# @param phone [Phone] - optional
|
79
|
+
# @param app_hash [String] - optional
|
80
|
+
# @param language [String] - optional
|
81
|
+
# @return [UnitResponse, UnitError]
|
82
|
+
def create_customer_token_verification(customer_id:, channel:, phone: nil, app_hash: nil, language: nil)
|
83
|
+
request = CreateCustomerTokenVerification.new(customer_id, channel, phone, app_hash, language)
|
84
|
+
Unit::Resource::ApiTokenResource.create_token_verification(request)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a customer token
|
4
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-create-customer-bearer-token
|
5
|
+
module Unit
|
6
|
+
module ApiToken
|
7
|
+
module Customer
|
8
|
+
class CreateCustomerTokenRequest
|
9
|
+
attr_reader :customer_id, :scope, :verification_token, :verification_code, :expires_in, :resources
|
10
|
+
|
11
|
+
# @param customer_id [String]
|
12
|
+
# @param scope [Array<String>]
|
13
|
+
# @param verification_token [String] - optional
|
14
|
+
# @param verification_code [String] - optional
|
15
|
+
# @param expires_in [Integer] - optional
|
16
|
+
# @param resources [Array<RestrictedResource>] - optional
|
17
|
+
def initialize(customer_id, scope, verification_token, verification_code = nil,
|
18
|
+
expires_in = nil, resources = nil)
|
19
|
+
@customer_id = customer_id
|
20
|
+
@scope = scope
|
21
|
+
@verification_token = verification_token
|
22
|
+
@verification_code = verification_code
|
23
|
+
@expires_in = expires_in
|
24
|
+
@resources = resources
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_json_api
|
28
|
+
result = { data: { type: "customerToken",
|
29
|
+
attributes:
|
30
|
+
{ scope: scope&.join(" "),
|
31
|
+
verificationToken: verification_token,
|
32
|
+
verificationCode: verification_code,
|
33
|
+
expiresIn: expires_in,
|
34
|
+
resources: resources } } }
|
35
|
+
result[:data][:attributes].compact!
|
36
|
+
result.to_json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a customer token verification
|
4
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-customer-token-verification
|
5
|
+
module Unit
|
6
|
+
module ApiToken
|
7
|
+
module Customer
|
8
|
+
class CreateCustomerTokenVerification
|
9
|
+
attr_reader :customer_id, :channel, :phone, :app_hash, :language
|
10
|
+
|
11
|
+
# @param customer_id [String]
|
12
|
+
# @param channel [String]
|
13
|
+
# @param phone [Phone] - optional
|
14
|
+
# @param app_hash [String] - optional
|
15
|
+
# @param language [String] - optional
|
16
|
+
def initialize(customer_id, channel, phone = nil, app_hash = nil, language = nil)
|
17
|
+
@customer_id = customer_id
|
18
|
+
@channel = channel
|
19
|
+
@phone = phone
|
20
|
+
@app_hash = app_hash
|
21
|
+
@language = language
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json_api
|
25
|
+
result = { data: { type: "customerTokenVerification",
|
26
|
+
attributes:
|
27
|
+
{ channel: channel,
|
28
|
+
phone: phone&.represent,
|
29
|
+
appHash: app_hash,
|
30
|
+
language: language } } }
|
31
|
+
result[:data][:attributes].compact!
|
32
|
+
result.to_json
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create Customer token using JWT
|
4
|
+
# @see https://docs.unit.co/customer-api-tokens#customers-create-customer-bearer-token-jwt
|
5
|
+
module Unit
|
6
|
+
module ApiToken
|
7
|
+
module Customer
|
8
|
+
class CreateTokenUsingJwtRequest
|
9
|
+
attr_reader :customer_id, :scope, :jwt_token
|
10
|
+
|
11
|
+
# @param scope [Array<String>]
|
12
|
+
# @param jwt_token [String]
|
13
|
+
def initialize(customer_id, scope, jwt_token = nil)
|
14
|
+
@customer_id = customer_id
|
15
|
+
@scope = scope
|
16
|
+
@jwt_token = jwt_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json_api
|
20
|
+
result = { data: { type: "customerToken",
|
21
|
+
attributes:
|
22
|
+
{ scope: scope&.join(" "),
|
23
|
+
jwtToken: jwt_token } } }
|
24
|
+
result[:data][:attributes].compact!
|
25
|
+
result.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create an org API token
|
4
|
+
# @see https://docs.unit.co/org-api-tokens#create-org-api-token
|
5
|
+
module Unit
|
6
|
+
module ApiToken
|
7
|
+
module Org
|
8
|
+
class CreateApiTokenRequest
|
9
|
+
attr_reader :user_id, :description, :scope, :expiration, :source_ip, :resources
|
10
|
+
|
11
|
+
# @param user_id [String]
|
12
|
+
# @param description [String]
|
13
|
+
# @param scope [String]
|
14
|
+
# @param expiration [String]
|
15
|
+
# @param source_ip [String] - optional
|
16
|
+
# @param resources [Array<RestrictedResource>] - optional
|
17
|
+
def initialize(user_id, description, scope, expiration, source_ip = nil, resources = nil)
|
18
|
+
@user_id = user_id
|
19
|
+
@description = description
|
20
|
+
@scope = scope
|
21
|
+
@expiration = expiration
|
22
|
+
@source_ip = source_ip
|
23
|
+
@resources = resources
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json_api
|
27
|
+
result = { data: { type: "apiToken",
|
28
|
+
attributes:
|
29
|
+
{ description: description,
|
30
|
+
scope: scope,
|
31
|
+
expiration: expiration,
|
32
|
+
sourceIp: source_ip,
|
33
|
+
resources: resources } } }
|
34
|
+
result[:data][:attributes].compact!
|
35
|
+
result.to_json
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to create a book payment
|
4
|
+
# @see https://docs.unit.co/book-payments#book-payments
|
5
|
+
module Unit
|
6
|
+
module Payment
|
7
|
+
class CreateBookPaymentRequest
|
8
|
+
attr_reader :amount, :description, :account_id, :counterparty_account_id, :transaction_summary_override, :idempotency_key, :tags, :relationships
|
9
|
+
|
10
|
+
# @param amount [Integer]
|
11
|
+
# @param description [String]
|
12
|
+
# @param account_id [String]
|
13
|
+
# @param counterparty_account_id [String]
|
14
|
+
# @param transaction_summary_override [String] - optional
|
15
|
+
# @param idempotency_key [String] - optional
|
16
|
+
# @param tags [Hash] - optional
|
17
|
+
def initialize(amount, description, account_id, counterparty_account_id, relationships, transaction_summary_override = nil,
|
18
|
+
idempotency_key = nil, tags = nil)
|
19
|
+
@amount = amount
|
20
|
+
@description = description
|
21
|
+
@account_id = account_id
|
22
|
+
@counterparty_account_id = counterparty_account_id
|
23
|
+
@relationships = relationships
|
24
|
+
@transaction_summary_override = transaction_summary_override
|
25
|
+
@idempotency_key = idempotency_key
|
26
|
+
@tags = tags
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_json_api
|
30
|
+
payload = {
|
31
|
+
data: {
|
32
|
+
type: "bookPayment",
|
33
|
+
attributes: {
|
34
|
+
amount: amount,
|
35
|
+
description: description,
|
36
|
+
transactionSummaryOverride: transaction_summary_override,
|
37
|
+
idempotencyKey: idempotency_key,
|
38
|
+
tags: tags
|
39
|
+
},
|
40
|
+
relationships: { account: Unit::Types::Relationship.new("depositAccount", account_id).to_hash,
|
41
|
+
counterpartyAccount: Unit::Types::Relationship.new("depositAccount", counterparty_account_id).to_hash }
|
42
|
+
}
|
43
|
+
}
|
44
|
+
payload[:data][:attributes].compact!
|
45
|
+
payload.to_json
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to update a book payment
|
4
|
+
# @see https://docs.unit.co/book-payments#update-book-payment
|
5
|
+
module Unit
|
6
|
+
module Payment
|
7
|
+
class PatchBookPaymentRequest
|
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: "bookPayment",
|
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,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
module Payment
|
5
|
+
autoload :CreateBookPaymentRequest, "unit/models/payment/create_book_payment_request"
|
6
|
+
autoload :PatchBookPaymentRequest, "unit/models/payment/patch_book_payment_request"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Create a new book payment by calling Unit's API
|
10
|
+
# @see https://docs.unit.co/book-payments#book-payments
|
11
|
+
# @param amount [Integer]
|
12
|
+
# @param description [String]
|
13
|
+
# @param account_id [String]
|
14
|
+
# @param counterparty_account_id [String]
|
15
|
+
# @param transaction_summary_override [String] - optional
|
16
|
+
# @param idempotency_key [String] - optional
|
17
|
+
# @param tags [Hash] - optional
|
18
|
+
# @return [UnitResponse, UnitError]
|
19
|
+
def create_book_payment(amount:, description:, account_id:, counterparty_account_id:, transaction_summary_override: nil,
|
20
|
+
idempotency_key: nil, tags: nil)
|
21
|
+
request = Unit::Payment::CreateBookPaymentRequest.new(amount, description, account_id, counterparty_account_id, transaction_summary_override,
|
22
|
+
idempotency_key, tags)
|
23
|
+
Unit::Resource::PaymentResource.create_payment(request)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Update a book payment by calling Unit's API
|
27
|
+
# @see https://docs.unit.co/book-payments#update-book-payment
|
28
|
+
# @param payment_id [String]
|
29
|
+
# @param tags [Hash] - optional
|
30
|
+
# @return [UnitResponse, UnitError]
|
31
|
+
def update_book_payment(payment_id:, tags: nil)
|
32
|
+
request = Unit::Payment::PatchBookPaymentRequest.new(payment_id, tags)
|
33
|
+
Unit::Resource::PaymentResource.update_payment(request)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to get a transaction
|
4
|
+
# @see https://docs.unit.co/transactions#get-specific-transaction
|
5
|
+
module Unit
|
6
|
+
module Transaction
|
7
|
+
class GetTransactionParams
|
8
|
+
attr_accessor :transaction_id, :account_id, :customer_id, :include
|
9
|
+
|
10
|
+
# @param transaction_id [String]
|
11
|
+
# @param account_id [String]
|
12
|
+
# @param customer_id [String] - optional
|
13
|
+
# @param include [Array<String>] - optional
|
14
|
+
def initialize(transaction_id, account_id, customer_id = nil, include = nil)
|
15
|
+
@transaction_id = transaction_id
|
16
|
+
@account_id = account_id
|
17
|
+
@customer_id = customer_id
|
18
|
+
@include = include
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
params = { "filter[customerId]": customer_id,
|
23
|
+
"include": include&.join(",") }
|
24
|
+
params.compact
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to list transactions
|
4
|
+
# @see https://docs.unit.co/transactions#list-transactions
|
5
|
+
module Unit
|
6
|
+
module Transaction
|
7
|
+
class ListTransactionParams
|
8
|
+
attr_reader :limit, :offset, :account_id, :customer_id, :query, :tags, :since, :_until, :card_id, :type, :from_amount, :to_amount, :direction, :exclude_fees, :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 query [String] - optional
|
15
|
+
# @param tags [String] - optional
|
16
|
+
# @param since [String] - optional
|
17
|
+
# @param _until [String] - optional
|
18
|
+
# @param card_id [String] - optional
|
19
|
+
# @param type [Array<String>] - optional
|
20
|
+
# @param from_amount [Integer] - optional
|
21
|
+
# @param to_amount [Integer] - optional
|
22
|
+
# @param direction [String] - optional
|
23
|
+
# @param exclude_fees [Boolean] - optional
|
24
|
+
# @param sort [String] - optional
|
25
|
+
# @param include [Array<String>] - optional
|
26
|
+
def initialize(limit = TRANSACTION_LIST_LIMIT, offset = TRANSACTION_LIST_OFFSET, account_id = nil, customer_id = nil,
|
27
|
+
query = nil, tags = nil, since = nil, _until = nil, card_id = nil, type = nil, from_amount = nil, to_amount = nil,
|
28
|
+
direction = nil, exclude_fees = nil, sort = nil, include = nil)
|
29
|
+
@limit = limit
|
30
|
+
@offset = offset
|
31
|
+
@account_id = account_id
|
32
|
+
@customer_id = customer_id
|
33
|
+
@query = query
|
34
|
+
@tags = tags
|
35
|
+
@since = since
|
36
|
+
@_until = _until
|
37
|
+
@card_id = card_id
|
38
|
+
@type = type
|
39
|
+
@from_amount = from_amount
|
40
|
+
@to_amount = to_amount
|
41
|
+
@direction = direction
|
42
|
+
@exclude_fees = exclude_fees
|
43
|
+
@sort = sort
|
44
|
+
@include = include
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_hash
|
48
|
+
params = { "page[limit]": limit,
|
49
|
+
"page[offset]": offset,
|
50
|
+
"filter[accountId]": account_id,
|
51
|
+
"filter[customerId]": customer_id,
|
52
|
+
"filter[query]": query,
|
53
|
+
"filter[tags]": tags,
|
54
|
+
"filter[since]": since,
|
55
|
+
"filter[until]": _until,
|
56
|
+
"filter[cardId]": card_id,
|
57
|
+
"filter[fromAmount]": from_amount,
|
58
|
+
"filter[toAmount]": to_amount,
|
59
|
+
"filter[direction]": direction,
|
60
|
+
"excludeFees": exclude_fees,
|
61
|
+
"sort": sort,
|
62
|
+
"include": include&.join(",") }
|
63
|
+
type&.each_with_index&.map do |val, index|
|
64
|
+
params.merge!({ "filter[type][#{index}]": val })
|
65
|
+
end
|
66
|
+
params.compact
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Request to update a transaction's tags
|
4
|
+
# @see https://docs.unit.co/transactions#update-transaction-tags
|
5
|
+
module Unit
|
6
|
+
module Transaction
|
7
|
+
class PatchTagsRequest
|
8
|
+
attr_accessor :account_id, :transaction_id, :tags
|
9
|
+
|
10
|
+
# @param account_id [String]
|
11
|
+
# @param transaction_id [String]
|
12
|
+
# @param tags [Hash] - optional
|
13
|
+
def initialize(account_id, transaction_id, tags = nil)
|
14
|
+
@account_id = account_id
|
15
|
+
@transaction_id = transaction_id
|
16
|
+
@tags = tags
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json_api
|
20
|
+
payload = {
|
21
|
+
"data": {
|
22
|
+
"type": "transaction",
|
23
|
+
"attributes": {
|
24
|
+
"tags": tags
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
payload[:data][:attributes].compact!
|
29
|
+
payload.to_json
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
module Transaction
|
5
|
+
TRANSACTION_LIST_LIMIT = 100
|
6
|
+
TRANSACTION_LIST_OFFSET = 0
|
7
|
+
autoload :GetTransactionParams, "unit/models/transaction/get_transaction_params"
|
8
|
+
autoload :ListTransactionParams, "unit/models/transaction/list_transaction_params"
|
9
|
+
autoload :PatchTagsRequest, "unit/models/transaction/patch_tags_request"
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# Get a transaction by id
|
13
|
+
# @see https://docs.unit.co/transactions#get-specific-transaction
|
14
|
+
# @param transaction_id [String]
|
15
|
+
# @param account_id [String]
|
16
|
+
# @param customer_id [String] - optional
|
17
|
+
# @param include [Array<String>] - optional
|
18
|
+
def get_transaction(transaction_id:, account_id:, customer_id: nil, include: nil)
|
19
|
+
params = GetTransactionParams.new(transaction_id, account_id, customer_id, include)
|
20
|
+
Unit::Resource::TransactionResource.get_transaction(params)
|
21
|
+
end
|
22
|
+
|
23
|
+
# List transactions
|
24
|
+
# @see https://docs.unit.co/transactions#list-transactions
|
25
|
+
# @param limit [Integer] - optional
|
26
|
+
# @param offset [Integer] - optional
|
27
|
+
# @param account_id [String] - optional
|
28
|
+
# @param query [String] - optional
|
29
|
+
# @param tags [String] - optional
|
30
|
+
# @param since [String] - optional
|
31
|
+
# @param _until [String] - optional
|
32
|
+
# @param card_id [String] - optional
|
33
|
+
# @param type [Array<String>] - optional
|
34
|
+
# @param from_amount [Integer] - optional
|
35
|
+
# @param to_amount [Integer] - optional
|
36
|
+
# @param direction [String] - optional
|
37
|
+
# @param exclude_fees [Boolean] - optional
|
38
|
+
# @param sort [String] - optional
|
39
|
+
# @param include [Array<String>] - optional
|
40
|
+
def list_transactions(limit: nil, offset: nil, account_id: nil, customer_id: nil,
|
41
|
+
query: nil, tags: nil, since: nil, _until: nil, card_id: nil, type: nil, from_amount: nil, to_amount: nil,
|
42
|
+
direction: nil, exclude_fees: nil, sort: nil, include: nil)
|
43
|
+
params = ListTransactionParams.new(limit, offset, account_id, customer_id, query, tags, since,
|
44
|
+
_until, card_id, type, from_amount, to_amount,
|
45
|
+
direction, exclude_fees, sort, include)
|
46
|
+
Unit::Resource::TransactionResource.list_transactions(params)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Update transaction tags
|
50
|
+
# @see https://docs.unit.co/transactions#update-transaction-tags
|
51
|
+
# @param account_id [String]
|
52
|
+
# @param transaction_id [String]
|
53
|
+
# @param tags [Hash]
|
54
|
+
def update_transaction(account_id:, transaction_id:, tags: nil)
|
55
|
+
request = PatchTagsRequest.new(account_id, transaction_id, tags)
|
56
|
+
Unit::Resource::TransactionResource.update_tags(request)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
module Unit
|
5
|
+
module Types
|
6
|
+
class RestrictedResource
|
7
|
+
attr_reader :ids, :type
|
8
|
+
|
9
|
+
def initialize(ids, type)
|
10
|
+
@ids = ids
|
11
|
+
@type = type
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_json_api
|
15
|
+
result = []
|
16
|
+
@ids.each do |id|
|
17
|
+
result << { type: type, id: id }
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/unit/version.rb
CHANGED
data/lib/unit_ruby_sdk.rb
CHANGED
@@ -6,11 +6,17 @@ module Unit
|
|
6
6
|
autoload :Application, "unit/models/application/application"
|
7
7
|
autoload :Customer, "unit/models/customer/customer"
|
8
8
|
autoload :Account, "unit/models/account/account"
|
9
|
+
autoload :ApiToken, "unit/models/api_token/api_token"
|
10
|
+
autoload :Payment, "unit/models/payment/payment"
|
11
|
+
autoload :Transaction, "unit/models/transaction/transaction"
|
9
12
|
|
10
13
|
module Resource
|
11
14
|
autoload :ApplicationResource, "unit/api_resources/application_resource"
|
12
15
|
autoload :CustomerResource, "unit/api_resources/customer_resource"
|
13
16
|
autoload :AccountResource, "unit/api_resources/account_resource"
|
17
|
+
autoload :ApiTokenResource, "unit/api_resources/api_token_resource"
|
18
|
+
autoload :PaymentResource, "unit/api_resources/payment_resource"
|
19
|
+
autoload :TransactionResource, "unit/api_resources/transaction_resource"
|
14
20
|
end
|
15
21
|
|
16
22
|
module Types
|
@@ -26,6 +32,7 @@ module Unit
|
|
26
32
|
autoload :PowerOfAttorneyAgent, "unit/types/power_of_attorney_agent"
|
27
33
|
autoload :Relationship, "unit/types/relationship"
|
28
34
|
autoload :RelationshipArray, "unit/types/relationship_array"
|
35
|
+
autoload :RestrictedResource, "unit/types/restricted_resource"
|
29
36
|
end
|
30
37
|
|
31
38
|
autoload :UnitErrorPayload, "unit/errors/unit_error_payload"
|
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: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Unit
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot_rails
|
@@ -95,9 +95,12 @@ files:
|
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- lib/unit/api_resources/account_resource.rb
|
98
|
+
- lib/unit/api_resources/api_token_resource.rb
|
98
99
|
- lib/unit/api_resources/application_resource.rb
|
99
100
|
- lib/unit/api_resources/base_resource.rb
|
100
101
|
- lib/unit/api_resources/customer_resource.rb
|
102
|
+
- lib/unit/api_resources/payment_resource.rb
|
103
|
+
- lib/unit/api_resources/transaction_resource.rb
|
101
104
|
- lib/unit/errors/unit_error.rb
|
102
105
|
- lib/unit/errors/unit_error_payload.rb
|
103
106
|
- lib/unit/models/account/account.rb
|
@@ -108,6 +111,11 @@ files:
|
|
108
111
|
- lib/unit/models/account/deposit/freeze_account_request.rb
|
109
112
|
- lib/unit/models/account/deposit/list_account_params.rb
|
110
113
|
- lib/unit/models/account/deposit/patch_deposit_account_request.rb
|
114
|
+
- lib/unit/models/api_token/api_token.rb
|
115
|
+
- lib/unit/models/api_token/customer/create_customer_token_request.rb
|
116
|
+
- lib/unit/models/api_token/customer/create_customer_token_verification.rb
|
117
|
+
- lib/unit/models/api_token/customer/create_token_using_jwt_request.rb
|
118
|
+
- lib/unit/models/api_token/org/create_api_token_request.rb
|
111
119
|
- lib/unit/models/application/application.rb
|
112
120
|
- lib/unit/models/application/create_business_application_request.rb
|
113
121
|
- lib/unit/models/application/create_individual_application_request.rb
|
@@ -121,6 +129,13 @@ files:
|
|
121
129
|
- lib/unit/models/customer/patch_business_customer_request.rb
|
122
130
|
- lib/unit/models/customer/patch_individual_customer_request.rb
|
123
131
|
- lib/unit/models/customer/remove_authorized_users_request.rb
|
132
|
+
- lib/unit/models/payment/create_book_payment_request.rb
|
133
|
+
- lib/unit/models/payment/patch_book_payment_request.rb
|
134
|
+
- lib/unit/models/payment/payment.rb
|
135
|
+
- lib/unit/models/transaction/get_transaction_params.rb
|
136
|
+
- lib/unit/models/transaction/list_transaction_params.rb
|
137
|
+
- lib/unit/models/transaction/patch_tags_request.rb
|
138
|
+
- lib/unit/models/transaction/transaction.rb
|
124
139
|
- lib/unit/models/unit_resource.rb
|
125
140
|
- lib/unit/models/unit_response.rb
|
126
141
|
- lib/unit/types/address.rb
|
@@ -135,6 +150,7 @@ files:
|
|
135
150
|
- lib/unit/types/power_of_attorney_agent.rb
|
136
151
|
- lib/unit/types/relationship.rb
|
137
152
|
- lib/unit/types/relationship_array.rb
|
153
|
+
- lib/unit/types/restricted_resource.rb
|
138
154
|
- lib/unit/utils/http_helper.rb
|
139
155
|
- lib/unit/version.rb
|
140
156
|
- lib/unit_ruby_sdk.rb
|