unit_ruby_sdk 0.1.4 → 0.1.5

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: 14fc2502ef67bd580d1fb1d8ed06af33d22d99161bce1fa79ea98ac7acc9dad6
4
- data.tar.gz: c0df3342ca09be9cb8f3ded2ff6717f188620716b0a8118b7850a19143b0ab4e
3
+ metadata.gz: 00b359a8630b7687c710525b86d5faec0f30dc7771ed820538a12f18e3423d9d
4
+ data.tar.gz: 6ed3a97d6962f88810a0801e0f7f98a2e5cd8a850fb870b945bb06bc91229af4
5
5
  SHA512:
6
- metadata.gz: 1270a0a50b9e23a8608716098ea341708a18233d290e124416aed5be9a564a28e4c4d7b4f1c59a8224e74ae54746dc51c3908bdf1bb790df79dc810ba173602f
7
- data.tar.gz: 5f4fac2c94ec93621ca4541ebc9c80a1bc0f2c0590f8503a1133d7b4fe437b783c0488ea42665f771d212c7959ac91837229f7917eec148ea7246e272a78a066
6
+ metadata.gz: cdc7b4d814b87313a2163176589d3c871f6986a9c39eb327a59596ef5ad7531645fe324703e105a0758a5d871da2a9d5cdc8ea30912a2a5983a77ff6d85949d0
7
+ data.tar.gz: 54884fbeb721faa5a5a8b2b78b91059a3b93af504f70d313e4b87963e33e6944c998d31c52412a61e2da198964bf9030872d39c22fab6db871f42a954c2681e3
data/README.md CHANGED
@@ -14,6 +14,8 @@ gem install unit_ruby_sdk
14
14
 
15
15
  ## Usage
16
16
 
17
+ Bellow are a few exapmles of the Ruby SDK application. For full documentation of the Unit API please refer to the full documentation at https://docs.unit.co/
18
+
17
19
  ### Creating a Business Application
18
20
 
19
21
  ```ruby
@@ -82,6 +84,19 @@ transaction = response.data
82
84
  puts transaction.id
83
85
  ```
84
86
 
87
+ ### Creating an individual debit card
88
+ ```ruby
89
+ response = Unit::Card.create_individual_debit_card(
90
+ account_id: '1234',
91
+ type: "depositAccount",
92
+ shipping_address: address,
93
+ design: "default",
94
+ additional_embossed_text: "Second Cardholder"
95
+ )
96
+ card = response.data
97
+ puts card.id
98
+ ```
99
+
85
100
  ### Logging Errors
86
101
 
