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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/util/validation/charge.rb', line 42
def self.list(data)
if data.key?('email')
unless Helpers.is_valid_email(data[:email])
raise CustomException.new('Invalid email.')
end
end
if data.key?('amount')
amount = data[:amount]
if amount.is_a?(String)
begin
amount = Integer(amount)
rescue ArgumentError
raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
end
end
unless amount.is_a?(Integer)
raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
end
end
if data.key?('min_amount')
unless data[:min_amount].is_a?(Integer)
raise CustomException.new('Invalid min amount.')
end
end
if data.key?('max_amount')
unless data[:max_amount].is_a?(Integer)
raise CustomException.new('Invalid max amount.')
end
end
if data.key?('installments')
unless data[:installments].is_a?(Integer)
raise CustomException.new('Invalid installments.')
end
end
if data.key?('min_installments')
unless data[:min_installments].is_a?(Integer)
raise CustomException.new('Invalid min installments.')
end
end
if data.key?('max_installments')
unless data[:max_installments].is_a?(Integer)
raise CustomException.new('Invalid max installments.')
end
end
if data.key?('currency_code')
Helpers.validate_currency_code(data[:currency_code])
end
if data.key?('card_brand')
allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners']
Helpers.validate_value(data[:card_brand], allowed_brand_values)
end
if data.key?('card_type')
allowed_card_type_values = ['credito', 'debito', 'internacional']
Helpers.validate_value(data[:card_type], allowed_card_type_values)
end
if data.key?('creation_date_from') && data.key?('creation_date_to')
Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
end
if data.key?('country_code')
Helpers.validate_value(data[:country_code], get_country_codes)
end
end
|