exact4r 0.5.2 → 0.6

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 (39) hide show
  1. data/CHANGELOG +8 -0
  2. data/README +8 -8
  3. data/VERSION +1 -1
  4. data/doc/classes/EWS/Transaction/FakeResponse.html +451 -0
  5. data/doc/classes/EWS/Transaction/Request.html +54 -81
  6. data/doc/classes/EWS/Transaction/Response.html +182 -14
  7. data/doc/classes/EWS/Transaction/Validator.html +168 -0
  8. data/doc/classes/EWS/Transporter.html +271 -0
  9. data/doc/created.rid +1 -1
  10. data/doc/files/CHANGELOG.html +15 -2
  11. data/doc/files/README.html +17 -9
  12. data/doc/files/VERSION.html +2 -2
  13. data/doc/files/lib/ews/transaction/fake_response_rb.html +101 -0
  14. data/doc/files/lib/ews/transaction/mapping_rb.html +1 -1
  15. data/doc/files/lib/ews/transaction/request_rb.html +8 -1
  16. data/doc/files/lib/ews/transaction/response_rb.html +1 -1
  17. data/doc/files/lib/ews/transaction/validator_rb.html +101 -0
  18. data/doc/files/lib/ews/{transaction/transporter_rb.html → transporter_rb.html} +3 -3
  19. data/doc/files/lib/exact4r_rb.html +4 -2
  20. data/doc/fr_class_index.html +3 -1
  21. data/doc/fr_file_index.html +3 -1
  22. data/doc/fr_method_index.html +18 -7
  23. data/lib/ews/transaction/fake_response.rb +137 -0
  24. data/lib/ews/transaction/mapping.rb +38 -15
  25. data/lib/ews/transaction/request.rb +10 -58
  26. data/lib/ews/transaction/response.rb +3 -3
  27. data/lib/ews/transaction/validator.rb +230 -0
  28. data/lib/ews/transporter.rb +143 -0
  29. data/lib/exact4r.rb +4 -1
  30. data/spec/donncha_spec.rb +13 -0
  31. data/spec/mapping_spec.rb +45 -4
  32. data/spec/request_spec.rb +96 -69
  33. data/spec/spec_helper.rb +20 -8
  34. data/spec/transporter_spec.rb +26 -2
  35. data/spec/validator_spec.rb +145 -0
  36. metadata +16 -7
  37. data/doc/classes/EWS/Transaction/Transporter.html +0 -250
  38. data/lib/ews/transaction/transporter.rb +0 -120
  39. data/output.log +0 -368
