TodoPagoConectorSS 1.8.0 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +34 -0
  3. data/.gitignore +37 -0
  4. data/README.md +1553 -0
  5. data/TodoPago/DataProvider.rb +273 -0
  6. data/TodoPago/DiscoverPaymentMethodsTest.rb +71 -0
  7. data/TodoPago/GetAuthorizeAnswerTest.rb +61 -0
  8. data/TodoPago/GetCredentialsTest.rb +70 -0
  9. data/TodoPago/GetOperationsTest.rb +72 -0
  10. data/TodoPago/MockClient.rb +195 -0
  11. data/TodoPago/ReturnRequestTest.rb +64 -0
  12. data/TodoPago/SendAuthorizeRequestTest.rb +63 -0
  13. data/TodoPago/coverage/.last_run.json +5 -0
  14. data/TodoPago/coverage/.resultset.json +892 -0
  15. data/TodoPago/coverage/.resultset.json.lock +0 -0
  16. data/TodoPago/coverage/assets/0.10.0/application.css +799 -0
  17. data/TodoPago/coverage/assets/0.10.0/application.js +1707 -0
  18. data/TodoPago/coverage/assets/0.10.0/colorbox/border.png +0 -0
  19. data/TodoPago/coverage/assets/0.10.0/colorbox/controls.png +0 -0
  20. data/TodoPago/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
  21. data/TodoPago/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
  22. data/TodoPago/coverage/assets/0.10.0/favicon_green.png +0 -0
  23. data/TodoPago/coverage/assets/0.10.0/favicon_red.png +0 -0
  24. data/TodoPago/coverage/assets/0.10.0/favicon_yellow.png +0 -0
  25. data/TodoPago/coverage/assets/0.10.0/loading.gif +0 -0
  26. data/TodoPago/coverage/assets/0.10.0/magnify.png +0 -0
  27. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  28. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  29. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  30. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  31. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  32. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  33. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  34. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  35. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  36. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  37. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  38. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  39. data/TodoPago/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  40. data/TodoPago/coverage/index.html +5510 -0
  41. data/TodoPago/test.rb +203 -0
  42. data/TodoPago/test_validations.rb +108 -0
  43. data/TodoPago/tests_coverage.rb +11 -0
  44. data/TodoPagoConector.gemspec +14 -0
  45. data/lib/Authorize.wsdl +320 -0
  46. data/lib/Classes/user.rb +30 -0
  47. data/lib/Connectors/RestConnector.rb +65 -0
  48. data/lib/Connectors/ServiceConnector.rb +32 -0
  49. data/lib/Connectors/SoapConnector.rb +139 -0
  50. data/lib/Exceptions/connection_exception.rb +6 -0
  51. data/lib/Exceptions/empty_field_exception.rb +6 -0
  52. data/lib/Exceptions/empty_field_password_exception.rb +8 -0
  53. data/lib/Exceptions/empty_field_user_exception.rb +8 -0
  54. data/lib/Exceptions/prueba.rb +5 -0
  55. data/lib/Exceptions/response_exception.rb +6 -0
  56. data/lib/FraudControlValidation.rb +406 -0
  57. data/lib/Operations.wsdl +319 -0
  58. data/lib/ServiceReferences/Authorize.wsdl +320 -0
  59. data/lib/ServiceReferences/EchoService.wsdl +125 -0
  60. data/lib/ServiceReferences/Operations.wsdl +319 -0
  61. data/lib/Validation/FraudControlValidation.rb +406 -0
  62. data/lib/config/postalCodes.json +26 -0
  63. data/lib/config/validations.json +623 -0
  64. data/lib/prueba.rb +4 -0
  65. data/lib/user.rb +41 -0
  66. metadata +65 -1