87
102
  ```ruby
@@ -11,6 +11,10 @@ module Unit
11
11
  handler.from_json_api(response)
12
12
  end
13
13
 
14
+ def file_response_handler(response)
15
+ response.code.to_i.between?(200, 299) ? response.body : Unit::UnitError
16
+ end
17
+
14
18
  protected
15
19
 
16
20
  def api_url
@@ -25,7 +29,7 @@ module Unit
25
29
  {
26
30
  "Content-Type" => "application/vnd.api+json",
27
31
  "Authorization" => "Bearer #{Unit.config[:token]}",
28
- "User-Agent" => "unit-ruby-sdk"
32
+ "X-UNIT-SDK" => "unit-ruby-sdk@v#{Unit::VERSION}"
29
33
  }
30
34
  end
31
35
  end
@@ -0,0 +1,104 @@
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 cards to Unit API and parsing responses
7
+ # @see https://docs.unit.co/cards
8
+ module Unit
9
+ module Resource
10
+ class CardResource < Unit::Resource::BaseResource
11
+ class << self
12
+ # Create a new card by calling Unit's API
13
+ # @param [CreateIndividualDebitCardRequest, CreateIndividualVirtualCardRequest] request
14
+ # @return [UnitResponse, UnitError]
15
+ def create_card(request)
16
+ payload = request.to_json_api
17
+ response = HttpHelper.post("#{api_url}/cards", body: payload, headers: headers)
18
+ response_handler(response)
19
+ end
20
+
21
+ # Get pin status by calling Unit's API
22
+ # @param card_id [String]
23
+ # @return [UnitResponse, UnitError]
24
+ def get_pin_status(card_id)
25
+ response = HttpHelper.get("#{api_url}/cards/#{card_id}/secure-data/pin/status", headers: headers)
26
+ response_handler(response)
27
+ end
28
+
29
+ # Report a card as a stolen by calling Unit's API
30
+ # @param card_id [String]
31
+ # @return [UnitResponse, UnitError]
32
+ def report_stolen(card_id)
33
+ response = HttpHelper.post("#{api_url}/cards/#{card_id}/report-stolen", headers: headers)
34
+ response_handler(response)
35
+ end
36
+
37
+ # Report a card as a lost by calling Unit's API
38
+ # @param card_id [String]
39
+ # @return [UnitResponse, UnitError]
40
+ def report_lost(card_id)
41
+ response = HttpHelper.post("#{api_url}/cards/#{card_id}/report-lost", headers: headers)
42
+ response_handler(response)
43
+ end
44
+
45
+ # Close a card by calling Unit's API
46
+ # @param card_id [String]
47
+ # @return [UnitResponse, UnitError]
48
+ def close_card(card_id)
49
+ response = HttpHelper.post("#{api_url}/cards/#{card_id}/close", headers: headers)
50
+ response_handler(response)
51
+ end
52
+
53
+ # Freeze a card by calling Unit's API
54
+ # @param card_id [String]
55
+ # @return [UnitResponse, UnitError]
56
+ def freeze_card(card_id)
57
+ response = HttpHelper.post("#{api_url}/cards/#{card_id}/freeze", headers: headers)
58
+ response_handler(response)
59
+ end
60
+
61
+ # Unfreeze a card by calling Unit's API
62
+ # @param card_id [String]
63
+ # @return [UnitResponse, UnitError]
64
+ def unfreeze_card(card_id)
65
+ response = HttpHelper.post("#{api_url}/cards/#{card_id}/unfreeze", headers: headers)
66
+ response_handler(response)
67
+ end
68
+
69
+ # Replace a card by calling Unit's API
70
+ # @param request [ReplaceCardRequest]
71
+ # @return [UnitResponse, UnitError]
72
+ def replace_card(request)
73
+ payload = request.to_json_api
74
+ response = HttpHelper.post("#{api_url}/cards/#{request.card_id}/replace", body: payload, headers: headers)
75
+ response_handler(response)
76
+ end
77
+
78
+ # Get a card by id by calling Unit's API
79
+ # @param card_id [String]
80
+ # @return [UnitResponse, UnitError]
81
+ def get_card(card_id)
82
+ response = HttpHelper.get("#{api_url}/cards/#{card_id}", headers: headers)
83
+ response_handler(response)
84
+ end
85
+
86
+ # List cards by calling Unit's API
87
+ # @param params [ListCardParams]
88
+ # @return [UnitResponse, UnitError]
89
+ def list_cards(params = nil)
90
+ response = HttpHelper.get("#{api_url}/cards", params: params&.to_hash, headers: headers)
91
+ response_handler(response)
92
+ end
93
+
94
+ # Get card limits by calling Unit's API
95
+ # @param card_id [String]
96
+ # @return [UnitResponse, UnitError]
97
+ def limits(card_id)
98
+ response = HttpHelper.get("#{api_url}/cards/#{card_id}/limits", headers: headers)
99
+ response_handler(response)
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,46 @@
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 statements to Unit API and parsing responses
7
+ # @see https://docs.unit.co/cards
8
+ module Unit
9
+ module Resource
10
+ class StatementResource < Unit::Resource::BaseResource
11
+ class << self
12
+ # Get statements by calling Unit's API
13
+ # @param params [ListStatementParams]
14
+ # @return [UnitResponse, UnitError]
15
+ def list(params = nil)
16
+ response = HttpHelper.get("#{api_url}/statements", params: params&.to_hash, headers: headers)
17
+ response_handler(response)
18
+ end
19
+
20
+ # Get a html statement by id by calling Unit's API
21
+ # @param params [GetHtmlByIdRequest]
22
+ # @return [UnitResponse, UnitError]
23
+ def get_html_by_id(request)
24
+ response = HttpHelper.get("#{api_url}/statements/#{request.statement_id}/html", params: request.to_hash, headers: headers)
25
+ file_response_handler(response)
26
+ end
27
+
28
+ # Get a pdf statement by id by calling Unit's API
29
+ # @param request [GetPdfByIdRequest]
30
+ # @return [UnitResponse, UnitError]
31
+ def get_pdf_by_id(request)
32
+ response = HttpHelper.get("#{api_url}/statements/#{request.statement_id}/pdf", params: request.to_hash, headers: headers)
33
+ file_response_handler(response)
34
+ end
35
+
36
+ # Get bank verification by calling Unit's API
37
+ # @param request [GetBankVerificationRequest]
38
+ # @return [UnitResponse, UnitError]
39
+ def get_bank_verification(request)
40
+ response = HttpHelper.get("#{api_url}/statements/#{request.account_id}/bank/pdf", params: request&.to_hash, headers: headers)
41
+ file_response_handler(response)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -10,7 +10,7 @@ module Unit
10
10
 
11
11
  # @param user_id [String]
12
12
  # @param description [String]
13
- # @param scope [String]
13
+ # @param scope [Array<String>]
14
14
  # @param expiration [String]
15
15
  # @param source_ip [String] - optional
16
16
  # @param resources [Array<RestrictedResource>] - optional
@@ -27,7 +27,7 @@ module Unit
27
27
  result = { data: { type: "apiToken",
28
28
  attributes:
29
29
  { description: description,
30
- scope: scope,
30
+ scope: scope.join(" "),
31
31
  expiration: expiration,
32
32
  sourceIp: source_ip,
33
33
  resources: resources } } }
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module Card
5
+ CARD_LIST_LIMIT = 100
6
+ CARD_LIST_OFFSET = 0
7
+ autoload :CreateIndividualDebitCardRequest, "unit/models/card/create_individual_debit_card_request"
8
+ autoload :CreateBusinessDebitCardRequest, "unit/models/card/create_business_debit_card_request"
9
+ autoload :CreateBusinessVirtualDebitCardRequest, "unit/models/card/create_business_virtual_debit_card_request"
10
+ autoload :CreateIndividualVirtualCardRequest, "unit/models/card/create_individual_virtual_card_request"
11
+ autoload :ReplaceCardRequest, "unit/models/card/replace_card_request"
12
+ autoload :ListCardParams, "unit/models/card/list_card_params"
13
+
14
+ class << self
15
+ # Create a new individual debit card by calling Unit's API
16
+ # @see https://docs.unit.co/cards#create-individual-debit-card
17
+ # @param account_id [String]
18
+ # @param shipping_address [Address] - optional
19
+ # @param design [String] - optional
20
+ # @param additional_embossed_text [String] - optional
21
+ # @param idempotency_key [String] - optional
22
+ # @param tags [Hash] - optional
23
+ # @param limits [Hash] - optional
24
+ # @param print_only_business_name [String] - optional
25
+ def create_individual_debit_card(account_id:, customer_id: nil, shipping_address: nil, design: nil, additional_embossed_text: nil,
26
+ idempotency_key: nil, tags: nil, limits: nil, print_only_business_name: nil)
27
+ request = CreateIndividualDebitCardRequest.new(account_id, customer_id, shipping_address, design, additional_embossed_text,
28
+ idempotency_key, tags, limits, print_only_business_name)
29
+ Unit::Resource::CardResource.create_card(request)
30
+ end
31
+
32
+ # Create a new business debit card by calling Unit's API
33
+ # @see https://docs.unit.co/cards#create-business-debit-card
34
+ # @param full_name [FullName]
35
+ # @param date_of_birth [Date]
36
+ # @param address [Address]
37
+ # @param shipping_address [Address] - optional
38
+ # @param phone [Phone] - optional
39
+ # @param email [String] - optional
40
+ # @param design [String] - optional
41
+ # @param additional_embossed_text [String] - optional
42
+ # @param idempotency_key [String] - optional
43
+ # @param tags [Hash] - optional
44
+ # @param limits [Hash] - optional
45
+ # @param print_only_business_name [Boolean] - optional
46
+ def create_business_debit_card(account_id:, full_name:, date_of_birth:, address:, phone:, email:, shipping_address: nil,
47
+ design: nil, additional_embossed_text: nil, idempotency_key: nil, tags: nil, limits: nil, print_only_business_name: nil)
48
+ request = CreateBusinessDebitCardRequest.new(account_id, full_name, date_of_birth, address, shipping_address, phone, email, design, additional_embossed_text,
49
+ idempotency_key, tags, limits, print_only_business_name)
50
+ Unit::Resource::CardResource.create_card(request)
51
+ end
52
+
53
+ # Create a new individual virtual card by calling Unit's API
54
+ # @see https://docs.unit.co/cards#create-individual-virtual-debit-card
55
+ # @param account_id [String]
56
+ # @param idempotency_key [String] - optional
57
+ # @param tags [Hash] - optional
58
+ # @param limits [Hash] - optional
59
+ def create_individual_virtual_card(account_id:, customer_id: nil, idempotency_key: nil, tags: nil, limits: nil)
60
+ request = CreateIndividualVirtualCardRequest.new(account_id, customer_id, idempotency_key, tags, limits)
61
+ Unit::Resource::CardResource.create_card(request)
62
+ end
63
+
64
+ # Create a new business virtual card by calling Unit's API
65
+ # @see https://docs.unit.co/cards#create-business-virtual-debit-card
66
+ # @param account_id [String]
67
+ # @param type [String]
68
+ # @param idempotency_key [String] - optional
69
+ # @param tags [Hash] - optional
70
+ # @param limits [Hash] - optional
71
+ def create_business_virtual_card(account_id:, full_name:, date_of_birth:, address:, phone: nil, email: nil, idempotency_key: nil, tags: nil, limits: nil)
72
+ request = CreateBusinessVirtualDebitCardRequest.new(account_id, full_name, date_of_birth, address, phone, email, idempotency_key, tags, limits)
73
+ Unit::Resource::CardResource.create_card(request)
74
+ end
75
+
76
+ # Get pin status by calling Unit's API
77
+ # @see https://docs.unit.co/cards#get-pin-status
78
+ # @param card_id [String]
79
+ def get_pin_status(card_id:)
80
+ Unit::Resource::CardResource.get_pin_status(card_id)
81
+ end
82
+
83
+ # Report a card as a stolen by calling Unit's API
84
+ # @param card_id [String]
85
+ def report_stolen(card_id:)
86
+ Unit::Resource::CardResource.report_stolen(card_id)
87
+ end
88
+
89
+ # Report a card as a lost by calling Unit's API
90
+ # @param card_id [String]
91
+ def report_lost(card_id:)
92
+ Unit::Resource::CardResource.report_lost(card_id)
93
+ end
94
+
95
+ # Close a card by calling Unit's API
96
+ # @param card_id [String]
97
+ def close_card(card_id:)
98
+ Unit::Resource::CardResource.close_card(card_id)
99
+ end
100
+
101
+ # Freeze a card by calling Unit's API
102
+ # @param card_id [String]
103
+ def freeze_card(card_id:)
104
+ Unit::Resource::CardResource.freeze_card(card_id)
105
+ end
106
+
107
+ # Unfreeze a card by calling Unit's API
108
+ # @param card_id [String]
109
+ def unfreeze_card(card_id:)
110
+ Unit::Resource::CardResource.unfreeze_card(card_id)
111
+ end
112
+
113
+ # Replace a card by calling Unit's API
114
+ # @param card_id [String]
115
+ # @param shipping_address [Address] - optional
116
+ def replace_card(card_id:, shipping_address: nil)
117
+ request = ReplaceCardRequest.new(card_id, shipping_address)
118
+ Unit::Resource::CardResource.replace_card(request)
119
+ end
120
+
121
+ # Get a card by id by calling Unit's API
122
+ # @param card_id [String]
123
+ def get_card(card_id:)
124
+ Unit::Resource::CardResource.get_card(card_id)
125
+ end
126
+
127
+ # List cards by calling Unit's API
128
+ # @param limit [Integer] - optional
129
+ # @param offset [Integer] - optional
130
+ # @param account_id [String] - optional
131
+ # @param customer_id [String] - optional
132
+ # @param tags [Hash] - optional
133
+ # @param status [Array<String>] - optional
134
+ # @param include [Array] - optional
135
+ # @param sort [String] - optional
136
+ def list_cards(limit: CARD_LIST_LIMIT, offset: CARD_LIST_OFFSET, account_id: nil,
137
+ customer_id: nil, tags: nil, status: nil, include: nil, sort: nil)
138
+ request = ListCardParams.new(limit, offset, account_id, customer_id, tags, status, include, sort)
139
+ Unit::Resource::CardResource.list_cards(request)
140
+ end
141
+
142
+ # Get a card limits by calling Unit's API
143
+ # @param card_id [String]
144
+ def limits(card_id:)
145
+ Unit::Resource::CardResource.limits(card_id)
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create business debit card request
4
+ # @see https://docs.unit.co/cards#create-business-debit-card
5
+ module Unit
6
+ module Card
7
+ class CreateBusinessDebitCardRequest
8
+ attr_reader :account_id, :full_name, :date_of_birth, :address, :shipping_address, :phone, :email, :design, :additional_embossed_text, :idempotency_key, :tags, :limits, :print_only_business_name
9
+
10
+ # @param account_id [String]
11
+ # @param full_name [FullName]
12
+ # @param date_of_birth [Date]
13
+ # @param address [Address]
14
+ # @param shipping_address [Address] - optional
15
+ # @param phone [Phone] - optional
16
+ # @param email [String] - optional
17
+ # @param design [String] - optional
18
+ # @param additional_embossed_text [String] - optional
19
+ # @param idempotency_key [String] - optional
20
+ # @param tags [Hash] - optional
21
+ # @param limits [Hash] - optional
22
+ # @param print_only_business_name [Boolean] - optional
23
+ def initialize(account_id, full_name, date_of_birth, address, shipping_address = nil, phone = nil, email = nil, design = nil,
24
+ additional_embossed_text = nil, idempotency_key = nil, tags = nil, limits = nil, print_only_business_name = nil)
25
+ @account_id = account_id
26
+ @full_name = full_name
27
+ @date_of_birth = date_of_birth
28
+ @address = address
29
+ @shipping_address = shipping_address
30
+ @phone = phone
31
+ @email = email
32
+ @design = design
33
+ @additional_embossed_text = additional_embossed_text
34
+ @idempotency_key = idempotency_key
35
+ @tags = tags
36
+ @limits = limits
37
+ @print_only_business_name = print_only_business_name
38
+ end
39
+
40
+ def to_json_api
41
+ payload = {
42
+ "data": {
43
+ "type": "businessDebitCard",
44
+ "attributes": {
45
+ "fullName": full_name&.represent,
46
+ "dateOfBirth": date_of_birth,
47
+ "address": address&.represent,
48
+ "shippingAddress": shipping_address,
49
+ "phone": phone&.represent,
50
+ "email": email,
51
+ "design": design,
52
+ "additionalEmbossedText": additional_embossed_text,
53
+ "idempotencyKey": idempotency_key,
54
+ "tags": tags,
55
+ "limits": limits,
56
+ "printOnlyBusinessName": print_only_business_name
57
+ },
58
+ "relationships": {
59
+ "account": Unit::Types::Relationship.new("account", account_id).to_hash
60
+ }
61
+ }
62
+ }
63
+ payload[:data][:attributes].compact!
64
+ payload.to_json
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create a business virtual debit card
4
+ # @see https://docs.unit.co/cards#create-business-virtual-debit-card
5
+ module Unit
6
+ module Card
7
+ class CreateBusinessVirtualDebitCardRequest
8
+ attr_reader :account_id, :full_name, :date_of_birth, :address, :phone, :email, :idempotency_key, :tags, :limits
9
+
10
+ # @param account_id [String]
11
+ # @param full_name [FullName]
12
+ # @param date_of_birth [Date]
13
+ # @param address [Address]
14
+ # @param phone [Phone] - optional
15
+ # @param email [String] - optional
16
+ # @param idempotency_key [String] - optional
17
+ # @param tags [Hash] - optional
18
+ # @param limits [Hash] - optional
19
+ def initialize(account_id, full_name, date_of_birth, address, phone, email,
20
+ idempotency_key, tags, limits)
21
+ @account_id = account_id
22
+ @full_name = full_name
23
+ @date_of_birth = date_of_birth
24
+ @address = address
25
+ @phone = phone
26
+ @email = email
27
+ @idempotency_key = idempotency_key
28
+ @tags = tags
29
+ @limits = limits
30
+ end
31
+
32
+ def to_json_api
33
+ payload = {
34
+ "data": {
35
+ "type": "businessVirtualDebitCard",
36
+ "attributes": {
37
+ "fullName": full_name&.represent,
38
+ "dateOfBirth": date_of_birth,
39
+ "address": address&.represent,
40
+ "phone": phone&.represent,
41
+ "email": email,
42
+ "idempotencyKey": idempotency_key,
43
+ "tags": tags,
44
+ "limits": limits
45
+ },
46
+ "relationships": {
47
+ "account": Unit::Types::Relationship.new("depositAccount", account_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,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create individual debit card request
4
+ # @see https://docs.unit.co/cards#create-individual-debit-card
5
+ module Unit
6
+ module Card
7
+ class CreateIndividualDebitCardRequest
8
+ attr_reader :account_id, :customer_id, :shipping_address, :design, :additional_embossed_text, :idempotency_key, :tags, :limits, :print_only_business_name
9
+
10
+ # @param account_id [String]
11
+ # @param customer_id [String] - optional
12
+ # @param shipping_address [Address] - optional
13
+ # @param design [String] - optional
14
+ # @param additional_embossed_text [String] - optional
15
+ # @param idempotency_key [String] - optional
16
+ # @param tags [Hash] - optional
17
+ # @param limits [Hash] - optional
18
+ # @param print_only_business_name [Boolean] - optional
19
+ def initialize(account_id, customer_id = nil, shipping_address = nil, design = nil, additional_embossed_text = nil,
20
+ idempotency_key = nil, tags = nil, limits = nil, print_only_business_name = nil)
21
+ @account_id = account_id
22
+ @customer_id = customer_id
23
+ @shipping_address = shipping_address
24
+ @design = design
25
+ @additional_embossed_text = additional_embossed_text
26
+ @idempotency_key = idempotency_key
27
+ @tags = tags
28
+ @limits = limits
29
+ @print_only_business_name = print_only_business_name
30
+ end
31
+
32
+ def to_json_api
33
+ payload = {
34
+ "data": {
35
+ "type": "individualDebitCard",
36
+ "attributes": {
37
+ "shippingAddress": shipping_address&.represent,
38
+ "design": design,
39
+ "additionalEmbossedText": additional_embossed_text,
40
+ "idempotencyKey": idempotency_key,
41
+ "tags": tags,
42
+ "limits": limits,
43
+ "printOnlyBusinessName": print_only_business_name
44
+ },
45
+ "relationships": {
46
+ "account": Unit::Types::Relationship.new("depositAccount", account_id).to_hash
47
+ }
48
+ }
49
+ }
50
+ customer = { "customer": Unit::Types::Relationship.new("customer", customer_id).to_hash } unless customer_id.nil?
51
+ payload[:data][:relationships].merge!(customer) unless customer.nil?
52
+ payload[:data][:attributes].compact!
53
+ payload.to_json
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to create individual virtual card
4
+ # @see https://docs.unit.co/cards#create-individual-virtual-debit-card
5
+ module Unit
6
+ module Card
7
+ class CreateIndividualVirtualCardRequest
8
+ attr_reader :account_id, :customer_id, :idempotency_key, :tags, :limits
9
+
10
+ # @param account_id [String]
11
+ # @param customer_id [String] - optional
12
+ # @param idempotency_key [String] - optional
13
+ # @param tags [Hash] - optional
14
+ # @param limits [Hash] - optional
15
+ def initialize(account_id, customer_id = nil, idempotency_key = nil, tags = nil, limits = nil)
16
+ @account_id = account_id
17
+ @customer_id = customer_id
18
+ @idempotency_key = idempotency_key
19
+ @tags = tags
20
+ @limits = limits
21
+ end
22
+
23
+ def to_json_api
24
+ payload = {
25
+ "data": {
26
+ "type": "individualVirtualDebitCard",
27
+ "attributes": {
28
+ "idempotencyKey": idempotency_key,
29
+ "tags": tags,
30
+ "limits": limits
31
+ },
32
+ "relationships": {
33
+ "account": Unit::Types::Relationship.new("depositAccount", account_id).to_hash
34
+ }
35
+ }
36
+ }
37
+ customer = { "customer": Unit::Types::Relationship.new("customer", customer_id).to_hash } unless customer_id.nil?
38
+ payload[:data][:relationships].merge!(customer) unless customer.nil?
39
+ payload[:data][:attributes].compact!
40
+ payload.to_json
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to list cards
4
+ # @see https://docs.unit.co/cards#list-cards
5
+ module Unit
6
+ module Card
7
+ class ListCardParams
8
+ attr_reader :limit, :offset, :account_id, :customer_id, :tags, :status, :include, :sort
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 [String] - optional
15
+ # @param status [Array<String>] - optional
16
+ # @param include [Array] - optional
17
+ # @param sort [String] - optional
18
+ def initialize(limit = CARD_LIST_LIMIT, offset = CARD_LIST_OFFSET, account_id = nil,
19
+ customer_id = nil, tags = nil, status = nil, include = nil, sort = nil)
20
+ @limit = limit
21
+ @offset = offset
22
+ @account_id = account_id
23
+ @customer_id = customer_id
24
+ @tags = tags
25
+ @status = status
26
+ @include = include
27
+ @sort = sort
28
+ end
29
+
30
+ def to_hash
31
+ params = { "page[limit]": limit,
32
+ "page[offset]": offset,
33
+ "filter[accountId]": account_id,
34
+ "filter[customerId]": customer_id,
35
+ "filter[tags]": tags,
36
+ "include": include&.join(","),
37
+ "sort": sort }
38
+ status&.each_with_index&.map do |val, index|
39
+ params.merge!({ "filter[status][#{index}]": val })
40
+ end
41
+ params.compact
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to replace a card
4
+ # @see https://docs.unit.co/cards#replace-card
5
+ module Unit
6
+ module Card
7
+ class ReplaceCardRequest
8
+ attr_reader :card_id, :shipping_address
9
+
10
+ # @param card_id [String]
11
+ # @param shipping_address [Address] - optional
12
+ def initialize(card_id, shipping_address = nil)
13
+ @card_id = card_id
14
+ @shipping_address = shipping_address
15
+ end
16
+
17
+ def to_json_api
18
+ payload = {
19
+ "data": {
20
+ "type": "replaceCard",
21
+ "attributes": {
22
+ "shippingAddress": shipping_address&.represent
23
+ }
24
+ }
25
+ }
26
+ payload[:data][:attributes].compact!
27
+ payload.to_json
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to get bank verification pdf
4
+ # @see https://docs.unit.co/statements#get-bank-verification-pdf
5
+ module Unit
6
+ module Statement
7
+ class GetBankVerificationPdf
8
+ attr_accessor :account_id, :include_proof_of_funds
9
+
10
+ # @param account_id [String]
11
+ # @param include_proof_of_funds [Boolean]
12
+ def initialize(account_id, include_proof_of_funds: false)
13
+ @account_id = account_id
14
+ @include_proof_of_funds = include_proof_of_funds
15
+ end
16
+
17
+ def to_hash
18
+ params = { "includeProofOfFunds": include_proof_of_funds }
19
+ params.compact
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to get html by id
4
+ # @see https://docs.unit.co/statements#get-statement-html
5
+ module Unit
6
+ module Statement
7
+ class GetHtmlByIdRequest
8
+ attr_accessor :statement_id, :customer_id, :language
9
+
10
+ # @param statement_id [String]
11
+ # @param customer_id [String]
12
+ # @param language [String]
13
+ def initialize(statement_id, customer_id, language = nil)
14
+ @statement_id = statement_id
15
+ @customer_id = customer_id
16
+ @language = language
17
+ end
18
+
19
+ def to_hash
20
+ params = { "filter[customerId]": customer_id,
21
+ "language": language }
22
+ params.compact
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to get pdf by id
4
+ # @see https://docs.unit.co/statements#get-statement-pdf
5
+ module Unit
6
+ module Statement
7
+ class GetPdfByIdRequest
8
+ attr_accessor :statement_id, :customer_id, :language
9
+
10
+ # @param statement_id [String]
11
+ # @param customer_id [String]
12
+ # @param language [String]
13
+ def initialize(statement_id, customer_id, language = nil)
14
+ @statement_id = statement_id
15
+ @customer_id = customer_id
16
+ @language = language
17
+ end
18
+
19
+ def to_hash
20
+ params = { "filter[customerId]": customer_id,
21
+ "language": language }
22
+ params.compact
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Request to list statements
4
+ # @see https://docs.unit.co/statements#list-statements
5
+ module Unit
6
+ module Statement
7
+ class ListStatementParams
8
+ attr_reader :limit, :offset, :account_id, :customer_id, :period, :sort
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 period [String] - optional
15
+ # @param sort [String] - optional
16
+ def initialize(limit = STATEMENT_LIST_LIMIT, offset = STATEMENT_LIST_OFFSET,
17
+ account_id = nil, customer_id = nil, period = nil, sort = nil)
18
+ @limit = limit
19
+ @offset = offset
20
+ @account_id = account_id
21
+ @customer_id = customer_id
22
+ @period = period
23
+ @sort = sort
24
+ end
25
+
26
+ def to_hash
27
+ params = { "page[limit]": limit,
28
+ "page[offset]": offset,
29
+ "filter[accountId]": account_id,
30
+ "filter[customerId]": customer_id,
31
+ "filter[period]": period,
32
+ "sort": sort }
33
+ params.compact
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unit
4
+ module Statement
5
+ STATEMENT_LIST_LIMIT = 100
6
+ STATEMENT_LIST_OFFSET = 0
7
+ autoload :ListStatementParams, "unit/models/statement/list_statement_params"
8
+ autoload :GetPdfByIdRequest, "unit/models/statement/get_pdf_by_id_request"
9
+ autoload :GetHtmlByIdRequest, "unit/models/statement/get_html_by_id_request"
10
+ autoload :GetBankVerificationPdf, "unit/models/statement/get_bank_verification_pdf"
11
+
12
+ class << self
13
+ # List statements
14
+ # @see https://docs.unit.co/statements#list-statements
15
+ # @param limit [Integer]
16
+ # @param offset [Integer]
17
+ # @param account_id [String]
18
+ # @param customer_id [String]
19
+ # @param period [String]
20
+ # @param sort [String]
21
+ def list_statements(limit: STATEMENT_LIST_LIMIT, offset: STATEMENT_LIST_OFFSET,
22
+ account_id: nil, customer_id: nil, period: nil, sort: nil)
23
+ params = ListStatementParams.new(limit, offset, account_id, customer_id, period, sort)
24
+ Unit::Resource::StatementResource.list(params)
25
+ end
26
+
27
+ # Get statement pdf by id
28
+ # @see https://docs.unit.co/statements#get-statement-pdf
29
+ # @param customer_id [String]
30
+ # @param language [String]
31
+ def get_pdf_by_id(statement_id:, customer_id:, language: nil)
32
+ request = GetPdfByIdRequest.new(statement_id, customer_id, language)
33
+ Unit::Resource::StatementResource.get_pdf_by_id(request)
34
+ end
35
+
36
+ # Get statement html by id
37
+ # @see https://docs.unit.co/statements#get-statement-html
38
+ # @param customer_id [String]
39
+ # @param language [String]
40
+ def get_html_by_id(statement_id:, customer_id:, language: nil)
41
+ request = GetHtmlByIdRequest.new(statement_id, customer_id, language)
42
+ Unit::Resource::StatementResource.get_html_by_id(request)
43
+ end
44
+
45
+ # Get a bank verification pdf
46
+ # @see https://docs.unit.co/statements#get-bank-verification-pdf
47
+ # @param account_id [String]
48
+ # @param include_proof_of_funds [Boolean]
49
+ def get_bank_verification_pdf(account_id:, include_proof_of_funds: false)
50
+ request = GetBankVerificationPdf.new(account_id, include_proof_of_funds: include_proof_of_funds)
51
+ Unit::Resource::StatementResource.get_bank_verification(request)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -35,11 +35,19 @@ module HttpHelper
35
35
  request = net_http.new uri, headers
36
36
  request.body = body unless body.nil?
37
37
  response = http.request request
38
- response.body = JSON.parse(response.body)
38
+ response.body = response_check(response)
39
39
  response
40
40
  end
41
41
  end
42
42
 
43
+ def self.response_check(response)
44
+ if response.body.include?("html") || response.body.include?("PDF")
45
+ response.body
46
+ else
47
+ JSON.parse(response.body)
48
+ end
49
+ end
50
+
43
51
  def self.encode(value, key = nil)
44
52
  case value
45
53
  when Hash then value.map { |k, v| encode(v, append_key(key, k)) }.join("&")
data/lib/unit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Unit
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/unit_ruby_sdk.rb CHANGED
@@ -9,6 +9,8 @@ module Unit
9
9
  autoload :ApiToken, "unit/models/api_token/api_token"
10
10
  autoload :Payment, "unit/models/payment/payment"
11
11
  autoload :Transaction, "unit/models/transaction/transaction"
12
+ autoload :Card, "unit/models/card/card"
13
+ autoload :Statement, "unit/models/statement/statement"
12
14
 
13
15
  module Resource
14
16
  autoload :ApplicationResource, "unit/api_resources/application_resource"
@@ -17,6 +19,8 @@ module Unit
17
19
  autoload :ApiTokenResource, "unit/api_resources/api_token_resource"
18
20
  autoload :PaymentResource, "unit/api_resources/payment_resource"
19
21
  autoload :TransactionResource, "unit/api_resources/transaction_resource"
22
+ autoload :CardResource, "unit/api_resources/card_resource"
23
+ autoload :StatementResource, "unit/api_resources/statement_resource"
20
24
  end
21
25
 
22
26
  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: 0.1.4
4
+ version: 0.1.5
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-22 00:00:00.000000000 Z
11
+ date: 2023-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot_rails
@@ -98,8 +98,10 @@ files:
98
98
  - lib/unit/api_resources/api_token_resource.rb
99
99
  - lib/unit/api_resources/application_resource.rb
100
100
  - lib/unit/api_resources/base_resource.rb
101
+ - lib/unit/api_resources/card_resource.rb
101
102
  - lib/unit/api_resources/customer_resource.rb
102
103
  - lib/unit/api_resources/payment_resource.rb
104
+ - lib/unit/api_resources/statement_resource.rb
103
105
  - lib/unit/api_resources/transaction_resource.rb
104
106
  - lib/unit/errors/unit_error.rb
105
107
  - lib/unit/errors/unit_error_payload.rb
@@ -122,6 +124,13 @@ files:
122
124
  - lib/unit/models/application/list_application_params.rb
123
125
  - lib/unit/models/application/patch_application_request.rb
124
126
  - lib/unit/models/application/upload_document_request.rb
127
+ - lib/unit/models/card/card.rb
128
+ - lib/unit/models/card/create_business_debit_card_request.rb
129
+ - lib/unit/models/card/create_business_virtual_debit_card_request.rb
130
+ - lib/unit/models/card/create_individual_debit_card_request.rb
131
+ - lib/unit/models/card/create_individual_virtual_card_request.rb
132
+ - lib/unit/models/card/list_card_params.rb
133
+ - lib/unit/models/card/replace_card_request.rb
125
134
  - lib/unit/models/customer/add_authorized_users_request.rb
126
135
  - lib/unit/models/customer/archive_customer_request.rb
127
136
  - lib/unit/models/customer/customer.rb
@@ -132,6 +141,11 @@ files:
132
141
  - lib/unit/models/payment/create_book_payment_request.rb
133
142
  - lib/unit/models/payment/patch_book_payment_request.rb
134
143
  - lib/unit/models/payment/payment.rb
144
+ - lib/unit/models/statement/get_bank_verification_pdf.rb
145
+ - lib/unit/models/statement/get_html_by_id_request.rb
146
+ - lib/unit/models/statement/get_pdf_by_id_request.rb
147
+ - lib/unit/models/statement/list_statement_params.rb
148
+ - lib/unit/models/statement/statement.rb
135
149
  - lib/unit/models/transaction/get_transaction_params.rb
136
150
  - lib/unit/models/transaction/list_transaction_params.rb
137
151
  - lib/unit/models/transaction/patch_tags_request.rb