culqi-ruby-oficial 1.0.4 → 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,76 +1,78 @@
1
- require 'date'
2
- require 'uri'
3
- require 'json'
4
- require 'util/validation/helper'
5
- require 'util/validation/error'
6
-
7
- class OrderValidation
8
- def self.create(data)
9
- # Validate amount
10
- amount = data[:amount]
11
-
12
- if amount.is_a?(String)
13
- begin
14
- amount = Integer(amount)
15
- rescue ArgumentError
16
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
17
- end
18
- end
19
-
20
- unless amount.is_a?(Integer)
21
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
22
- end
23
-
24
- # Validate currency
25
- HelperValidation.validate_currency_code(data[:currency_code])
26
-
27
- # Validate firstname, lastname, and phone
28
- client_details = data[:client_details] || {}
29
- raise CustomException.new('first name is empty.') if client_details[:first_name].nil? || client_details[:first_name].empty?
30
- raise CustomException.new('last name is empty.') if client_details[:last_name].nil? || client_details[:last_name].empty?
31
- raise CustomException.new('phone_number is empty.') if client_details[:phone_number].nil? || client_details[:phone_number].empty?
32
-
33
- # Validate email
34
- raise CustomException.new('Invalid email.') unless HelperValidation.is_valid_email(client_details[:email])
35
-
36
- # Validate expiration date
37
- raise CustomException.new('expiration_date must be a future date.') unless HelperValidation.is_future_date(data[:expiration_date])
38
- end
39
-
40
- def self.list(data)
41
- # Validate amount
42
- if data.key?('amount')
43
- amount = data[:amount]
44
-
45
- if amount.is_a?(String)
46
- begin
47
- amount = Integer(amount)
48
- rescue ArgumentError
49
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
50
- end
51
- end
52
-
53
- unless amount.is_a?(Integer)
54
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
55
- end
56
- end
57
-
58
- # Validate min_amount
59
- if data.key?('min_amount')
60
- unless data[:min_amount].is_a?(Integer)
61
- raise CustomException.new('Invalid min amount.')
62
- end
63
- end
64
-
65
- # Validate max_amount
66
- if data.key?('max_amount')
67
- unless data[:max_amount].is_a?(Integer)
68
- raise CustomException.new('Invalid max amount.')
69
- end
70
- end
71
-
72
- if data.key?('creation_date_from') && data.key?('creation_date_to')
73
- HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
74
- end
75
- end
76
- end
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class OrderValidation
8
+ def self.create(data)
9
+ # Validate amount
10
+ data = data.to_json
11
+ data = JSON.parse(data)
12
+ amount = data['amount'];
13
+
14
+ if amount.is_a?(String)
15
+ begin
16
+ amount = Integer(amount)
17
+ rescue ArgumentError
18
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
19
+ end
20
+ end
21
+
22
+ unless amount.is_a?(Integer)
23
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
24
+ end
25
+
26
+ # Validate currency
27
+ HelperValidation.validate_currency_code(data['currency_code'])
28
+
29
+ # Validate firstname, lastname, and phone
30
+ client_details = data['client_details'] || {}
31
+ raise CustomException.new('first name is empty.') if client_details['first_name'].nil? || client_details['first_name'].empty?
32
+ raise CustomException.new('last name is empty.') if client_details['last_name'].nil? || client_details['last_name'].empty?
33
+ raise CustomException.new('phone_number is empty.') if client_details['phone_number'].nil? || client_details['phone_number'].empty?
34
+
35
+ # Validate email
36
+ raise CustomException.new('Invalid email.') unless HelperValidation.is_valid_email(client_details['email'])
37
+
38
+ # Validate expiration date
39
+ raise CustomException.new('expiration_date must be a future date.') unless HelperValidation.is_future_date(data['expiration_date'])
40
+ end
41
+
42
+ def self.list(data)
43
+ # Validate amount
44
+ if data.key?('amount')
45
+ amount = data[:amount]
46
+
47
+ if amount.is_a?(String)
48
+ begin
49
+ amount = Integer(amount)
50
+ rescue ArgumentError
51
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
52
+ end
53
+ end
54
+
55
+ unless amount.is_a?(Integer)
56
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
57
+ end
58
+ end
59
+
60
+ # Validate min_amount
61
+ if data.key?('min_amount')
62
+ unless data[:min_amount].is_a?(Integer)
63
+ raise CustomException.new('Invalid min amount.')
64
+ end
65
+ end
66
+
67
+ # Validate max_amount
68
+ if data.key?('max_amount')
69
+ unless data[:max_amount].is_a?(Integer)
70
+ raise CustomException.new('Invalid max amount.')
71
+ end
72
+ end
73
+
74
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
75
+ HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
76
+ end
77
+ end
78
+ end
@@ -1,69 +1,71 @@
1
- require 'date'
2
- require 'uri'
3
- require 'json'
4
- require 'util/validation/helper'
5
- require 'util/validation/error'
6
-
7
- class PlanValidation
8
- def self.create(data)
9
- # Validate amount
10
- amount = data[:amount]
11
-
12
- if amount.is_a?(String)
13
- begin
14
- amount = Integer(amount)
15
- print amount
16
- rescue ArgumentError
17
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
18
- end
19
- end
20
-
21
- unless amount.is_a?(Integer)
22
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
23
- end
24
-
25
- # Validate interval
26
- allowed_values = ['dias', 'semanas', 'meses', 'años']
27
- HelperValidation.validate_value(data[:interval], allowed_values)
28
-
29
- # Validate currency
30
- HelperValidation.validate_currency_code(data[:currency_code])
31
- end
32
-
33
- def self.list(data)
34
- # Validate amount
35
- if data.key?('amount')
36
- amount = data[:amount]
37
-
38
- if amount.is_a?(String)
39
- begin
40
- amount = Integer(amount)
41
- rescue ArgumentError
42
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
43
- end
44
- end
45
-
46
- unless amount.is_a?(Integer)
47
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
48
- end
49
- end
50
-
51
- # Validate min_amount
52
- if data.key?('min_amount')
53
- unless data[:min_amount].is_a?(Integer)
54
- raise CustomException.new('Invalid min amount.')
55
- end
56
- end
57
-
58
- # Validate max_amount
59
- if data.key?('max_amount')
60
- unless data[:max_amount].is_a?(Integer)
61
- raise CustomException.new('Invalid max amount.')
62
- end
63
- end
64
-
65
- if data.key?('creation_date_from') && data.key?('creation_date_to')
66
- HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
67
- end
68
- end
69
- end
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class PlanValidation
8
+ def self.create(data)
9
+ data = data.to_json
10
+ data = JSON.parse(data)
11
+ # Validate amount
12
+ amount = data['amount']
13
+
14
+ if amount.is_a?(String)
15
+ begin
16
+ amount = Integer(amount)
17
+ print amount
18
+ rescue ArgumentError
19
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
20
+ end
21
+ end
22
+
23
+ unless amount.is_a?(Integer)
24
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
25
+ end
26
+
27
+ # Validate interval
28
+ allowed_values = ['dias', 'semanas', 'meses', 'años']
29
+ HelperValidation.validate_value(data['interval'], allowed_values)
30
+
31
+ # Validate currency
32
+ HelperValidation.validate_currency_code(data['currency_code'])
33
+ end
34
+
35
+ def self.list(data)
36
+ # Validate amount
37
+ if data.key?('amount')
38
+ amount = data[:amount]
39
+
40
+ if amount.is_a?(String)
41
+ begin
42
+ amount = Integer(amount)
43
+ rescue ArgumentError
44
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
45
+ end
46
+ end
47
+
48
+ unless amount.is_a?(Integer)
49
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
50
+ end
51
+ end
52
+
53
+ # Validate min_amount
54
+ if data.key?('min_amount')
55
+ unless data[:min_amount].is_a?(Integer)
56
+ raise CustomException.new('Invalid min amount.')
57
+ end
58
+ end
59
+
60
+ # Validate max_amount
61
+ if data.key?('max_amount')
62
+ unless data[:max_amount].is_a?(Integer)
63
+ raise CustomException.new('Invalid max amount.')
64
+ end
65
+ end
66
+
67
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
68
+ HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
69
+ end
70
+ end
71
+ end
@@ -1,45 +1,47 @@
1
- require 'date'
2
- require 'uri'
3
- require 'json'
4
- require 'util/validation/helper'
5
- require 'util/validation/error'
6
-
7
- class RefundValidation
8
- def self.create(data)
9
- # Validate charge format
10
- HelperValidation.validate_string_start(data[:charge_id], "chr")
11
-
12
- # Validate reason
13
- allowed_values = ['duplicado', 'fraudulento', 'solicitud_comprador']
14
- HelperValidation.validate_value(data[:reason], allowed_values)
15
-
16
- # Validate amount
17
- amount = data[:amount]
18
-
19
- if amount.is_a?(String)
20
- begin
21
- amount = Integer(amount)
22
- print amount
23
- rescue ArgumentError
24
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
25
- end
26
- end
27
-
28
- unless amount.is_a?(Integer)
29
- raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
30
- end
31
- end
32
-
33
- def self.list(data)
34
- # Validate card_brand
35
- if data.key?('reason')
36
- allowed_brand_values = ['duplicado', 'fraudulento', 'solicitud_comprador']
37
- Helpers.validate_value(data[:reason], allowed_brand_values)
38
- end
39
-
40
- # Validate date filter
41
- if data.key?('creation_date_from') && data.key?('creation_date_to')
42
- Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
43
- end
44
- end
45
- end
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class RefundValidation
8
+ def self.create(data)
9
+ data = data.to_json
10
+ data = JSON.parse(data)
11
+ # Validate charge format
12
+ HelperValidation.validate_string_start(data['charge_id'], "chr")
13
+
14
+ # Validate reason
15
+ allowed_values = ['duplicado', 'fraudulento', 'solicitud_comprador']
16
+ HelperValidation.validate_value(data['reason'], allowed_values)
17
+
18
+ # Validate amount
19
+ amount = data['amount']
20
+
21
+ if amount.is_a?(String)
22
+ begin
23
+ amount = Integer(amount)
24
+ print amount
25
+ rescue ArgumentError
26
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
27
+ end
28
+ end
29
+
30
+ unless amount.is_a?(Integer)
31
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
32
+ end
33
+ end
34
+
35
+ def self.list(data)
36
+ # Validate card_brand
37
+ if data.key?('reason')
38
+ allowed_brand_values = ['duplicado', 'fraudulento', 'solicitud_comprador']
39
+ Helpers.validate_value(data[:reason], allowed_brand_values)
40
+ end
41
+
42
+ # Validate date filter
43
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
44
+ Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
45
+ end
46
+ end
47
+ end
@@ -1,24 +1,26 @@
1
- require 'date'
2
- require 'uri'
3
- require 'json'
4
- require 'util/validation/helper'
5
- require 'util/validation/error'
6
-
7
- class SubscriptionValidation
8
- def self.create(data)
9
- HelperValidation.validate_string_start(data[:card_id], "crd")
10
- HelperValidation.validate_string_start(data[:plan_id], "pln")
11
- end
12
-
13
- def self.list(data)
14
- # Validate card_brand
15
- if data.key?('plan_id')
16
- HelperValidation.validate_string_start(data[:plan_id], "pln")
17
- end
18
-
19
- # Validate date filter
20
- if data.key?('creation_date_from') && data.key?('creation_date_to')
21
- Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
22
- end
23
- end
24
- end
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class SubscriptionValidation
8
+ def self.create(data)
9
+ data = data.to_json
10
+ data = JSON.parse(data)
11
+ HelperValidation.validate_string_start(data['card_id'], "crd")
12
+ HelperValidation.validate_string_start(data['plan_id'], "pln")
13
+ end
14
+
15
+ def self.list(data)
16
+ # Validate card_brand
17
+ if data.key?('plan_id')
18
+ HelperValidation.validate_string_start(data[:plan_id], "pln")
19
+ end
20
+
21
+ # Validate date filter
22
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
23
+ Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
24
+ end
25
+ end
26
+ end
@@ -1,65 +1,70 @@
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 TokenValidation
9
- def self.create(data)
10
- # Validate card number
11
- raise CustomException.new('Invalid card number.') unless HelperValidation.is_valid_card_number(data[:card_number])
12
-
13
- # Validate CVV
14
- raise CustomException.new('Invalid CVV.') unless data[:cvv]&.match?(/^\d{3,4}$/)
15
-
16
- # Validate email
17
- raise CustomException.new('Invalid email.') unless HelperValidation.is_valid_email(data[:email])
18
-
19
- # Validate expiration month
20
- raise 'Invalid expiration month.' unless data[:expiration_month].to_s.match?(/^(0?[1-9]|1[012])$/)
21
-
22
- # Validate expiration year
23
- current_year = Date.today.year
24
- if !data[:expiration_year].to_s.match?(/^\d{4}$/) || data[:expiration_year].to_s.to_i < current_year
25
- raise 'Invalid expiration year.'
26
- end
27
-
28
- # Check if the card is expired
29
- exp_date = Date.strptime("#{data[:expiration_year]}-#{data[:expiration_month]}", '%Y-%m')
30
- raise 'Card has expired.' if exp_date < Date.today
31
- end
32
-
33
- def self.create_token_yape_validation(data)
34
- # Validate amount
35
- unless data[:amount].is_a?(Numeric) && data[:amount].to_i == data[:amount]
36
- raise CustomException.new('Invalid amount.')
37
- end
38
- end
39
-
40
- def self.list(data)
41
- if data.key?('device_type')
42
- allowed_device_values = ['desktop', 'mobile', 'tablet']
43
- HelperValidation.validate_value(data[:device_type], allowed_device_values)
44
- end
45
-
46
- if data.key?('card_brand')
47
- allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners']
48
- HelperValidation.validate_value(data[:card_brand], allowed_brand_values)
49
- end
50
-
51
- if data.key?('card_type')
52
- allowed_card_type_values = ['credito', 'debito', 'internacional']
53
- HelperValidation.validate_value(data[:card_type], allowed_card_type_values)
54
- end
55
-
56
- if data.key?('country_code')
57
- HelperValidation.validate_value(data[:country_code], get_country_codes)
58
- end
59
-
60
- if data.key?('creation_date_from') && data.key?('creation_date_to')
61
- HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
62
- end
63
- end
64
-
65
- end
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 TokenValidation
9
+ def self.create(data)
10
+ data = data.to_json
11
+ data = JSON.parse(data)
12
+
13
+ # Validate card number
14
+ raise CustomException.new('Invalid card number.') unless HelperValidation.is_valid_card_number(data['card_number'])
15
+
16
+ # Validate CVV
17
+ raise CustomException.new('Invalid CVV.') unless data['cvv']&.match?(/^\d{3,4}$/)
18
+
19
+ # Validate email
20
+ raise CustomException.new('Invalid email.') unless HelperValidation.is_valid_email(data['email'])
21
+
22
+ # Validate expiration month
23
+ raise 'Invalid expiration month.' unless data['expiration_month'].to_s.match?(/^(0?[1-9]|1[012])$/)
24
+
25
+ # Validate expiration year
26
+ current_year = Date.today.year
27
+ if !data['expiration_year'].to_s.match?(/^\d{4}$/) || data['expiration_year'].to_s.to_i < current_year
28
+ raise 'Invalid expiration year.'
29
+ end
30
+
31
+ # Check if the card is expired
32
+ exp_date = Date.strptime("#{data['expiration_year']}-#{data['expiration_month']}", '%Y-%m')
33
+ raise 'Card has expired.' if exp_date < Date.today
34
+ end
35
+
36
+ def self.create_token_yape_validation(data)
37
+ data = data.to_json
38
+ data = JSON.parse(data)
39
+ # Validate amount
40
+ unless data['amount'].is_a?(Numeric) && data['amount'].to_i == data['amount']
41
+ raise CustomException.new('Invalid amount.')
42
+ end
43
+ end
44
+
45
+ def self.list(data)
46
+ if data.key?('device_type')
47
+ allowed_device_values = ['desktop', 'mobile', 'tablet']
48
+ HelperValidation.validate_value(data[:device_type], allowed_device_values)
49
+ end
50
+
51
+ if data.key?('card_brand')
52
+ allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners']
53
+ HelperValidation.validate_value(data[:card_brand], allowed_brand_values)
54
+ end
55
+
56
+ if data.key?('card_type')
57
+ allowed_card_type_values = ['credito', 'debito', 'internacional']
58
+ HelperValidation.validate_value(data[:card_type], allowed_card_type_values)
59
+ end
60
+
61
+ if data.key?('country_code')
62
+ HelperValidation.validate_value(data[:country_code], get_country_codes)
63
+ end
64
+
65
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
66
+ HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
67
+ end
68
+ end
69
+
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: culqi-ruby-oficial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Culqi Team
@@ -19,7 +19,6 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - lib/CulqiCRUD.rb
23
22
  - lib/culqi-ruby.rb
24
23
  - lib/culqi/card.rb
25
24
  - lib/culqi/charge.rb
@@ -40,7 +39,6 @@ files:
40
39
  - lib/operation/list.rb
41
40
  - lib/operation/post.rb
42
41
  - lib/operation/update.rb
43
- - lib/test_list.rb
44
42
  - lib/util/connect.rb
45
43
  - lib/util/country-codes.rb
46
44
  - lib/util/encrypt-data.rb