@@ -1,120 +0,0 @@
1
- require 'net/https'
2
-
3
- module EWS # :nodoc:
4
- module Transaction # :nodoc:
5
-
6
- # A Transporter is responsible for communicating with the E-xact Web Service in
7
- # whichever dialect is chosen by the user. The available options are:
8
- # :json REST with JSON payload
9
- # :rest REST with XML payload (default)
10
- # :soap SOAP
11
- #
12
- # The Transporter will connect to the service, using SSL if required, and will
13
- # encode Reqests to send to the service, and decode Responses received from the
14
- # service.
15
- #
16
- # Once configured to connect to a particular service, it can be used repeatedly
17
- # to send as many transactions as required.
18
- class Transporter
19
-
20
- # Initialize a Transporter.
21
- #
22
- # You can specify the URL you would like the Transporter to connect to, although it defaults
23
- # to https://api.e-xact.com, the location of our transaction processing web service.
24
- #
25
- # You can also specify a hash of options as follows:
26
- # :server_cert the path to the server's certificate
27
- # :issuer_cert the path to the certificate of the issuer of the server certificate
28
- # :transport_type the default transport_type for this transporter (defaults to :rest)
29
- #
30
- # The default certificates are those required to connect to https://api.e-xact.com and the
31
- # default <tt>transport_type</tt> is <tt>:rest</tt>. The default <tt>transport_type</tt> can be overridden on a per-transaction
32
- # basis, if you choose to do so, by specifying it as a parameter to the <tt>send</tt> method.
33
- def initialize(url = "https://api.e-xact.com/", options = {})
34
- @url = URI.parse(url.gsub(/\/$/,''))
35
- base = File.dirname(__FILE__)
36
- @server_cert = options[:server_cert] || base+"/../../../certs/exact.cer"
37
- @issuer_cert = options[:issuer_cert] || base+"/../../../certs/equifax_ca.cer"
38
- @transport_type = options[:transport_type] || :rest
39
- end
40
-
41
- # Send a transaction request to the server
42
- #
43
- # <tt>transaction</tt>:: the Request object to encode for transmission to the server
44
- # <tt>transport_type</tt>:: (optional) the transport type to use for this transaction only. If it is not specified, the Transporter's transport type will be used
45
- def submit(transaction, transport_type = nil)
46
- raise "Request not supplied" if transaction.nil?
47
- return false unless transaction.valid?
48
-
49
- transport_type ||= @transport_type
50
-
51
- raise "Transport type #{transport_type} is not supported" unless @@transport_types.include? transport_type
52
-
53
- transport_details = @@transport_types[transport_type]
54
-
55
- request = build_http_request(transaction, transport_type, transport_details[:suffix])
56
- request.basic_auth(transaction.gateway_id, transaction.password)
57
- request["User-Agent"] = "Ruby"
58
- request.content_type = "#{transport_details[:content_type]}; charset=UTF-8"
59
-
60
- response = get_connection.request(request)
61
-
62
- case response
63
- when Net::HTTPSuccess then EWS::Transaction::Mapping.send "#{transport_type}_to_response", response.body
64
- else
65
- response.error!
66
- end
67
-
68
- end
69
-
70
- private
71
-
72
- def build_http_request(transaction, transport_type, request_suffix)
73
- req = nil
74
- if !transaction.is_find_transaction? or transport_type == :soap
75
- req = Net::HTTP::Post.new(@url.path + "/transaction.#{request_suffix}")
76
- if transport_type == :soap
77
- # add the SOAPAction header
78
- soapaction = (transaction.is_find_transaction?) ? "TransactionInfo" : "SendAndCommit"
79
- req.add_field "soapaction", "http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/#{soapaction}"
80
- end
81
- req.body = EWS::Transaction::Mapping.send "request_to_#{transport_type.to_s}", transaction
82
- else
83
- req = Net::HTTP::Get.new(@url.path + "/transaction/#{transaction.transaction_tag}.#{request_suffix}")
84
- end
85
- req
86
- end
87
-
88
- def get_connection
89
- # re-use the connection if it's available
90
- return @connection unless @connection.nil?
91
-
92
- @connection = Net::HTTP.new(@url.host, @url.port)
93
- @connection.set_debug_output $stdout if $DEBUG
94
- if @url.scheme == 'https'
95
- @connection.use_ssl = true
96
- @connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
97
- @connection.ca_file = @issuer_cert
98
- @connection.verify_callback = method(:validate_certificate)
99
- end
100
- @connection
101
- end
102
-
103
- def validate_certificate(is_ok, ctx)
104
- # Don't check the root CA cert
105
- unless (ctx.current_cert.subject.to_s == ctx.current_cert.issuer.to_s)
106
- is_ok &&= File.open(@server_cert).read == ctx.current_cert.to_pem
107
- end
108
- is_ok
109
- end
110
-
111
- # what transport types we support, and their corresponding suffixes
112
- @@transport_types = {
113
- :rest => {:suffix => "xml", :content_type => "application/xml"},
114
- :json => {:suffix => "json", :content_type => "application/json"},
115
- :soap => {:suffix => "xmlsoap", :content_type => "application/xml"}
116
- }
117
-
118
- end
119
- end
120
- end
data/output.log DELETED
@@ -1,368 +0,0 @@
1
- Index: VERSION
2
- ===================================================================
3
- --- VERSION (revision 6047)
4
- +++ VERSION (working copy)
5
- @@ -1 +1 @@
6
- -0.5.1
7
-
8
- +0.5.2
9
-
10
- Index: lib/ews/transaction/response.rb
11
- ===================================================================
12
- --- lib/ews/transaction/response.rb (revision 6043)
13
- +++ lib/ews/transaction/response.rb (working copy)
14
- @@ -2,13 +2,17 @@
15
- module Transaction # :nodoc:
16
-
17
- # This class encapsulates all the data returned from the E-xact Web Service.
18
- - class Response < EWS::Transaction::Request
19
- + class Response
20
-
21
- attr_accessor :logon_message, :error_number, :error_description, :transaction_error, :transaction_approved
22
- attr_accessor :exact_resp_code, :exact_message, :bank_resp_code, :bank_message, :bank_resp_code_2
23
- attr_accessor :sequence_no, :avs, :cvv2, :retrieval_ref_no, :cavv_response
24
- attr_accessor :merchant_name, :merchant_address, :merchant_city, :merchant_province, :merchant_country, :merchant_postal, :merchant_url, :CTR
25
-
26
- + attr_accessor :gateway_id, :password, :transaction_type, :amount, :surcharge_amount, :cc_number, :transaction_tag, :track1, :track2, :pan, :auth_number, :cc_expiry, :cardholder_name
27
- + attr_accessor :cc_verification_str1, :cc_verification_str2, :cvd_presence_ind, :tax1_amount, :tax1_number, :tax2_amount, :tax2_number, :secure_auth_required, :secure_auth_result
28
- + attr_accessor :ecommerce_flag, :xid, :cavv, :cavv_algorithm, :reference_no, :customer_ref, :reference_3, :language, :client_ip, :client_email, :user_name
29
- +
30
- # Indicates whether or not the transaction was approved
31
- def approved?
32
- self.transaction_approved == 1
33
- Index: lib/ews/transaction/transporter.rb
34
- ===================================================================
35
- --- lib/ews/transaction/transporter.rb (revision 6047)
36
- +++ lib/ews/transaction/transporter.rb (working copy)
37
- @@ -6,7 +6,7 @@
38
- # A Transporter is responsible for communicating with the E-xact Web Service in
39
- # whichever dialect is chosen by the user. The available options are:
40
- # :json REST with JSON payload
41
- - # :rest REST with XML payload
42
- + # :rest REST with XML payload (default)
43
- # :soap SOAP
44
- #
45
- # The Transporter will connect to the service, using SSL if required, and will
46
- @@ -19,95 +19,85 @@
47
-
48
- # Initialize a Transporter.
49
- #
50
- - # You can specify the URL you would like the Transporter to connect to,
51
- - # although it defaults to https://api.e-xact.com, the location of our web
52
- - # service.
53
- + # You can specify the URL you would like the Transporter to connect to, although it defaults
54
- + # to https://api.e-xact.com, the location of our transaction processing web service.
55
- #
56
- # You can also specify a hash of options as follows:
57
- # :server_cert the path to the server's certificate
58
- # :issuer_cert the path to the certificate of the issuer of the server certificate
59
- - # :transport_type the default transport_type for this transporter
60
- + # :transport_type the default transport_type for this transporter (defaults to :rest)
61
- #
62
- # The default certificates are those required to connect to https://api.e-xact.com and the
63
- # default <tt>transport_type</tt> is <tt>:rest</tt>. The default <tt>transport_type</tt> can be overridden on a per-transaction
64
- # basis, if you choose to do so, by specifying it as a parameter to the <tt>send</tt> method.
65
- def initialize(url = "https://api.e-xact.com/", options = {})
66
- - @url = URI.parse(url)
67
- + @url = URI.parse(url.gsub(/\/$/,''))
68
- base = File.dirname(__FILE__)
69
- @server_cert = options[:server_cert] || base+"/../../../certs/exact.cer"
70
- @issuer_cert = options[:issuer_cert] || base+"/../../../certs/equifax_ca.cer"
71
- - @transport_type = options[:issuer_cert] || :rest
72
- + @transport_type = options[:transport_type] || :rest
73
- end
74
-
75
- # Send a transaction request to the server
76
- #
77
- - # <tt>request</tt>:: the Request object to encode for transmission to the server
78
- - # <tt>transport_type</tt>:: (optional) the transport type to use for this transaction only. If it not specified, the default transport type for this Transporter will be used
79
- - def submit(request, transport_type = nil)
80
- - raise "Request not supplied" if request.nil?
81
- - return false unless request.valid?
82
- + # <tt>transaction</tt>:: the Request object to encode for transmission to the server
83
- + # <tt>transport_type</tt>:: (optional) the transport type to use for this transaction only. If it is not specified, the Transporter's transport type will be used
84
- + def submit(transaction, transport_type = nil)
85
- + raise "Request not supplied" if transaction.nil?
86
- + return false unless transaction.valid?
87
-
88
- transport_type ||= @transport_type
89
-
90
- raise "Transport type #{transport_type} is not supported" unless @@transport_types.include? transport_type
91
-
92
- - if !request.is_find_transaction? or transport_type == :soap
93
- - content = post(request, transport_type)
94
- - else
95
- - content = get(request, transport_type)
96
- - end
97
- + transport_details = @@transport_types[transport_type]
98
- +
99
- + request = build_http_request(transaction, transport_type, transport_details[:suffix])
100
- + request.basic_auth(transaction.gateway_id, transaction.password)
101
- + request["User-Agent"] = "Ruby"
102
- + request.content_type = "#{transport_details[:content_type]}; charset=UTF-8"
103
-
104
- - EWS::Transaction::Mapping.send "#{transport_type}_to_response", content
105
- - end
106
- + response = get_connection.request(request)
107
-
108
- - private
109
- -
110
- - def post(request, transport_type)
111
- - # build the request
112
- - req = Net::HTTP::Post.new(@url.path + "transaction.#{@@transport_types[transport_type]}")
113
- - req.basic_auth(request.gateway_id, request.password)
114
- - if transport_type == :soap
115
- - # add the SOAPAction header
116
- - soapaction = (request.is_find_transaction?) ? "TransactionInfo" : "SendAndCommit"
117
- - req.add_field "soapaction", "http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/#{soapaction}"
118
- - end
119
- - req.content_type = (transport_type == :json) ? "application/json" : "application/xml"
120
- - req.body = EWS::Transaction::Mapping.send "request_to_#{transport_type.to_s}", request
121
- -
122
- - response = get_connection.request(req)
123
- -
124
- case response
125
- - when Net::HTTPSuccess then response.body
126
- + when Net::HTTPSuccess then EWS::Transaction::Mapping.send "#{transport_type}_to_response", response.body
127
- else
128
- response.error!
129
- end
130
- +
131
- end
132
-
133
- - def get(request, transport_type)
134
- - # build the request
135
- - req = Net::HTTP::Get.new(@url.path + "transaction/#{request.transaction_tag}.#{@@transport_types[transport_type]}")
136
- - req.basic_auth(request.gateway_id, request.password)
137
- - req.content_type = (transport_type == :json) ? "application/json" : "application/xml"
138
- + private
139
-
140
- - response = get_connection.request(req)
141
- -
142
- - case response
143
- - when Net::HTTPSuccess then response.body
144
- + def build_http_request(transaction, transport_type, request_suffix)
145
- + req = nil
146
- + if !transaction.is_find_transaction? or transport_type == :soap
147
- + req = Net::HTTP::Post.new(@url.path + "/transaction.#{request_suffix}")
148
- + if transport_type == :soap
149
- + # add the SOAPAction header
150
- + soapaction = (transaction.is_find_transaction?) ? "TransactionInfo" : "SendAndCommit"
151
- + req.add_field "soapaction", "http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/#{soapaction}"
152
- + end
153
- + req.body = EWS::Transaction::Mapping.send "request_to_#{transport_type.to_s}", transaction
154
- else
155
- - response.error!
156
- + req = Net::HTTP::Get.new(@url.path + "/transaction/#{transaction.transaction_tag}.#{request_suffix}")
157
- end
158
- + req
159
- end
160
- -
161
- +
162
- def get_connection
163
- - connection = Net::HTTP.new(@url.host, @url.port)
164
- - connection.set_debug_output $stdout if $DEBUG
165
- + # re-use the connection if it's available
166
- + return @connection unless @connection.nil?
167
- +
168
- + @connection = Net::HTTP.new(@url.host, @url.port)
169
- + @connection.set_debug_output $stdout if $DEBUG
170
- if @url.scheme == 'https'
171
- - connection.use_ssl = true
172
- - connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
173
- - connection.ca_file = @issuer_cert
174
- - connection.verify_callback = method(:validate_certificate)
175
- + @connection.use_ssl = true
176
- + @connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
177
- + @connection.ca_file = @issuer_cert
178
- + @connection.verify_callback = method(:validate_certificate)
179
- end
180
- - connection
181
- + @connection
182
- end
183
-
184
- def validate_certificate(is_ok, ctx)
185
- @@ -120,9 +110,9 @@
186
-
187
- # what transport types we support, and their corresponding suffixes
188
- @@transport_types = {
189
- - :rest => "xml",
190
- - :json => "json",
191
- - :soap => "xmlsoap"
192
- + :rest => {:suffix => "xml", :content_type => "application/xml"},
193
- + :json => {:suffix => "json", :content_type => "application/json"},
194
- + :soap => {:suffix => "xmlsoap", :content_type => "application/xml"}
195
- }
196
-
197
- end
198
- Index: CHANGELOG
199
- ===================================================================
200
- --- CHANGELOG (revision 6047)
201
- +++ CHANGELOG (working copy)
202
- @@ -1,3 +1,9 @@
203
- +== v0.5.2
204
- + Updated Transporter to play nicely with mod_security
205
- + Stripped trailing '/'s from URLs
206
- + Now re-use same connection
207
- + Updated RDoc with test login details
208
- +
209
- == v0.5.1
210
- Added CHANGELOG, LICENCE & VERSION
211
- Ensured README etc. were included in gem and displayed as default in RDoc
212
- Index: spec/transporter_spec.rb
213
- ===================================================================
214
- --- spec/transporter_spec.rb (revision 6047)
215
- +++ spec/transporter_spec.rb (working copy)
216
- @@ -14,49 +14,8 @@
217
-
218
- lambda {
219
- tr = ::EWS::Transaction::Transporter.new
220
- - tr.submit(txn, json)
221
- + tr.submit(txn)
222
- }.should_not raise_error(RuntimeError)
223
- end
224
-
225
- -
226
- end
227
- -
228
- -describe "Transporter finding transactions" do
229
- -
230
- - before :each do
231
- - txn = basic_new_transaction
232
- - @tr = ::EWS::Transaction::Transporter.new
233
- - r = @tr.submit(txn, :json)
234
- - @transaction_tag = r.transaction_tag
235
- - end
236
- -
237
- - it "should support all transport types" do
238
- - [:json, :rest, :soap].each do |type|
239
- - txn = basic_find_transaction(:transaction_tag => @transaction_tag)
240
- - resp = @tr.submit(txn, type)
241
- -
242
- - resp.transaction_tag.should == @transaction_tag
243
- - resp.cc_number == "4111111111111"
244
- - resp.exact_resp_code.should == "00"
245
- - resp.exact_message.should == "Transaction Normal"
246
- - resp.bank_message.should == "APPROVED"
247
- - end
248
- - end
249
- -
250
- -end
251
- -
252
- -describe "Transporter creating and finding transactions" do
253
- -
254
- - it "should support all transport types" do
255
- - [:json, :rest, :soap].each do |type|
256
- - tr = ::EWS::Transaction::Transporter.new
257
- - new_txn = tr.submit(basic_new_transaction, type)
258
- - new_txn.transaction_tag.should_not be_nil
259
- -
260
- - found_txn = tr.submit(basic_find_transaction(:transaction_tag => new_txn.transaction_tag), :json)
261
- - found_txn.should_not be_nil
262
- - found_txn.transaction_tag.should == new_txn.transaction_tag
263
- - end
264
- - end
265
- -
266
- -end
267
-
268
- Index: spec/request_spec.rb
269
- ===================================================================
270
- --- spec/request_spec.rb (revision 6047)
271
- +++ spec/request_spec.rb (working copy)
272
- @@ -70,7 +70,7 @@
273
-
274
- resp.exact_resp_code.should == "00"
275
- resp.exact_message.should == "Transaction Normal"
276
- - resp.bank_message.should == "APPROVED"
277
- + resp.bank_message.downcase.should match(/approved/)
278
- resp.transaction_tag.should_not be_nil
279
- end
280
-
281
- @@ -81,7 +81,7 @@
282
-
283
- resp.exact_resp_code.should == "00"
284
- resp.exact_message.should == "Transaction Normal"
285
- - resp.bank_message.should == "APPROVED"
286
- + resp.bank_message.downcase.should match(/approved/)
287
- resp.transaction_tag.should_not be_nil
288
- end
289
- end
290
- @@ -95,6 +95,9 @@
291
-
292
- txn = basic_new_transaction
293
- @transaction_tag = @transporter.submit(txn, :json).transaction_tag
294
- + puts "Sleeping for replication: #{REPLICATION_TIME}s"
295
- + sleep(REPLICATION_TIME) # need time for replication to take place on the host
296
- + puts "Awake"
297
- end
298
-
299
- it "should work without a specified transport_type" do
300
- @@ -103,7 +106,7 @@
301
-
302
- resp.exact_resp_code.should == "00"
303
- resp.exact_message.should == "Transaction Normal"
304
- - resp.bank_message.should == "APPROVED"
305
- + resp.bank_message.downcase.should match(/approved/)
306
- resp.transaction_tag.should_not be_nil
307
- end
308
-
309
- @@ -116,7 +119,7 @@
310
- resp.cc_number == "4111111111111"
311
- resp.exact_resp_code.should == "00"
312
- resp.exact_message.should == "Transaction Normal"
313
- - resp.bank_message.should == "APPROVED"
314
- + resp.bank_message.downcase.should match(/approved/)
315
- end
316
- end
317
-
318
- Index: spec/spec_helper.rb
319
- ===================================================================
320
- --- spec/spec_helper.rb (revision 6048)
321
- +++ spec/spec_helper.rb (working copy)
322
- @@ -3,6 +3,8 @@
323
- require 'spec'
324
- require 'lib/exact4r'
325
-
326
- +REPLICATION_TIME = 20
327
- +
328
- def basic_params(options = {})
329
- {
330
- :transaction_type => :purchase,
331
- @@ -18,8 +20,7 @@
332
- def basic_find_transaction(options = {})
333
- params = {
334
- :transaction_type => :transaction_details,
335
- - :gateway_id => "AD0008-01",
336
- - :password => "7nfcpc7n"
337
- + :gateway_id => "A00049-01", :password => "test1"
338
- }.merge(options)
339
-
340
- ::EWS::Transaction::Request.new(params)
341
- @@ -33,8 +34,7 @@
342
- :cc_number => "4111111111111111",
343
- :cc_expiry => "1005",
344
- :reference_no => "987987",
345
- - :gateway_id => "AD0008-01",
346
- - :password => "7nfcpc7n"
347
- + :gateway_id => "A00049-01", :password => "test1"
348
- }.merge(options)
349
-
350
- ::EWS::Transaction::Request.new(params)
351
- Index: README
352
- ===================================================================
353
- --- README (revision 6047)
354
- +++ README (working copy)
355
- @@ -4,6 +4,13 @@
356
-
357
- == Getting Started
358
-
359
- +To submit requests to our transaction processing service, you must first have a Gateway ID,
360
- +and a password. Test logins are as follows:
361
- +
362
- + Account 1: :gateway_id => "A00049-01", :password => "test1"
363
- + Account 2: :gateway_id => "A00427-01", :password => "testus"
364
- +
365
- +
366
- =1. Submit a transaction
367
-
368
- require 'rubygems'