culqi-ruby-oficial 1.0.0 → 1.0.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.
@@ -1,14 +1,64 @@
1
- require 'util/connect'
2
-
3
- module Culqi::List
4
-
5
- def initialize
6
- @url = ''
7
- end
8
-
9
- def list(params={})
10
- response = Culqi.connect(@url, Culqi.secret_key, params, 'get', Culqi::LIST_TIMEOUT)
11
- return response.read_body
12
- end
13
-
14
- end
1
+ require 'util/connect'
2
+ require 'util/validation/token'
3
+ require 'util/validation/charge'
4
+ require 'util/validation/customer'
5
+ require 'util/validation/refund'
6
+ require 'util/validation/plan'
7
+ require 'util/validation/card'
8
+ require 'util/validation/subscription'
9
+ require 'util/validation/order'
10
+
11
+ module Culqi::List
12
+
13
+ def initialize
14
+ @url = ''
15
+ end
16
+
17
+ def list(params={})
18
+ error = verifyClassValidationList(@url, params)
19
+ if error
20
+ return error
21
+ end
22
+ response = Culqi.connect(@url, Culqi.secret_key, params, 'get', Culqi::LIST_TIMEOUT)
23
+ return response
24
+ end
25
+
26
+ def verifyClassValidationList(url='', params)
27
+ begin
28
+ if @url.include? 'token'
29
+ TokenValidation.list(params)
30
+ end
31
+
32
+ if @url.include? 'charge'
33
+ ChargeValidation.list(params)
34
+ end
35
+
36
+ if @url.include? 'card'
37
+ CardValidation.list(params)
38
+ end
39
+
40
+ if @url.include? 'customer'
41
+ CustomerValidation.list(params)
42
+ end
43
+
44
+ if @url.include? 'refund'
45
+ RefundValidation.list(params)
46
+ end
47
+
48
+ if @url.include? 'plan'
49
+ PlanValidation.list(params)
50
+ end
51
+
52
+ if @url.include? 'subscription'
53
+ SubscriptionValidation.list(params)
54
+ end
55
+
56
+ if @url.include? 'order'
57
+ OrderValidation.list(params)
58
+ end
59
+ rescue CustomException => e
60
+ return e.message
61
+ end
62
+ end
63
+
64
+ end
@@ -1,27 +1,85 @@
1
- require 'util/connect'
2
- require 'util/encrypt-data'
3
- module Culqi::Post
4
-
5
- def initialize
6
- @url = ''
7
- end
8
-
9
- def create(params={}, rsa_key='', rsa_id='')
10
- key = ''
11
- puts params
12
- if @url.include? 'token'
13
- if(rsa_key != '')
14
- params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
15
- end
16
- key = Culqi.public_key
17
- response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
18
- return response, statuscode
19
- else
20
- key = Culqi.secret_key
21
- response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, false, '')
22
- return response, statuscode
23
- end
24
-
25
- end
26
-
27
- end
1
+ require 'util/connect'
2
+ require 'util/encrypt-data'
3
+ require 'util/validation/token'
4
+ require 'util/validation/charge'
5
+ require 'util/validation/customer'
6
+ require 'util/validation/refund'
7
+ require 'util/validation/plan'
8
+ require 'util/validation/card'
9
+ require 'util/validation/subscription'
10
+ require 'util/validation/order'
11
+
12
+ module Culqi::Post
13
+
14
+ def initialize
15
+ @url = ''
16
+ end
17
+
18
+ def create(params={}, rsa_key='', rsa_id='')
19
+ key = ''
20
+ puts params
21
+ error = verifyClassValidation(@url, params)
22
+ if error
23
+ return error
24
+ end
25
+
26
+ if @url.include? 'token'
27
+ if(rsa_key != '')
28
+ params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
29
+ end
30
+ key = Culqi.public_key
31
+ response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
32
+ return response, statuscode
33
+ else
34
+ key = Culqi.secret_key
35
+ url = @url
36
+
37
+ if(url.include? 'plans')
38
+ url = url + 'create/'
39
+ end
40
+
41
+ response, statuscode = Culqi.connect(url, key, params, 'post', Culqi::READ_TIMEOUT, false, '')
42
+ return response, statuscode
43
+ end
44
+
45
+ end
46
+
47
+ def verifyClassValidation(url='', params)
48
+ begin
49
+ if @url.include? 'token'
50
+ TokenValidation.create(params)
51
+ end
52
+
53
+ if @url.include? 'charge'
54
+ ChargeValidation.create(params)
55
+ end
56
+
57
+ if @url.include? 'card'
58
+ CardValidation.create(params)
59
+ end
60
+
61
+ if @url.include? 'customer'
62
+ CustomerValidation.create(params)
63
+ end
64
+
65
+ if @url.include? 'refund'
66
+ RefundValidation.create(params)
67
+ end
68
+
69
+ if @url.include? 'plan'
70
+ PlanValidation.create(params)
71
+ end
72
+
73
+ if @url.include? 'subscription'
74
+ SubscriptionValidation.create(params)
75
+ end
76
+
77
+ if @url.include? 'order'
78
+ OrderValidation.create(params)
79
+ end
80
+ rescue CustomException => e
81
+ return e.message
82
+ end
83
+ end
84
+
85
+ end
@@ -1,17 +1,22 @@
1
- require 'util/connect'
2
-
3
- module Culqi::Update
4
-
5
- def initialize
6
- @url = ''
7
- end
8
-
9
- def update(id, params={}, rsa_key='', rsa_id='')
10
- if(rsa_key != '')
11
- params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
12
- end
13
- response, statusCode = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, params, 'patch', Culqi::READ_TIMEOUT, rsa_id)
14
- return response, statusCode
15
- end
16
-
17
- end
1
+ require 'util/connect'
2
+ require 'util/validation/helper'
3
+
4
+ module Culqi::Update
5
+
6
+ def initialize
7
+ @url = ''
8
+ end
9
+
10
+ def update(id, params={}, rsa_key='', rsa_id='')
11
+ error = verifyClassValidationGet(@url, id)
12
+ if error
13
+ return error
14
+ end
15
+ if(rsa_key != '')
16
+ params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
17
+ end
18
+ response, statusCode = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, params, 'patch', Culqi::READ_TIMEOUT, rsa_id)
19
+ return response, statusCode
20
+ end
21
+
22
+ end
data/lib/util/connect.rb CHANGED
@@ -1,42 +1,54 @@
1
- require 'excon'
2
- require 'json'
3
- require 'culqi-ruby'
4
-
5
- module Culqi
6
- def self.connect(url, api_key, data, type, time_out, secure_url = false, rsa_id='')
7
- base_url = secure_url ? Culqi::API_BASE_SECURE : Culqi::API_BASE
8
- full_url = "#{base_url}#{url}"
9
-
10
- headers = {
11
- "Authorization" => "Bearer #{api_key}",
12
- "Content-Type" => "application/json",
13
- "x-culqi-rsa-id" => rsa_id
14
- }
15
-
16
- puts "Body"
17
- puts data.to_json
18
-
19
- response = Excon.new(full_url,
20
- headers: headers,
21
- read_timeout: time_out,
22
- idempotent: true,
23
- retry_limit: 6)
24
-
25
- case type.upcase
26
- when 'GET'
27
- result = response.request(method: :get, query: data)
28
- when 'POST'
29
- result = response.request(method: :post, body: data.to_json)
30
- when 'DELETE'
31
- result = response.request(method: :delete)
32
- when 'PATCH'
33
- result = response.request(method: :patch, body: data.to_json)
34
- else
35
- raise ArgumentError, "Unsupported request type: #{type}"
36
- end
37
-
38
- puts result.body
39
-
40
- return result.body, result.status
41
- end
42
- end
1
+ require 'excon'
2
+ require 'json'
3
+ require 'culqi-ruby'
4
+
5
+ module Culqi
6
+ def self.connect(url, api_key, data, type, time_out, secure_url = false, rsa_id='')
7
+ base_url = secure_url ? Culqi::API_BASE_SECURE : Culqi::API_BASE
8
+ full_url = "#{base_url}#{url}"
9
+
10
+ print full_url
11
+
12
+ if(api_key.include? 'test')
13
+ env = Culqi::X_CULQI_ENV_TEST
14
+ else
15
+ env = Culqi::X_CULQI_ENV_LIVE
16
+ end
17
+
18
+ headers = {
19
+ "Authorization" => "Bearer #{api_key}",
20
+ "Content-Type" => "application/json",
21
+ "x-culqi-env" => env,
22
+ "x-api-version" => Culqi::X_API_VERSION,
23
+ "x-culqi-client" => Culqi::X_CULQI_CLIENT,
24
+ "x-culqi-client-version" => Culqi::X_CULQI_CLIENT,
25
+ "x-culqi-rsa-id" => rsa_id
26
+ }
27
+
28
+ puts "Body"
29
+ puts data.to_json
30
+
31
+ response = Excon.new(full_url,
32
+ headers: headers,
33
+ read_timeout: time_out,
34
+ idempotent: true,
35
+ retry_limit: 6)
36
+
37
+ case type.upcase
38
+ when 'GET'
39
+ result = response.request(method: :get, query: data)
40
+ when 'POST'
41
+ result = response.request(method: :post, body: data.to_json)
42
+ when 'DELETE'
43
+ result = response.request(method: :delete)
44
+ when 'PATCH'
45
+ result = response.request(method: :patch, body: data.to_json)
46
+ else
47
+ raise ArgumentError, "Unsupported request type: #{type}"
48
+ end
49
+
50
+ puts result.body
51
+
52
+ return result.body, result.status
53
+ end
54
+ end
@@ -0,0 +1,22 @@
1
+ # country_codes.rb
2
+ module CountryCodes
3
+ def self.get_country_codes
4
+ ['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ',
5
+ 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS',
6
+ 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN',
7
+ 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE',
8
+ 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF',
9
+ 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM',
10
+ 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM',
11
+ 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC',
12
+ 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK',
13
+ 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA',
14
+ 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG',
15
+ 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW',
16
+ 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS',
17
+ 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO',
18
+ 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI',
19
+ 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW']
20
+ end
21
+ end
22
+
@@ -1,49 +1,49 @@
1
- require 'openssl'
2
- require 'base64'
3
- require 'json'
4
- require 'openssl/oaep'
5
-
6
- module Encrypt
7
- def self.generate_random_bytes(length)
8
- OpenSSL::Random.random_bytes(length)
9
- end
10
-
11
- def self.encrypt_with_aes_rsa(data, public_key, is_json)
12
- key = generate_random_bytes(32) # Generate a 256-bit random key for AES encryption
13
- iv = generate_random_bytes(12) # GCM mode requires a 96-bit (12 bytes) random initialization vector
14
- auth_data = generate_random_bytes(16)
15
- cipher = OpenSSL::Cipher.new('AES-256-GCM')
16
- cipher.encrypt
17
- cipher.key = key
18
- cipher.iv = iv
19
- cipher.auth_data = auth_data
20
-
21
- # Since GCM does not require padding, we can directly pass the data to be encrypted
22
- cipher_text = cipher.update(data.to_json) + cipher.final
23
-
24
- # Get the auth tag
25
- auth_tag = cipher.auth_tag
26
-
27
- # Combine cipher text and auth tag
28
- encrypted = cipher_text #+ auth_tag
29
- #encrypted = encrypted.slice(0...-16)
30
- encrypted_data = Base64.strict_encode64(encrypted)
31
-
32
- ####
33
- rsa_public_key = OpenSSL::PKey::RSA.new(public_key)
34
- encrypted_key = rsa_encrypt(key, rsa_public_key)
35
- encrypted_iv = rsa_encrypt(iv, rsa_public_key)
36
-
37
- { encrypted_data: encrypted_data, encrypted_key: encrypted_key, encrypted_iv: encrypted_iv }
38
- end
39
-
40
- def self.rsa_encrypt(data, public_key)
41
- # Define the encryption parameters
42
- label = ''
43
-
44
- md = OpenSSL::Digest::SHA256
45
- cipher_text = public_key.public_encrypt_oaep(data, label, md, md)
46
-
47
- Base64.strict_encode64(cipher_text)
48
- end
49
- end
1
+ require 'openssl'
2
+ require 'base64'
3
+ require 'json'
4
+ require 'openssl/oaep'
5
+
6
+ module Encrypt
7
+ def self.generate_random_bytes(length)
8
+ OpenSSL::Random.random_bytes(length)
9
+ end
10
+
11
+ def self.encrypt_with_aes_rsa(data, public_key, is_json)
12
+ key = generate_random_bytes(32) # Generate a 256-bit random key for AES encryption
13
+ iv = generate_random_bytes(12) # GCM mode requires a 96-bit (12 bytes) random initialization vector
14
+ auth_data = generate_random_bytes(16)
15
+ cipher = OpenSSL::Cipher.new('AES-256-GCM')
16
+ cipher.encrypt
17
+ cipher.key = key
18
+ cipher.iv = iv
19
+ cipher.auth_data = auth_data
20
+
21
+ # Since GCM does not require padding, we can directly pass the data to be encrypted
22
+ cipher_text = cipher.update(data.to_json) + cipher.final
23
+
24
+ # Get the auth tag
25
+ auth_tag = cipher.auth_tag
26
+
27
+ # Combine cipher text and auth tag
28
+ encrypted = cipher_text #+ auth_tag
29
+ #encrypted = encrypted.slice(0...-16)
30
+ encrypted_data = Base64.strict_encode64(encrypted)
31
+
32
+ ####
33
+ rsa_public_key = OpenSSL::PKey::RSA.new(public_key)
34
+ encrypted_key = rsa_encrypt(key, rsa_public_key)
35
+ encrypted_iv = rsa_encrypt(iv, rsa_public_key)
36
+
37
+ { encrypted_data: encrypted_data, encrypted_key: encrypted_key, encrypted_iv: encrypted_iv }
38
+ end
39
+
40
+ def self.rsa_encrypt(data, public_key)
41
+ # Define the encryption parameters
42
+ label = ''
43
+
44
+ md = OpenSSL::Digest::SHA256
45
+ cipher_text = public_key.public_encrypt_oaep(data, label, md, md)
46
+
47
+ Base64.strict_encode64(cipher_text)
48
+ end
49
+ end
@@ -0,0 +1,38 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class CardValidation
8
+ def self.create(data)
9
+ data = data.to_json
10
+ data = JSON.parse(data)
11
+ HelperValidation.validate_string_start(data['customer_id'], "cus")
12
+ HelperValidation.validate_string_start(data['token_id'], "tkn")
13
+ end
14
+
15
+ def self.list(data)
16
+ # Validate card_brand
17
+ if data.key?('card_brand')
18
+ allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners']
19
+ Helpers.validate_value(data[:card_brand], allowed_brand_values)
20
+ end
21
+
22
+ # Validate card_type
23
+ if data.key?('card_type')
24
+ allowed_card_type_values = ['credito', 'debito', 'internacional']
25
+ Helpers.validate_value(data[:card_type], allowed_card_type_values)
26
+ end
27
+
28
+ # Validate date filter
29
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
30
+ Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
31
+ end
32
+
33
+ # Validate country_code
34
+ if data.key?('country_code')
35
+ Helpers.validate_value(data[:country_code], get_country_codes)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,131 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class ChargeValidation
8
+ def self.create(data)
9
+ data = data.to_json
10
+ data = JSON.parse(data)
11
+ # Validate email
12
+ raise 'Invalid email.' unless HelperValidation.is_valid_email(data['email'])
13
+
14
+ # Validate amount
15
+ amount = data['amount']
16
+
17
+ if amount.is_a?(String)
18
+ begin
19
+ amount = Integer(amount)
20
+ print amount
21
+ rescue ArgumentError
22
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
23
+ end
24
+ end
25
+
26
+ unless amount.is_a?(Integer)
27
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
28
+ end
29
+
30
+ HelperValidation.validate_currency_code(data['currency_code'])
31
+ source_id = data['source_id']
32
+
33
+ if source_id.start_with?("tkn")
34
+ HelperValidation.validate_string_start(source_id, "tkn")
35
+ elsif source_id.start_with?("ype")
36
+ HelperValidation.validate_string_start(source_id, "ype")
37
+ elsif source_id.start_with?("crd")
38
+ HelperValidation.validate_string_start(source_id, "crd")
39
+ else
40
+ raise CustomException.new("Incorrect format. The format must start with tkn, ype, or crd")
41
+ end
42
+ end
43
+
44
+ def self.list(data)
45
+ # Validate email
46
+ if data.key?('email')
47
+ unless Helpers.is_valid_email(data[:email])
48
+ raise CustomException.new('Invalid email.')
49
+ end
50
+ end
51
+
52
+ # Validate amount
53
+ if data.key?('amount')
54
+ amount = data[:amount]
55
+
56
+ if amount.is_a?(String)
57
+ begin
58
+ amount = Integer(amount)
59
+ rescue ArgumentError
60
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
61
+ end
62
+ end
63
+
64
+ unless amount.is_a?(Integer)
65
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
66
+ end
67
+ end
68
+
69
+ # Validate min_amount
70
+ if data.key?('min_amount')
71
+ unless data[:min_amount].is_a?(Integer)
72
+ raise CustomException.new('Invalid min amount.')
73
+ end
74
+ end
75
+
76
+ # Validate max_amount
77
+ if data.key?('max_amount')
78
+ unless data[:max_amount].is_a?(Integer)
79
+ raise CustomException.new('Invalid max amount.')
80
+ end
81
+ end
82
+
83
+ # Validate installments
84
+ if data.key?('installments')
85
+ unless data[:installments].is_a?(Integer)
86
+ raise CustomException.new('Invalid installments.')
87
+ end
88
+ end
89
+
90
+ # Validate min_installments
91
+ if data.key?('min_installments')
92
+ unless data[:min_installments].is_a?(Integer)
93
+ raise CustomException.new('Invalid min installments.')
94
+ end
95
+ end
96
+
97
+ # Validate max_installments
98
+ if data.key?('max_installments')
99
+ unless data[:max_installments].is_a?(Integer)
100
+ raise CustomException.new('Invalid max installments.')
101
+ end
102
+ end
103
+
104
+ # Validate currency_code
105
+ if data.key?('currency_code')
106
+ Helpers.validate_currency_code(data[:currency_code])
107
+ end
108
+
109
+ # Validate card_brand
110
+ if data.key?('card_brand')
111
+ allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners']
112
+ Helpers.validate_value(data[:card_brand], allowed_brand_values)
113
+ end
114
+
115
+ # Validate card_type
116
+ if data.key?('card_type')
117
+ allowed_card_type_values = ['credito', 'debito', 'internacional']
118
+ Helpers.validate_value(data[:card_type], allowed_card_type_values)
119
+ end
120
+
121
+ # Validate date filter
122
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
123
+ Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
124
+ end
125
+
126
+ # Validate country_code
127
+ if data.key?('country_code')
128
+ Helpers.validate_value(data[:country_code], get_country_codes)
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,41 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/country-codes'
5
+ require 'util/validation/helper'
6
+ require 'util/validation/error'
7
+
8
+ class CustomerValidation
9
+ def self.create(data)
10
+ data = data.to_json
11
+ data = JSON.parse(data)
12
+ # Validate address, firstname, and lastname
13
+ raise CustomException.new('first name is empty.') if data['first_name'].nil? || data['first_name'].empty?
14
+ raise CustomException.new('last name is empty.') if data['last_name'].nil? || data['last_name'].empty?
15
+ raise CustomException.new('address is empty.') if data['address'].nil? || data['address'].empty?
16
+ raise CustomException.new('address_city is empty.') if data['address_city'].nil? || data['address_city'].empty?
17
+
18
+ unless data['phone_number'].is_a?(String)
19
+ raise CustomException.new("Invalid 'phone_number'. It should be a string.")
20
+ end
21
+
22
+ # Validate country code
23
+ HelperValidation.validate_value(data['country_code'], CountryCodes.get_country_codes)
24
+
25
+ # Validate email
26
+ raise 'Invalid email.' unless HelperValidation.is_valid_email(data['email'])
27
+ end
28
+
29
+ def self.list(data)
30
+ # Validate email
31
+ if data.key?('email')
32
+ unless Helpers.is_valid_email(data[:email])
33
+ raise CustomException.new('Invalid email.')
34
+ end
35
+ end
36
+ # Validate country_code
37
+ if data.key?('country_code')
38
+ Helpers.validate_value(data[:country_code], get_country_codes)
39
+ end
40
+ end
41
+ end