risepay 1.0.1 → 1.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/risepays.rb +77 -48
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76988fde3c1e69422437dde47722dd4a874e9a37
4
- data.tar.gz: e53ff682dd8c3d8009ad98e902e1171ab04d60c7
3
+ metadata.gz: c64f6ac0e7c2b686ec830e8b0a7219d922bf696d
4
+ data.tar.gz: 207c02aecb0d4b5c74880e245b51ec8a7c9d9907
5
5
  SHA512:
6
- metadata.gz: 10c295c530b87ebefccc652496fc63ab8bfd246ee1432f8bebd2ac8b323ee723a4a5842bf790fc1a3e7ed251465abe99639786a7c16cda49422fb88615b74613
7
- data.tar.gz: db66d76411619b958ebb407f4fd0f79fded908253770451a5c199df73f06d3f07df064965af320db29ffdad0de38fe45dfa15e10c4b0afe789c3bc18fed75900
6
+ metadata.gz: cac45e0a0ef2996ae38266176e30fedf9c8673bbc56b6e7ff27613e42e7d0e156b6ee5c9491898ba91da6505d9b7ca741c103c11a096d58004d0b9db3ca06d0a
7
+ data.tar.gz: c81576a3169cf55fc64791de8829bc5728c9620328a9535399476b51608acf481aee03782967cb826e209dd747e72d687bb64fc1ae9f23c250c513737148a04e
data/lib/risepays.rb CHANGED
@@ -29,7 +29,7 @@ require 'active_support'
29
29
 
30
30
  class Risepays
31
31
 
32
- attr_accessor :UserName, :Password, :url, :defFileds, :info, :RespMSG, :formData
32
+ attr_accessor :UserName, :Password, :url, :defFileds, :info, :RespMSG, :formData, :resp
33
33
 
34
34
 
35
35
  def initialize(user,pass)
@@ -41,7 +41,7 @@ class Risepays
41
41
  @formData = [];
42
42
  @url ="https://gateway1.risepay.com/ws/transact.asmx/ProcessCreditCard"
43
43
  @amountFields = ['Amount', 'TipAmt', 'TaxAmt'];
44
-
44
+ @resp = ''
45
45
 
46
46
  end
47
47
 
@@ -130,6 +130,10 @@ class Risepays
130
130
 
131
131
  end
132
132
 
133
+ def stringStartsWith(haystack, needle)
134
+ return haystack.index(needle) === 0
135
+ end
136
+
133
137
  def prepare()
134
138
 
135
139
  @data = {};
@@ -170,66 +174,91 @@ class Risepays
170
174
 
171
175
  def convert_response(obj)
172
176
 
173
- #ConvertExtData
174
- #Split plain data and XML into @matches hash
175
- s = obj['ExtData']
176
- s = s.match(/([,=0-9a-zA-Z]*)(\<.*\>)?/)
177
- @str = s[1]
178
- @str2 = s[2]
179
-
180
-
181
- @str.split(",").each do |f|
182
- arr = f.split('=');
183
- arr[1] && (obj[arr[0]] = arr[1])
184
- end
185
-
186
- #Process XML Part
177
+ @resp = obj
178
+ @resp['Approved'] = false
179
+
180
+ #Add Approved Value
181
+ if(@resp['Result'] == "0")
182
+ @resp['Approved']= true
183
+
184
+ #ConvertExtData
185
+ #Split plain data and XML into @matches hash
186
+ matches = @resp['ExtData']
187
+ matches = matches.match(/([,=0-9a-zA-Z]*)(\<.*\>)?/)
188
+ @str = matches[1]
189
+
190
+ #Process plain text coma separated keypairs
191
+ @str.split(",").each do |f|
192
+ arr = f.split('=');
193
+ arr[1] && (@resp[arr[0]] = arr[1])
194
+ end
187
195
 
188
- @xmldata = Hash.from_xml(@str2)
196
+ #Process XML Part
197
+ if(matches.length == 2)
198
+ @xmldata = Hash.from_xml(matches[2])
199
+
200
+
201
+ if @xmldata
202
+ for x in @xmldata
203
+ @resp[x] = @xmldata[x]
204
+ end
205
+ end
206
+ end
189
207
 
190
-
191
- if @xmldata
192
- for x in @xmldata
193
- obj[x] = @xmldata[x]
194
- end
195
208
  end
196
-
197
209
  @jsonlist = ['xmlns:xsd', 'xmlns:xsi', 'xmlns', 'ExtData']
198
210
 
199
211
  @jsonlist.each do |j|
200
- obj.delete(j)
212
+ @resp.delete(j)
201
213
 
202
214
  end
203
215
 
204
- return obj
205
- end
206
216
 
217
+ if(!@resp['Message'])
218
+ @resp['Message'] = "";
219
+ end
207
220
 
208
- def post(opts)
209
-
210
- uri = URI.parse(@url)
211
-
212
- http = Net::HTTP.new(uri.host, uri.port)
213
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
214
- http.use_ssl = (uri.scheme == "https")
215
- request = Net::HTTP::Post.new(uri.request_uri)
216
-
217
- request.set_form_data(opts);
218
-
219
- response = http.request(request)
220
- xml= response.body
221
- session = Hash.from_xml(xml)
222
- res = session['Response']
223
- json = convert_response(res);
221
+ if(@resp['RespMSG'])
222
+ @resp['Message'] = @resp['Message'] + " " + @resp['RespMSG'];
223
+ end
224
+
225
+ return @resp
226
+ end
224
227
 
225
- approved = false
226
- if(json['Result'] == "0")
227
- approved = true;
228
228
 
229
- end
230
- json['Approved']=approved
231
- return json
229
+ def post(opts)
232
230
 
231
+ begin
232
+
233
+ uri = URI.parse(@url)
234
+
235
+ http = Net::HTTP.new(uri.host, uri.port)
236
+ http.read_timeout = 120
237
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
238
+ http.use_ssl = (uri.scheme == "https")
239
+ request = Net::HTTP::Post.new(uri.request_uri)
240
+
241
+ request.set_form_data(opts);
242
+
243
+ response = http.request(request)
244
+ xml= response.body
245
+ session = Hash.from_xml(xml)
246
+ res = session['Response']
247
+
248
+ if (stringStartsWith(xml, "<?xml"))
249
+ convert_response(res);
250
+ else
251
+ @resp['Result'] = -999
252
+ @resp['Message'] = "Gateway error" + xml
253
+ return @resp
254
+ end
255
+
256
+ return @resp
257
+ rescue Exception => e
258
+ @resp['Result'] = -999
259
+ @resp['Message'] = "Gateway error" + xml
260
+ return @resp
261
+ end
233
262
  end
234
263
 
235
264
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: risepay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Perez