@@ -0,0 +1,30 @@
1
+ #encoding: utf-8
2
+ require_relative "../Exceptions/empty_field_user_exception"
3
+ require_relative "../Exceptions/empty_field_password_exception"
4
+
5
+ class User
6
+
7
+ attr_accessor :merchant, :apiKey
8
+ attr_reader :user, :password
9
+
10
+ def initialize(user=nil, password=nil)
11
+ @user= user
12
+ @password= password
13
+ end
14
+
15
+ def getData
16
+ if(@user==nil)
17
+ raise EmptyFieldUserException.new
18
+ end
19
+
20
+ if (@password==nil)
21
+ raise EmptyFieldPasswordException.new
22
+ end
23
+
24
+ data = {:USUARIO=>@user, :CLAVE=>@password}
25
+
26
+ return data
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,65 @@
1
+ #encoding: utf-8
2
+ require 'rest-client'
3
+ require 'json'
4
+
5
+ require_relative "ServiceConnector"
6
+
7
+ class RestConnector < ServiceConnector
8
+
9
+ def initialize(j_header_http, j_wsdl, endpoint, env)
10
+ super(j_header_http, j_wsdl, endpoint, env)
11
+
12
+ # atributos
13
+ @restEndPoint = @endPoint + $tenant + $restAppend
14
+ @credentialsEndPoint = @endPoint + $restAppend
15
+ end
16
+
17
+ def discoverPaymentMethods()
18
+ url = @restEndPoint + 'PaymentMethods/Discover'
19
+ resource = RestClient::Resource.new(url, :verify_ssl => false)
20
+ xml = resource.get(:Authorization => @j_header_http['Authorization'])
21
+
22
+ return xml
23
+ end
24
+
25
+ def getCredentials(user)
26
+ url = @credentialsEndPoint + "Credentials"
27
+ response = RestClient.post url, user.getData.to_json, :content_type => :json
28
+ response = JSON.parse(response)
29
+
30
+ if response['Credentials']['resultado']['codigoResultado'] != 0
31
+ raise ResponseException.new, response
32
+ end
33
+
34
+ user.merchant = response['Credentials']['merchantId']
35
+ user.apiKey = response['Credentials']['APIKey']
36
+
37
+ return user
38
+ end
39
+
40
+ def getOperations(optionsOperations)
41
+ url = @restEndPoint + 'Operations/GetByOperationId/MERCHANT/' + optionsOperations[:MERCHANT] + '/OPERATIONID/' + optionsOperations[:OPERATIONID]
42
+
43
+ resource = RestClient::Resource.new(url, :verify_ssl => false)
44
+ xml = resource.get( :Authorization => @j_header_http['Authorization'] )
45
+
46
+ return xml
47
+ end
48
+
49
+ def getAllPaymentMethods(optionsPaymentMethod)
50
+ url = @restEndPoint + 'PaymentMethods/Get/MERCHANT/' + optionsPaymentMethod[:MERCHANT]
51
+
52
+ resource = RestClient::Resource.new(url, :verify_ssl => false)
53
+ xml = resource.get( :Authorization => @j_header_http['Authorization'] )
54
+
55
+ return xml
56
+ end
57
+
58
+ def getByRangeDateTime(optionsGetByRange)
59
+ url = @restEndPoint +"Operations/GetByRangeDateTime/MERCHANT/#{optionsGetByRange[:Merchant]}/STARTDATE/#{optionsGetByRange[:STARTDATE]}/ENDDATE/#{optionsGetByRange[:ENDDATE]}/PAGENUMBER/#{optionsGetByRange[:PAGENUMBER]}"
60
+ response = RestClient.get url
61
+
62
+ return response
63
+ end
64
+ end
65
+
@@ -0,0 +1,32 @@
1
+ #encoding: utf-8
2
+
3
+ $tenant = 't/1.1/'
4
+ $soapAppend = 'services/'
5
+ $restAppend = 'api/'
6
+
7
+ class ServiceConnector
8
+ def initialize(j_header_http, j_wsdl, endpoint, env)#j_wsdl=nil, endpoint=nil, env=nil
9
+ # if args.length == 2
10
+
11
+ # j_wsdls = args[0]
12
+ # endpoint = args[1]
13
+
14
+ # else args.length == 1
15
+
16
+ # j_wsdls = { 'Operations'=> '../lib/ServiceReferences/Operations.wsdl', 'Authorize'=> '../lib/ServiceReferences/Authorize.wsdl',
17
+ # 'EchoService'=> '../lib/ServiceReferences/EchoService.wsdl' }
18
+ # if args[0] == "prod"
19
+ # endpoint = 'https://apis.todopago.com.ar/'
20
+ # else
21
+ # endpoint = 'https://developers.todopago.com.ar/'
22
+ # #endpoint = 'http://127.0.0.1:8280/'
23
+ # end
24
+
25
+ # end
26
+
27
+ # atributos
28
+ @j_header_http = j_header_http
29
+ @j_wsdls = j_wsdl
30
+ @endPoint = endpoint
31
+ end
32
+ end
@@ -0,0 +1,139 @@
1
+ #encoding: utf-8
2
+ require 'savon'
3
+ require 'json'
4
+
5
+ require_relative "ServiceConnector"
6
+
7
+ class SoapConnector < ServiceConnector
8
+
9
+ def initialize(j_header_http, j_wsdl, endpoint, env)
10
+ super(j_header_http, j_wsdl, endpoint, env)
11
+ end
12
+
13
+ def sendAuthorizeRequest(options_commerce, optionsAuthorize)
14
+ result = ""
15
+ begin
16
+ message = {Security: options_commerce[:SECURITY],
17
+ MERCHANT: options_commerce[:MERCHANT],
18
+ EncodingMethod: options_commerce[:ENCODINGMETHOD],
19
+ URL_OK: options_commerce[:URL_OK],
20
+ URL_ERROR: options_commerce[:URL_ERROR],
21
+ #MAILCLIENTE: options_commerce[:EMAILCLIENTE],
22
+ #Session: options_commerce[:SESSION],
23
+ Payload: SoapConnector.buildPayload(optionsAuthorize)}
24
+
25
+ client = getClientSoap(@j_wsdls['Authorize'], $tenant + 'Authorize')
26
+
27
+ response = client.call(:send_authorize_request, message: message)
28
+
29
+ resp = response.hash
30
+
31
+ result = resp.to_json
32
+ rescue Exception=>e
33
+ e.message
34
+ result = e.message.to_json
35
+ end
36
+
37
+ return result
38
+ end
39
+
40
+ def getAuthorizeAnswer(optionsAnwser)
41
+ message = {Security: optionsAnwser[:security],
42
+ Merchant: optionsAnwser[:MERCHANT],
43
+ RequestKey: optionsAnwser[:RequestKey],
44
+ AnswerKey: optionsAnwser[:AnswerKey]};
45
+
46
+ client = getClientSoap(@j_wsdls['Authorize'], $tenant + 'Authorize')
47
+ response= client.call(:get_authorize_answer, message:message)
48
+ resp = response.hash
49
+ return resp.to_json
50
+ end
51
+
52
+ def voidRequest(refoundOptions)
53
+ message = {
54
+ Security: refoundOptions[:Security],
55
+ Merchant: refoundOptions[:Merchant],
56
+ RequestKey: refoundOptions[:RequestKey],
57
+ }
58
+
59
+ client = getClientSoap(@j_wsdls['Authorize'], $tenant + 'Authorize')
60
+ response= client.call(:void_request, message:message)
61
+ resp = response.hash
62
+
63
+ return resp.to_json
64
+ end
65
+
66
+ def returnRequest(refoundOptions)
67
+ message = {
68
+ Security: refoundOptions[:Security],
69
+ Merchant: refoundOptions[:Merchant],
70
+ RequestKey: refoundOptions[:RequestKey],
71
+ AMOUNT: refoundOptions[:AMOUNT]
72
+ }
73
+
74
+ client = getClientSoap(@j_wsdls['Authorize'], $tenant + 'Authorize')
75
+ response= client.call(:return_request, message:message)
76
+ resp = response.hash
77
+
78
+ return resp.to_json
79
+ end
80
+
81
+ def echoService(serviceName)
82
+ random = Array.new(15){[*"A".."Z", *"0".."9"].sample}.join
83
+ message = { message: random }
84
+ result = false
85
+
86
+ begin
87
+ client = getClientSoapEcho(@j_wsdls['EchoService'], serviceName)
88
+ response = client.call(:echo_operation, message:message)
89
+ resp = response.hash
90
+ result = resp.to_json.include? random
91
+ rescue Exception => msg
92
+
93
+ end
94
+
95
+ return result
96
+ end
97
+
98
+ def self.buildPayload(optionAuthorize)
99
+
100
+ # optionAuthorize[:SDK] = "Ruby"
101
+ # optionAuthorize[:SDKVERSION] = $versionTodoPago
102
+ # optionAuthorize[:LENGUAGEVERSION] = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
103
+
104
+ @xml = "<Request>"
105
+ optionAuthorize.each do |item|
106
+ @xml = @xml.concat("<").concat(item[0].to_s).concat(">")
107
+
108
+ #crop values
109
+ aux = if item[1].size > 254 then
110
+ item[1].slice(0, 253)
111
+ else
112
+ item[1]
113
+ end
114
+
115
+ @xml = @xml.concat(aux)
116
+ @xml = @xml.concat("</").concat(item[0].to_s).concat(">")
117
+ end
118
+
119
+ @xml = @xml.concat("</Request>");
120
+
121
+ return @xml;
122
+ end
123
+
124
+ ###########################################################################################
125
+ #Metodo de clase que crea cliente que accede al servicio a través de SOAP utilizando savon
126
+ ###########################################################################################
127
+ private
128
+ def getClientSoap(wsdlService, sufijoEndpoint)
129
+ return Savon.client(
130
+ headers:@j_header_http,
131
+ wsdl: wsdlService,
132
+ endpoint: @endPoint + $soapAppend + sufijoEndpoint,
133
+ log: false,
134
+ log_level: :debug,
135
+ ssl_verify_mode: :none,
136
+ convert_request_keys_to: :none)
137
+ end
138
+ end
139
+
@@ -0,0 +1,6 @@
1
+ #encoding: utf-8
2
+ class ConnectionException < Exception
3
+ def initialize(data="ConnectionException(error en la conexi&oacute;n)")
4
+ super(data)
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ #encoding: utf-8
2
+ class EmptyFieldException < Exception
3
+ def initialize(data="EmptyFieldException(alg&uacute;n campo incompleto)")
4
+ super(data)
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ #encoding: utf-8
2
+ require_relative "empty_field_exception.rb"
3
+
4
+ class EmptyFielPasswordException < EmptyFieldException
5
+ def initialize(data="EmptyFieldPasswordException(falta parametro password)")
6
+ super(data)
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ #encoding: utf-8
2
+ require_relative "empty_field_exception.rb"
3
+
4
+ class EmptyFieldUserException < EmptyFieldException
5
+ def initialize(data="EmptyFieldUserException(falta parametro user)")
6
+ super(data)
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ #encoding: utf-8
2
+ require_relative "empty_field_exception.rb"
3
+
4
+
5
+ raise EmptyFieldException.new
@@ -0,0 +1,6 @@
1
+ #encoding: utf-8
2
+ class ResponseException < Exception
3
+ def initialize(data="ResponseException(error en la respuesta)")
4
+ super(data)
5
+ end
6
+ end
@@ -0,0 +1,406 @@
1
+ #encoding: utf-8
2
+ require "json"
3
+
4
+ CONST_CSITPRODUCTDESCRIPTION = 'CSITPRODUCTDESCRIPTION'
5
+ CSBTSTATE = "CSBTSTATE"
6
+ NUMERAL = "#"
7
+ FIELD = "field"
8
+ VALIDATE = "validate"
9
+ FORMAT = "format"
10
+ FUNCTION = "function"
11
+ MESSAGE = "message"
12
+ PARAMS = "params"
13
+ DEFAULT = "default"
14
+ MIN_LENGTH = 20
15
+ MAX_CHARS = 254
16
+ URL_VALIDATION_JSON = "../lib/config/validations.json"
17
+ URL_POSTALCODES_JSON = "../lib/config/postalCodes.json"
18
+ #########################################
19
+ # => Validation Class for Fraud Control
20
+ ###########################################
21
+ class FraudControlValidation
22
+ # @url = "../validations.json"
23
+ # @file = File.read(@url)
24
+ # @data_hash = JSON.parse(file)
25
+
26
+ attr_accessor :data_hash , :postalcodes_hash, :csit_hash, :campError, :parameters
27
+
28
+ def initialize()
29
+
30
+ file_validations = File.read(URL_VALIDATION_JSON)
31
+ @data_hash = JSON.parse(file_validations)
32
+
33
+ file_postalcodes = File.read(URL_POSTALCODES_JSON)
34
+ @postalcodes_hash = JSON.parse(file_postalcodes)
35
+
36
+ @csit_hash = Hash.new
37
+ @campError = Hash.new
38
+ @parameters = Hash.new
39
+ end
40
+ ############################################################
41
+ # => @boolean: notEmpty => true , empty => false
42
+ ############################################################
43
+ def notEmpty(str)
44
+ strResult = str.strip
45
+ return ( strResult.length > 0 )? true:false
46
+ end
47
+ ############################################################
48
+ # => @string: clean special chars
49
+ ############################################################
50
+ def clean(str)
51
+ return str.gsub(/([.*+?^${}()|\[\]\/\\])/, '')
52
+ end
53
+ ############################################################
54
+ # => @string: truncate string to @max characters
55
+ ############################################################
56
+ def truncate(str, max)
57
+ lim = 0.. + max.to_i
58
+ return str[lim]
59
+ end
60
+ ############################################################
61
+ # => Hardcode value to set
62
+ ############################################################
63
+ def hardcode(strHardCode)
64
+ return strHardCode
65
+ end
66
+ ############################################################
67
+ # => Generate random ID
68
+ ############################################################
69
+ def random()
70
+ return (0...8).map { (1 + rand(9)) }.join
71
+ end
72
+ ############################################################
73
+ # => Validate with regular Expression
74
+ ############################################################
75
+ def regex? (str, regExp)
76
+ ( str =~ '/\A('+ regExp + ')\Z/is' )==0
77
+ end
78
+
79
+ def email? (str)
80
+ (str =~ /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z])+$/)==0
81
+ end
82
+
83
+ def ip? (str)
84
+ (str =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/)==0
85
+ end
86
+
87
+ def totalAmount? (str)
88
+ (str =~ /^([0-9]{0,12}).([0-9]{0,2})$/)==0
89
+ end
90
+
91
+ def isBoolean? (str)
92
+ (str =~ /^[YySsNn]$/)==0
93
+ end
94
+
95
+ def phone? (str)
96
+ (str =~ /[0-9]/)==0
97
+ end
98
+
99
+ def word? (str)
100
+ (str =~ /[\w]/)==0
101
+ end
102
+
103
+ def upper (str)
104
+ return str.upcase
105
+ end
106
+
107
+ def phoneSanitize ( phoneNumber )
108
+ phoneNumber = phoneNumber.gsub(' ', '')
109
+ phoneNumber = phoneNumber.gsub(/([+()-])/,'')
110
+
111
+ if ( phoneNumber[0..1] == "54")
112
+ return phoneNumber
113
+ end
114
+ if ( phoneNumber[0..1] == "15")
115
+ phoneNumber = phoneNumber[2, phoneNumber.length]
116
+ end
117
+ if ( phoneNumber.length == 8 )
118
+ return "5411" + phoneNumber
119
+ end
120
+ if (phoneNumber[0] == "0" )
121
+ return "54" + phoneNumber[1, phoneNumber.length]
122
+ end
123
+ return "54" + phoneNumber
124
+ end
125
+
126
+ def findState ( field, strState )
127
+ s = 'C'
128
+ if (strState && (strState.strip != ''))
129
+ s = strState[0]
130
+ elsif (!@parameters['CSBTSTATE'][0].nil? && (@parameters['CSBTSTATE'][0].strip != '') )
131
+ s = @parameters['CSBTSTATE'][0]
132
+ end
133
+ s = s.upcase
134
+
135
+ return @postalcodes_hash[s]
136
+ end
137
+
138
+ ############################################################
139
+ # => Load csi Values into csiHash
140
+ ############################################################
141
+ def loadCsit (field , value)
142
+ @csit_hash[field] = value
143
+ return value
144
+ end
145
+
146
+ ###########################################################################
147
+ # => Min chars of ProductDescription = 20
148
+ # => If length > size , ommit lastest elements until adjust to given size
149
+ ###########################################################################
150
+ def cutDescription(values, size)
151
+ result = ''
152
+ arrayValues = Hash.new
153
+ arrayValues = values.split(NUMERAL)
154
+ aux = ''
155
+ count = arrayValues.length
156
+ x = (size / count) - 1
157
+
158
+ if (x >= 20)
159
+ arrayValues.each do |value|
160
+ aux = truncate(value.strip, x) + NUMERAL
161
+ result = result + aux
162
+ end
163
+ else
164
+ cantProduct = (size / 21)-1
165
+ for i in(0..cantProduct)
166
+ aux = truncate(arrayValues[i].strip, (MIN_LENGTH - 1)) + NUMERAL
167
+ result = result + aux
168
+ end
169
+ end
170
+
171
+ result = result[0, result.length - 1]
172
+
173
+ return result
174
+ end
175
+
176
+ def genericCutCsit(values, cant)
177
+ result = ""
178
+ arrayValues = values.split(NUMERAL)
179
+ aux = ''
180
+
181
+ for i in(0..arrayValues.length)
182
+ if (i < cant)
183
+ aux = truncate(arrayValues[i].strip, (MIN_LENGTH - 1) ) + NUMERAL
184
+ result = result + aux
185
+ end
186
+ end
187
+
188
+ result = result[0, result.length - 1]
189
+
190
+ return result
191
+ end
192
+
193
+ def addError(field, message)
194
+
195
+ if(self.campError[field].nil?)
196
+ self.campError[field] = ' * ' + message
197
+ else
198
+ self.campError[field] = self.campError[field] + ' * ' + message
199
+ end
200
+ end
201
+
202
+ ############################################################
203
+ # => Format csi Values into csiHash
204
+ ############################################################
205
+ def csitFormat(size)
206
+ mapResult = Hash.new
207
+ value = nil
208
+ sizeDescription = 0
209
+
210
+ if (!@csit_hash[CONST_CSITPRODUCTDESCRIPTION].nil?)
211
+
212
+ value = @csit_hash[CONST_CSITPRODUCTDESCRIPTION]
213
+ value = cutDescription(value, size)
214
+
215
+ aux = value.split(NUMERAL)
216
+ sizeDescription = aux.length
217
+
218
+ @csit_hash.each do |key , val|
219
+ mapResult[key] = genericCutCsit(val, sizeDescription)
220
+ end
221
+ else
222
+ addError(CONST_CSITPRODUCTDESCRIPTION , 'CSIT Product description está vacio')
223
+ end
224
+
225
+ return mapResult
226
+ end
227
+ ############################################################
228
+ # => main validation process
229
+ ############################################################
230
+ def validate (parameters)
231
+ @parameters = parameters
232
+ resultMap = Hash.new
233
+ begin
234
+ parameters.each do |field , value|
235
+ resultMap[field]= self.validateAndFormat(field , value)
236
+ end
237
+ # csitformat elements from @csit_hash
238
+ csitResult = csitFormat(254)
239
+ csitResult.each do |field , value|
240
+ resultMap[field]= value
241
+ end
242
+ return resultMap
243
+ rescue Exception=>e
244
+ e.message
245
+ end
246
+
247
+ end
248
+ ###
249
+ # => get validate item from field
250
+ ###
251
+ def getValidateItem(field)
252
+ item = nil
253
+ @data_hash.each do |value|
254
+ if (value['field']==field)
255
+ item = value
256
+ break
257
+ end
258
+ end
259
+ return item
260
+ end
261
+ ############################################################
262
+ # => Validation and format process for each field
263
+ ############################################################
264
+ def validateAndFormat(field , value)
265
+
266
+ item = getValidateItem(field)
267
+
268
+ # VALIDATE Value
269
+ if (!item['validate'].nil? )
270
+ item['validate'].each do |elem|
271
+ paramsValidate = Hash.new
272
+ paramsValidate['str'] = value
273
+ paramsValidate['field'] = field
274
+
275
+ if (!elem['params'].nil? )
276
+ paramsValidate['parameters'] = elem['params']
277
+ end
278
+
279
+ result = self.executeFunction(elem['function'], paramsValidate )
280
+
281
+ # if is empty and required
282
+ if (!result && (elem['function'] == 'notEmpty') )
283
+ if(item['required'])
284
+ if (!elem['default'].nil? )
285
+ value = self.executeFunction(elem['default'], paramsValidate )
286
+ elsif (!elem['message'].nil? )
287
+
288
+ addError(field, elem['message'])
289
+ else
290
+ addError(field, 'El valor de este campo esta vacio o es invalido')
291
+ end
292
+ end
293
+ elsif (!result && (elem['function'] != 'notEmpty') )
294
+ if(item['required'])
295
+ if (!elem['default'].nil? )
296
+ value = self.executeFunction(elem['default'], paramsValidate )
297
+ elsif (!elem['message'].nil? )
298
+ # 'notify field error'
299
+ addError(field, elem['message'])
300
+ else
301
+ addError(field, 'El valor de este campo esta vacio o es invalido')
302
+ end
303
+ end
304
+ end
305
+
306
+ end
307
+ end
308
+
309
+
310
+ # FORMAT Value
311
+ if (!item['format'].nil? )
312
+
313
+ item['format'].each do |elem|
314
+
315
+ paramsFormat = Hash.new
316
+ paramsFormat['str'] = value
317
+ if (!elem['params'].nil? )
318
+ paramsFormat['parameters'] = elem['params']
319
+ end
320
+ if (elem['function'] == 'csitFormat')
321
+ paramsFormat['field'] = field
322
+ end
323
+
324
+ value = self.executeFunction(elem['function'], paramsFormat)
325
+
326
+ if (!elem['default'].nil? )
327
+ value = self.executeFunction(elem['default'], paramsFormat )
328
+ elsif (!elem['message'].nil? )
329
+ # notify field error
330
+ addError(field, elem['message'])
331
+ end
332
+
333
+ end
334
+
335
+ end
336
+
337
+ return value
338
+
339
+ end
340
+ ############################################################
341
+ # => Execute @functionName with @params and return result
342
+ ############################################################
343
+ def executeFunction(functionName, params)
344
+ case functionName
345
+ when 'notEmpty'
346
+ return self.notEmpty(params['str'])
347
+ when 'clean'
348
+ return self.clean(params['str'])
349
+ when 'truncate'
350
+ return self.truncate(params['str'], params['parameters'][0])
351
+ when 'hardcode'
352
+ return self.hardcode(params['parameters'][0])
353
+ when 'random'
354
+ return self.random()
355
+ when 'regex'
356
+ #puts params['parameters'][0]
357
+ return self.regex? params['str'], params['parameters'][0]
358
+ when 'email'
359
+ #puts params['parameters'][0]
360
+ return self.email? params['str'].strip
361
+ when 'ip'
362
+ #puts params['parameters'][0]
363
+ return self.ip? params['str'].strip
364
+ when 'totalAmount'
365
+ #puts params['parameters'][0]
366
+ return self.totalAmount? params['str'].strip
367
+ when 'boolean'
368
+ #puts params['parameters'][0]
369
+ return self.isBoolean? params['str'].strip
370
+ when 'phone'
371
+ #puts params['parameters'][0]
372
+ return self.phone? params['str']
373
+ when 'phoneSanitize'
374
+ #puts params['parameters'][0]
375
+ return self.phoneSanitize( params['str'] )
376
+ when 'word'
377
+ return self.word? params['str'].strip
378
+ when 'upper'
379
+ return self.upper( params['str'] )
380
+ when 'findState'
381
+ return self.findState( params['field'], params['str'] )
382
+ when 'csitFormat'
383
+ return loadCsit( params['field'], params['str'])
384
+ when 'N'
385
+ return self.hardcode("N")
386
+ when 'C'
387
+ return self.hardcode("C")
388
+ else
389
+ addError(functionName, 'no se encontro implementacion para este método ')
390
+ return false
391
+ end
392
+ end
393
+
394
+ end
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+