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.
- checksums.yaml +4 -4
- data/lib/culqi/card.rb +16 -16
- data/lib/culqi/charge.rb +20 -20
- data/lib/culqi/customer.rb +17 -17
- data/lib/culqi/event.rb +14 -14
- data/lib/culqi/iins.rb +14 -14
- data/lib/culqi/order.rb +18 -18
- data/lib/culqi/plan.rb +16 -16
- data/lib/culqi/refund.rb +15 -15
- data/lib/culqi/subscription.rb +16 -16
- data/lib/culqi/token.rb +37 -37
- data/lib/culqi/transfer.rb +14 -14
- data/lib/culqi/version.rb +3 -3
- data/lib/culqi/yape.rb +13 -13
- data/lib/culqi-ruby.rb +38 -38
- data/lib/operation/confirm_type.rb +24 -24
- data/lib/operation/delete.rb +19 -19
- data/lib/operation/get.rb +57 -57
- data/lib/operation/list.rb +64 -64
- data/lib/operation/post.rb +85 -79
- data/lib/operation/update.rb +22 -22
- data/lib/util/connect.rb +54 -54
- data/lib/util/country-codes.rb +21 -21
- data/lib/util/encrypt-data.rb +49 -49
- data/lib/util/validation/card.rb +38 -36
- data/lib/util/validation/charge.rb +131 -129
- data/lib/util/validation/customer.rb +41 -39
- data/lib/util/validation/error.rb +17 -17
- data/lib/util/validation/helper.rb +40 -40
- data/lib/util/validation/order.rb +78 -76
- data/lib/util/validation/plan.rb +71 -69
- data/lib/util/validation/refund.rb +47 -45
- data/lib/util/validation/subscription.rb +26 -24
- data/lib/util/validation/token.rb +70 -65
- metadata +1 -3
- data/lib/CulqiCRUD.rb +0 -344
- data/lib/test_list.rb +0 -37
@@ -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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
raise CustomException.new('
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
data/lib/util/validation/plan.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# Validate
|
14
|
-
raise CustomException.new('Invalid
|
15
|
-
|
16
|
-
# Validate
|
17
|
-
raise CustomException.new('Invalid
|
18
|
-
|
19
|
-
# Validate
|
20
|
-
raise 'Invalid
|
21
|
-
|
22
|
-
# Validate expiration
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
if data.key?('
|
47
|
-
|
48
|
-
HelperValidation.validate_value(data[:
|
49
|
-
end
|
50
|
-
|
51
|
-
if data.key?('
|
52
|
-
|
53
|
-
HelperValidation.validate_value(data[:
|
54
|
-
end
|
55
|
-
|
56
|
-
if data.key?('
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
+
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
|