exact4r 0.9.1 → 0.9.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.
- data/CHANGELOG +6 -1
- data/README +71 -3
- data/Rakefile +8 -7
- data/VERSION +1 -1
- data/doc/classes/EWS/Transaction/FakeResponse.html +451 -0
- data/doc/classes/EWS/Transaction/Request.html +61 -80
- data/doc/classes/EWS/Transaction/Response.html +206 -14
- data/doc/classes/EWS/Transaction/Validator.html +182 -0
- data/doc/classes/EWS/Transporter.html +269 -0
- data/doc/classes/REXML/Document.html +176 -0
- data/doc/classes/REXML/Entity.html +150 -0
- data/doc/classes/REXML.html +112 -0
- data/doc/created.rid +1 -1
- data/doc/files/CHANGELOG.html +156 -0
- data/doc/files/LICENCE.html +109 -0
- data/doc/files/README.html +164 -23
- data/doc/files/VERSION.html +107 -0
- data/doc/files/lib/ews/transaction/fake_response_rb.html +101 -0
- data/doc/files/lib/ews/transaction/mapping_rb.html +1 -1
- data/doc/files/lib/ews/transaction/request_rb.html +8 -1
- data/doc/files/lib/ews/transaction/response_rb.html +1 -1
- data/doc/files/lib/ews/transaction/validator_rb.html +101 -0
- data/doc/files/lib/ews/{transaction/transporter_rb.html → transporter_rb.html} +3 -3
- data/doc/files/lib/exact4r_rb.html +6 -2
- data/doc/fr_class_index.html +6 -1
- data/doc/fr_file_index.html +6 -1
- data/doc/fr_method_index.html +22 -7
- data/lib/ews/transaction/mapping.rb +41 -40
- data/lib/ews/transaction/request.rb +3 -4
- data/lib/ews/transaction/response.rb +5 -0
- data/lib/ews/transaction/validator.rb +44 -34
- data/lib/ews/transporter.rb +3 -3
- data/lib/exact4r.rb +1 -1
- data/test/exhaustive/forced_post_test.rb +75 -0
- data/test/exhaustive/online_debit_purchase_test.rb +66 -0
- data/test/exhaustive/online_debit_refund_test.rb +66 -0
- data/test/exhaustive/pre_auth_completion_test.rb +99 -0
- data/test/exhaustive/pre_auth_only_test.rb +68 -0
- data/test/exhaustive/pre_auth_test.rb +68 -0
- data/test/exhaustive/purchase_correction_test.rb +79 -0
- data/test/exhaustive/purchase_test.rb +68 -0
- data/test/exhaustive/recurring_seed_pre_auth_test.rb +68 -0
- data/test/exhaustive/recurring_seed_purchase_test.rb +68 -0
- data/test/exhaustive/refund_correction_test.rb +79 -0
- data/test/exhaustive/refund_test.rb +68 -0
- data/test/exhaustive/secure_storage_test.rb +75 -0
- data/test/exhaustive/tagged_online_debit_refund_test.rb +168 -0
- data/test/exhaustive/tagged_pre_auth_completion_test.rb +119 -0
- data/test/exhaustive/tagged_pre_auth_test.rb +116 -0
- data/test/exhaustive/tagged_purchase_test.rb +116 -0
- data/test/exhaustive/tagged_refund_test.rb +144 -0
- data/test/exhaustive/transaction_details_test.rb +86 -0
- data/test/exhaustive/void_test.rb +75 -0
- data/{spec/avs_spec.rb → test/general/avs_test.rb} +33 -44
- data/test/general/json_encoding_test.rb +62 -0
- data/test/general/request_test.rb +185 -0
- data/test/general/rest_encoding_test.rb +174 -0
- data/test/general/soap_encoding_test.rb +211 -0
- data/test/general/transporter_test.rb +54 -0
- data/test/general/validator_test.rb +150 -0
- data/test/samples/rest.dodgy.response.xml +60 -0
- data/test/samples/rest.everything.response.xml +67 -0
- data/test/samples/rest.response.xml +60 -0
- data/test/samples/soap.deserialization.fault.xml +10 -0
- data/test/samples/soap.dodgy.response.xml +95 -0
- data/test/samples/soap.everything.response.xml +75 -0
- data/test/samples/soap.generalfailure.fault.xml +13 -0
- data/test/samples/soap.nulltransaction.fault.xml +14 -0
- data/test/samples/soap.response.xml +95 -0
- data/test/test_helper.rb +115 -0
- metadata +52 -12
- data/doc/classes/EWS/Transaction/Transporter.html +0 -251
- data/pkg/exact4r-0.5.gem +0 -0
- data/spec/mapping_spec.rb +0 -126
- data/spec/request_spec.rb +0 -154
- data/spec/spec_helper.rb +0 -55
- data/spec/transporter_spec.rb +0 -43
- data/spec/validator_spec.rb +0 -150
@@ -0,0 +1,144 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
class TaggedRefundTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# NOTE: INTERAC Online Debit transactions are ONLY supported by Chase merchants
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@transporter = EWS::Transporter.new(LOCATION)
|
9
|
+
|
10
|
+
# do initial recurring seed
|
11
|
+
request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :recurring_seed_purchase))
|
12
|
+
request.amount = 11.25
|
13
|
+
assert request.valid?, request.errors.inspect
|
14
|
+
|
15
|
+
@response = @transporter.submit(request, :json)
|
16
|
+
assert @response.approved?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_mandatory
|
20
|
+
request = EWS::Transaction::Request.new(:transaction_type => :tagged_refund)
|
21
|
+
assert !request.valid?
|
22
|
+
assert_equal "gateway_id must be supplied", request.errors[:gateway_id]
|
23
|
+
|
24
|
+
request.gateway_id = EMERGIS_BASIC_AUTH[:gateway_id]
|
25
|
+
assert !request.valid?
|
26
|
+
assert_equal "password must be supplied", request.errors[:password]
|
27
|
+
|
28
|
+
request.password = EMERGIS_BASIC_AUTH[:password]
|
29
|
+
assert !request.valid?
|
30
|
+
assert_equal "One of the following must be supplied: cc_number, track1, track2 or transaction_tag.", request.errors[:base]
|
31
|
+
|
32
|
+
request.transaction_tag = 1234
|
33
|
+
assert !request.valid?
|
34
|
+
assert_equal "authorization_num must be supplied", request.errors[:authorization_num]
|
35
|
+
|
36
|
+
request.authorization_num = "TH6754"
|
37
|
+
assert !request.valid?
|
38
|
+
assert_equal "amount must be supplied", request.errors[:amount]
|
39
|
+
|
40
|
+
request.amount = 11.25
|
41
|
+
assert request.valid?
|
42
|
+
|
43
|
+
request.cc_number = "4111111111111111"
|
44
|
+
assert !request.valid?
|
45
|
+
assert_equal "do not set cc_number for tagged transactions", request.errors[:cc_number]
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_json
|
49
|
+
request = EWS::Transaction::Request.new({
|
50
|
+
:transaction_type => :tagged_refund,
|
51
|
+
:amount => 11.25,
|
52
|
+
:transaction_tag => @response.transaction_tag,
|
53
|
+
:authorization_num => @response.authorization_num
|
54
|
+
}.merge(EMERGIS_BASIC_AUTH))
|
55
|
+
assert request.valid?, request.errors.inspect
|
56
|
+
|
57
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_rest
|
61
|
+
request = EWS::Transaction::Request.new({
|
62
|
+
:transaction_type => :tagged_refund,
|
63
|
+
:amount => 11.25,
|
64
|
+
:transaction_tag => @response.transaction_tag,
|
65
|
+
:authorization_num => @response.authorization_num
|
66
|
+
}.merge(EMERGIS_BASIC_AUTH))
|
67
|
+
assert request.valid?, request.errors.inspect
|
68
|
+
|
69
|
+
assert_details_correct request, @transporter.submit(request, :rest)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_soap
|
73
|
+
request = EWS::Transaction::Request.new({
|
74
|
+
:transaction_type => :tagged_refund,
|
75
|
+
:amount => 11.25,
|
76
|
+
:transaction_tag => @response.transaction_tag,
|
77
|
+
:authorization_num => @response.authorization_num
|
78
|
+
}.merge(EMERGIS_BASIC_AUTH))
|
79
|
+
assert request.valid?, request.errors.inspect
|
80
|
+
|
81
|
+
assert_details_correct request, @transporter.submit(request, :soap)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_multiple_refunds_against_one_seed
|
85
|
+
request = EWS::Transaction::Request.new({
|
86
|
+
:transaction_type => :tagged_refund,
|
87
|
+
:amount => 3.50,
|
88
|
+
:transaction_tag => @response.transaction_tag,
|
89
|
+
:authorization_num => @response.authorization_num
|
90
|
+
}.merge(EMERGIS_BASIC_AUTH))
|
91
|
+
assert request.valid?, request.errors.inspect
|
92
|
+
|
93
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
94
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
95
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
96
|
+
|
97
|
+
# can't refund more than original amount
|
98
|
+
response = @transporter.submit(request, :json)
|
99
|
+
assert !response.approved?
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_not_permitted_after_recurring_seed_pre_auth
|
103
|
+
# do initial recurring seed pre auth
|
104
|
+
pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :recurring_seed_pre_auth))
|
105
|
+
pre_request.amount = 11.25
|
106
|
+
assert pre_request.valid?, pre_request.errors.inspect
|
107
|
+
|
108
|
+
pre_response = @transporter.submit(pre_request, :json)
|
109
|
+
assert pre_response.approved?
|
110
|
+
|
111
|
+
# now do the tagged refund
|
112
|
+
request = EWS::Transaction::Request.new({
|
113
|
+
:transaction_type => :tagged_refund,
|
114
|
+
:amount => 11.25,
|
115
|
+
:transaction_tag => @response.transaction_tag,
|
116
|
+
:authorization_num => @response.authorization_num
|
117
|
+
}.merge(EMERGIS_BASIC_AUTH))
|
118
|
+
assert request.valid?, request.errors.inspect
|
119
|
+
|
120
|
+
response = @transporter.submit(request, :json)
|
121
|
+
assert !response.approved?
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_permitted_after_plain_purchase
|
125
|
+
# do initial purchase
|
126
|
+
pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :purchase))
|
127
|
+
pre_request.amount = 11.25
|
128
|
+
assert pre_request.valid?, pre_request.errors.inspect
|
129
|
+
|
130
|
+
pre_response = @transporter.submit(pre_request, :json)
|
131
|
+
assert pre_response.approved?
|
132
|
+
|
133
|
+
# now do the tagged refund
|
134
|
+
request = EWS::Transaction::Request.new({
|
135
|
+
:transaction_type => :tagged_refund,
|
136
|
+
:amount => 11.25,
|
137
|
+
:transaction_tag => @response.transaction_tag,
|
138
|
+
:authorization_num => @response.authorization_num
|
139
|
+
}.merge(EMERGIS_BASIC_AUTH))
|
140
|
+
assert request.valid?, request.errors.inspect
|
141
|
+
|
142
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
class TransactionDetailsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@transporter = EWS::Transporter.new(LOCATION)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_mandatory
|
10
|
+
request = EWS::Transaction::Request.new(:transaction_type => :transaction_details)
|
11
|
+
assert !request.valid?
|
12
|
+
assert_equal "gateway_id must be supplied", request.errors[:gateway_id]
|
13
|
+
|
14
|
+
request.gateway_id = EMERGIS_BASIC_AUTH[:gateway_id]
|
15
|
+
assert !request.valid?
|
16
|
+
assert_equal "password must be supplied", request.errors[:password]
|
17
|
+
|
18
|
+
request.password = EMERGIS_BASIC_AUTH[:password]
|
19
|
+
assert !request.valid?
|
20
|
+
assert_equal "transaction_tag must be supplied", request.errors[:transaction_tag]
|
21
|
+
|
22
|
+
request.transaction_tag = 1234
|
23
|
+
assert request.valid?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_credit_transaction_details
|
27
|
+
# do initial purchase
|
28
|
+
pre_request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :purchase))
|
29
|
+
pre_request.amount = 10.1
|
30
|
+
assert pre_request.valid?, pre_request.errors.inspect
|
31
|
+
|
32
|
+
pre_response = @transporter.submit(pre_request, :json)
|
33
|
+
assert pre_response.approved?
|
34
|
+
|
35
|
+
request = EWS::Transaction::Request.new({
|
36
|
+
:transaction_type => :transaction_details,
|
37
|
+
:transaction_tag => pre_response.transaction_tag
|
38
|
+
}.merge(EMERGIS_BASIC_AUTH))
|
39
|
+
assert request.valid?, request.errors.inspect
|
40
|
+
|
41
|
+
assert_details_match_original_response pre_response, @transporter.submit(request, :json)
|
42
|
+
assert_details_match_original_response pre_response, @transporter.submit(request, :rest)
|
43
|
+
assert_details_match_original_response pre_response, @transporter.submit(request, :soap)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_debit_transaction_details
|
47
|
+
# do initial purchase
|
48
|
+
pre_request = EWS::Transaction::Request.new({
|
49
|
+
:transaction_type => :idebit_purchase,
|
50
|
+
:amount => 10.1,
|
51
|
+
:pan => TEST_CARD_NUMBER,
|
52
|
+
:cardholder_name => TEST_CARD_HOLDER
|
53
|
+
}.merge(CHASE_BASIC_AUTH))
|
54
|
+
assert pre_request.valid?, pre_request.errors.inspect
|
55
|
+
|
56
|
+
pre_response = @transporter.submit(pre_request, :json)
|
57
|
+
assert pre_response.approved?
|
58
|
+
|
59
|
+
request = EWS::Transaction::Request.new({
|
60
|
+
:transaction_type => :transaction_details,
|
61
|
+
:transaction_tag => pre_response.transaction_tag
|
62
|
+
}.merge(CHASE_BASIC_AUTH))
|
63
|
+
assert request.valid?, request.errors.inspect
|
64
|
+
|
65
|
+
assert_details_match_original_response pre_response, @transporter.submit(request, :json)
|
66
|
+
assert_details_match_original_response pre_response, @transporter.submit(request, :rest)
|
67
|
+
assert_details_match_original_response pre_response, @transporter.submit(request, :soap)
|
68
|
+
end
|
69
|
+
|
70
|
+
def assert_details_match_original_response(original_response, details_response)
|
71
|
+
[:logon_message, :error_number, :error_description, :transaction_error, :transaction_approved, :exact_resp_code, :exact_message,
|
72
|
+
:bank_resp_code, :bank_message, :bank_resp_code_2, :sequence_no, :avs, :cvv2, :retrieval_ref_no, :cavv_response, :merchant_name,
|
73
|
+
:merchant_address, :merchant_city, :merchant_province, :merchant_country, :merchant_postal, :merchant_url, :gateway_id, :password,
|
74
|
+
:transaction_type, :amount, :surcharge_amount, :cc_number, :transaction_tag, :track1, :track2, :pan, :authorization_num, :cc_expiry,
|
75
|
+
:cardholder_name, :cc_verification_str1, :cc_verification_str2, :cvd_presence_ind, :tax1_amount, :tax1_number, :tax2_amount,
|
76
|
+
:tax2_number, :secure_auth_required, :secure_auth_result, :ecommerce_flag, :xid, :cavv, :cavv_algorithm, :reference_no, :customer_ref,
|
77
|
+
:reference_3, :language, :client_ip, :client_email, :user_name, :zip_code].each do |attr_name|
|
78
|
+
o_value = original_response.send(attr_name).to_s
|
79
|
+
d_value = details_response.send(attr_name).to_s
|
80
|
+
unless o_value == d_value
|
81
|
+
puts "#{attr_name}: #{o_value} / #{d_value}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
private :assert_details_match_original_response
|
86
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
class VoidTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@transporter = EWS::Transporter.new(LOCATION)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_mandatory
|
10
|
+
request = EWS::Transaction::Request.new(:transaction_type => :void)
|
11
|
+
assert !request.valid?
|
12
|
+
assert_equal "gateway_id must be supplied", request.errors[:gateway_id]
|
13
|
+
|
14
|
+
request.gateway_id = EMERGIS_BASIC_AUTH[:gateway_id]
|
15
|
+
assert !request.valid?
|
16
|
+
assert_equal "password must be supplied", request.errors[:password]
|
17
|
+
|
18
|
+
request.password = EMERGIS_BASIC_AUTH[:password]
|
19
|
+
assert !request.valid?
|
20
|
+
assert_equal "One of the following must be supplied: cc_number, track1, track2 or transaction_tag.", request.errors[:base]
|
21
|
+
|
22
|
+
request.cc_number = "4111111111111111"
|
23
|
+
assert !request.valid?
|
24
|
+
assert_equal "cc_expiry must be supplied", request.errors[:cc_expiry]
|
25
|
+
|
26
|
+
request.cc_expiry = "0913"
|
27
|
+
assert !request.valid?
|
28
|
+
assert_equal "cardholder_name must be supplied", request.errors[:cardholder_name]
|
29
|
+
|
30
|
+
request.cardholder_name = "Simon Jones"
|
31
|
+
assert !request.valid?
|
32
|
+
assert_equal "amount must be supplied", request.errors[:amount]
|
33
|
+
|
34
|
+
request.amount = 10
|
35
|
+
assert !request.valid?
|
36
|
+
assert_equal "authorization_num must be supplied", request.errors[:authorization_num]
|
37
|
+
|
38
|
+
request.authorization_num = "TH6754"
|
39
|
+
assert request.valid?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_by_credit_card
|
43
|
+
request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :void))
|
44
|
+
request.amount = 11.25
|
45
|
+
request.authorization_num = "1234"
|
46
|
+
assert request.valid?, request.errors.inspect
|
47
|
+
|
48
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
49
|
+
assert_details_correct request, @transporter.submit(request, :rest)
|
50
|
+
assert_details_correct request, @transporter.submit(request, :soap)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_by_track1
|
54
|
+
request = EWS::Transaction::Request.new(track1_params.merge(:transaction_type => :void))
|
55
|
+
request.amount = 11.25
|
56
|
+
request.authorization_num = "1234"
|
57
|
+
assert request.valid?, request.errors.inspect
|
58
|
+
|
59
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
60
|
+
assert_details_correct request, @transporter.submit(request, :rest)
|
61
|
+
assert_details_correct request, @transporter.submit(request, :soap)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_by_track2
|
65
|
+
request = EWS::Transaction::Request.new(track2_params.merge(:transaction_type => :void))
|
66
|
+
request.amount = 11.25
|
67
|
+
request.authorization_num = "1234"
|
68
|
+
assert request.valid?, request.errors.inspect
|
69
|
+
|
70
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
71
|
+
assert_details_correct request, @transporter.submit(request, :rest)
|
72
|
+
assert_details_correct request, @transporter.submit(request, :soap)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require File.dirname(__FILE__) + "
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class AvsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_packing_to_cc_verification_str1
|
6
6
|
tx_params = basic_params.merge(:avs_test_flag => nil,
|
7
7
|
:avs_street_address => '1234567LOUGHEEDHIGHW',
|
8
8
|
:avs_unit_no => nil,
|
9
9
|
:avs_po_box => nil,
|
10
10
|
:avs_postal_code => '902101234')
|
11
11
|
r = EWS::Transaction::Request.new(tx_params)
|
12
|
-
|
12
|
+
assert_equal '1234567LOUGHEEDHIGHW|902101234', r.cc_verification_str1
|
13
13
|
|
14
14
|
tx_params = basic_params.merge(:avs_test_flag => 'W',
|
15
15
|
:avs_street_address => '1234567LOUGHEEDHIGHW',
|
@@ -17,78 +17,67 @@ describe "AVS Request" do
|
|
17
17
|
:avs_po_box => nil,
|
18
18
|
:avs_postal_code => '902101234')
|
19
19
|
r = EWS::Transaction::Request.new(tx_params)
|
20
|
-
|
20
|
+
assert_equal 'W1234567LOUGHEEDHIGHW12|902101234', r.cc_verification_str1
|
21
21
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
|
23
|
+
def test_street_address_trumps_po_box
|
25
24
|
tx_params = basic_params.merge(:avs_test_flag => nil,
|
26
25
|
:avs_street_address => '1234567LOUGHEEDHIGHW',
|
27
26
|
:avs_unit_no => nil,
|
28
27
|
:avs_po_box => 'P.O.BOX24356',
|
29
28
|
:avs_postal_code => '902101234')
|
30
29
|
r = EWS::Transaction::Request.new(tx_params)
|
31
|
-
|
30
|
+
assert_equal '1234567LOUGHEEDHIGHW|902101234', r.cc_verification_str1
|
32
31
|
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "Submitting AVS Requests" do
|
36
32
|
|
37
|
-
|
38
|
-
@transporter = EWS::Transporter.new(LOCATION)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should be Paymentech AVS string" do
|
33
|
+
def test_encodes_for_paymentech
|
42
34
|
tx_params = basic_params.merge(:avs_test_flag => nil,
|
43
35
|
:avs_street_address => '1234567LOUGHEEDHIGHW',
|
44
36
|
:avs_unit_no => nil,
|
45
37
|
:avs_po_box => nil,
|
46
|
-
:avs_postal_code => '902101234'
|
47
|
-
:gateway_id => "AD0002-01",
|
48
|
-
:password => "63d9934x")
|
38
|
+
:avs_postal_code => '902101234').merge(CHASE_BASIC_AUTH)
|
49
39
|
r = EWS::Transaction::Request.new(tx_params)
|
50
|
-
|
51
|
-
|
52
|
-
|
40
|
+
assert_equal '1234567LOUGHEEDHIGHW|902101234', r.cc_verification_str1
|
41
|
+
|
42
|
+
resp = EWS::Transporter.new(LOCATION).submit(r)
|
43
|
+
assert_equal r.cc_verification_str1, resp.cc_verification_str1
|
53
44
|
end
|
54
45
|
|
55
|
-
|
46
|
+
def test_uses_default_avs_string
|
56
47
|
tx_params = basic_params.merge(:avs_test_flag => nil,
|
57
48
|
:avs_street_address => '1234567LOUGHEEDHIGHW',
|
58
49
|
:avs_unit_no => nil,
|
59
50
|
:avs_po_box => nil,
|
60
|
-
:avs_postal_code => '902101234'
|
61
|
-
:gateway_id => "AD0007-01",
|
62
|
-
:password => "3uLi726f")
|
51
|
+
:avs_postal_code => '902101234').merge(EMERGIS_BASIC_AUTH)
|
63
52
|
r = EWS::Transaction::Request.new(tx_params)
|
64
|
-
resp =
|
65
|
-
|
53
|
+
resp = EWS::Transporter.new(LOCATION).submit(r)
|
54
|
+
assert_equal '1234567LOUGHEEDHIGHW902101234', resp.cc_verification_str1
|
66
55
|
end
|
56
|
+
|
57
|
+
def test_space_with_numerals_for_tsys
|
58
|
+
transporter = EWS::Transporter.new(LOCATION)
|
67
59
|
|
68
|
-
|
60
|
+
# should put space between numeral and zip code for Tsys
|
69
61
|
tx_params = basic_params.merge(:avs_test_flag => nil,
|
70
62
|
:avs_street_address => nil,
|
71
63
|
:avs_unit_no => nil,
|
72
64
|
:avs_po_box => 'P.O.BOX24356',
|
73
|
-
:avs_postal_code => '902101234'
|
74
|
-
:gateway_id => "AD0001-01",
|
75
|
-
:password => "8q53g4ef")
|
65
|
+
:avs_postal_code => '902101234').merge(VITAL_BASIC_AUTH)
|
76
66
|
r = EWS::Transaction::Request.new(tx_params)
|
77
|
-
resp =
|
67
|
+
resp = transporter.submit(r)
|
78
68
|
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
assert_equal 'P.O.BOX24356 902101234', resp.cc_verification_str1
|
70
|
+
|
71
|
+
# should not put space if no numerals for Tsys
|
82
72
|
tx_params = basic_params.merge(:avs_test_flag => nil,
|
83
73
|
:avs_street_address => '1234567LOUGHEEDHIGHW',
|
84
74
|
:avs_unit_no => nil,
|
85
75
|
:avs_po_box => nil,
|
86
|
-
:avs_postal_code => '902101234'
|
87
|
-
:gateway_id => "AD0001-01",
|
88
|
-
:password => "8q53g4ef")
|
76
|
+
:avs_postal_code => '902101234').merge(EMERGIS_BASIC_AUTH)
|
89
77
|
r = EWS::Transaction::Request.new(tx_params)
|
90
|
-
resp =
|
78
|
+
resp = transporter.submit(r)
|
91
79
|
|
92
|
-
|
80
|
+
assert_equal '1234567LOUGHEEDHIGHW902101234', resp.cc_verification_str1
|
93
81
|
end
|
94
|
-
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
class JsonEncodingTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_basic_request_encoding
|
6
|
+
r = EWS::Transaction::Request.new(basic_params)
|
7
|
+
|
8
|
+
json = EWS::Transaction::Mapping.request_to_json(r)
|
9
|
+
|
10
|
+
res = ActiveSupport::JSON.decode(json)
|
11
|
+
assert_equal "10.13", res["amount"]
|
12
|
+
assert_equal "Simon Brown", res["cardholder_name"]
|
13
|
+
assert_equal "4111111111111111", res["cc_number"]
|
14
|
+
assert_equal "1012", res["cc_expiry"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_request_encoding_everything
|
18
|
+
request = EWS::Transaction::Request.new(sample_everything_params)
|
19
|
+
|
20
|
+
json = EWS::Transaction::Mapping.request_to_json(request)
|
21
|
+
|
22
|
+
res = ActiveSupport::JSON.decode(json)
|
23
|
+
sample_everything_params.keys.each do |k|
|
24
|
+
assert_equal request.send(k), res[k.to_s]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_response_decoding
|
29
|
+
payload = <<PAYLOAD
|
30
|
+
{"bank_message": "APPROVED", "transaction_type": "00", "transaction_tag": 2238, "exact_message": "Transaction Normal"}
|
31
|
+
PAYLOAD
|
32
|
+
|
33
|
+
r = EWS::Transaction::Mapping.json_to_response(payload)
|
34
|
+
|
35
|
+
assert_equal "Transaction Normal", r.exact_message
|
36
|
+
assert_nil r.error_description
|
37
|
+
assert_equal "APPROVED", r.bank_message
|
38
|
+
assert_equal 2238, r.transaction_tag
|
39
|
+
assert_equal "00", r.transaction_type
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_decodes_garbage_in_response
|
43
|
+
payload = <<PAYLOAD
|
44
|
+
{"bank_message": "APPROVED", "transaction_type": "00", "transaction_tag": 2238, "exact_message": "Transaction Normal", "cardholder_name": "Simon Brown Is Not A Really Long Name But This Is", "customer_ref": "This Is A Really LONG Customer Reference", "cc_number": "411111111111111166666666666"}
|
45
|
+
PAYLOAD
|
46
|
+
|
47
|
+
r = EWS::Transaction::Mapping.json_to_response(payload)
|
48
|
+
|
49
|
+
assert_equal "Transaction Normal", r.exact_message
|
50
|
+
assert_nil r.error_description
|
51
|
+
assert_equal "APPROVED", r.bank_message
|
52
|
+
assert_equal 2238, r.transaction_tag
|
53
|
+
assert_equal "00", r.transaction_type
|
54
|
+
|
55
|
+
# the following are all invalid examples of the relevant fields, so ensure we
|
56
|
+
# decode them without complaint.
|
57
|
+
assert_equal "Simon Brown Is Not A Really Long Name But This Is", r.cardholder_name
|
58
|
+
assert_equal "411111111111111166666666666", r.cc_number
|
59
|
+
assert_equal "This Is A Really LONG Customer Reference", r.customer_ref
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
class RequestTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_empty_construction
|
6
|
+
assert_nothing_raised {
|
7
|
+
assert_not_nil EWS::Transaction::Request.new
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_hash_construction
|
12
|
+
r = EWS::Transaction::Request.new(basic_params)
|
13
|
+
|
14
|
+
assert_equal "10.13", r.amount
|
15
|
+
assert_equal "Simon Brown", r.cardholder_name
|
16
|
+
assert_equal "4111111111111111", r.cc_number
|
17
|
+
assert_equal "1012", r.cc_expiry
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_errors_with_invalid_transaction_types
|
21
|
+
assert_nothing_raised {
|
22
|
+
EWS::Transaction::Request.new(basic_params(:transaction_type => "00"))
|
23
|
+
}
|
24
|
+
|
25
|
+
assert_nothing_raised {
|
26
|
+
EWS::Transaction::Request.new(basic_params(:transaction_type => :purchase))
|
27
|
+
}
|
28
|
+
|
29
|
+
assert_raises(ArgumentError) {
|
30
|
+
EWS::Transaction::Request.new(basic_params(:transaction_type => nil))
|
31
|
+
}
|
32
|
+
|
33
|
+
assert_raises(ArgumentError) {
|
34
|
+
EWS::Transaction::Request.new(basic_params(:transaction_type => ""))
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_raises(ArgumentError) {
|
38
|
+
EWS::Transaction::Request.new(basic_params(:transaction_type => "barry"))
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_value_setting
|
43
|
+
r = nil
|
44
|
+
assert_nothing_raised do
|
45
|
+
r = EWS::Transaction::Request.new(sample_everything_params)
|
46
|
+
end
|
47
|
+
assert_not_nil r
|
48
|
+
|
49
|
+
sample_everything_params.each do |k,v|
|
50
|
+
assert_equal v, r.send(k)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_default_submission
|
55
|
+
transporter = EWS::Transporter.new(LOCATION)
|
56
|
+
resp = transporter.submit(basic_new_transaction)
|
57
|
+
|
58
|
+
assert_equal "00", resp.exact_resp_code
|
59
|
+
assert_equal "Transaction Normal", resp.exact_message
|
60
|
+
assert_equal 1, resp.transaction_approved
|
61
|
+
assert_match /approved/, resp.bank_message.downcase
|
62
|
+
assert_not_nil resp.transaction_tag
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_json_submission
|
66
|
+
transporter = EWS::Transporter.new(LOCATION)
|
67
|
+
resp = transporter.submit(basic_new_transaction, :json)
|
68
|
+
|
69
|
+
assert_equal "00", resp.exact_resp_code
|
70
|
+
assert_equal "Transaction Normal", resp.exact_message
|
71
|
+
assert_equal 1, resp.transaction_approved
|
72
|
+
assert_match /approved/, resp.bank_message.downcase
|
73
|
+
assert_not_nil resp.transaction_tag
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_rest_submission
|
77
|
+
transporter = EWS::Transporter.new(LOCATION)
|
78
|
+
resp = transporter.submit(basic_new_transaction, :rest)
|
79
|
+
|
80
|
+
assert_equal "00", resp.exact_resp_code
|
81
|
+
assert_equal "Transaction Normal", resp.exact_message
|
82
|
+
assert_equal 1, resp.transaction_approved
|
83
|
+
assert_match /approved/, resp.bank_message.downcase
|
84
|
+
assert_not_nil resp.transaction_tag
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_soap_submission
|
88
|
+
transporter = EWS::Transporter.new(LOCATION)
|
89
|
+
resp = transporter.submit(basic_new_transaction, :soap)
|
90
|
+
|
91
|
+
assert_equal "00", resp.exact_resp_code
|
92
|
+
assert_equal "Transaction Normal", resp.exact_message
|
93
|
+
assert_equal 1, resp.transaction_approved
|
94
|
+
assert_match /approved/, resp.bank_message.downcase
|
95
|
+
assert_not_nil resp.transaction_tag
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_default_find
|
99
|
+
transporter = EWS::Transporter.new(LOCATION)
|
100
|
+
original_resp = transporter.submit(basic_new_transaction)
|
101
|
+
|
102
|
+
req = basic_find_transaction(:transaction_tag => original_resp.transaction_tag)
|
103
|
+
resp = transporter.submit(req)
|
104
|
+
|
105
|
+
assert_equal "00", resp.exact_resp_code
|
106
|
+
assert_equal "Transaction Normal", resp.exact_message
|
107
|
+
assert_match /approved/, resp.bank_message.downcase
|
108
|
+
assert_equal original_resp.transaction_tag, resp.transaction_tag
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_json_find
|
112
|
+
transporter = EWS::Transporter.new(LOCATION)
|
113
|
+
original_resp = transporter.submit(basic_new_transaction, :json)
|
114
|
+
|
115
|
+
req = basic_find_transaction(:transaction_tag => original_resp.transaction_tag)
|
116
|
+
resp = transporter.submit(req, :json)
|
117
|
+
|
118
|
+
assert_equal "00", resp.exact_resp_code
|
119
|
+
assert_equal "Transaction Normal", resp.exact_message
|
120
|
+
assert_match /approved/, resp.bank_message.downcase
|
121
|
+
assert_equal original_resp.transaction_tag, resp.transaction_tag
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_rest_find
|
125
|
+
transporter = EWS::Transporter.new(LOCATION)
|
126
|
+
original_resp = transporter.submit(basic_new_transaction, :rest)
|
127
|
+
|
128
|
+
req = basic_find_transaction(:transaction_tag => original_resp.transaction_tag)
|
129
|
+
resp = transporter.submit(req, :rest)
|
130
|
+
|
131
|
+
assert_equal "00", resp.exact_resp_code
|
132
|
+
assert_equal "Transaction Normal", resp.exact_message
|
133
|
+
assert_match /approved/, resp.bank_message.downcase
|
134
|
+
assert_equal original_resp.transaction_tag, resp.transaction_tag
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_soap_find
|
138
|
+
transporter = EWS::Transporter.new(LOCATION)
|
139
|
+
original_resp = transporter.submit(basic_new_transaction, :soap)
|
140
|
+
|
141
|
+
req = basic_find_transaction(:transaction_tag => original_resp.transaction_tag)
|
142
|
+
resp = transporter.submit(req, :soap)
|
143
|
+
|
144
|
+
assert_equal "00", resp.exact_resp_code
|
145
|
+
assert_equal "Transaction Normal", resp.exact_message
|
146
|
+
assert_match /approved/, resp.bank_message.downcase
|
147
|
+
assert_equal original_resp.transaction_tag, resp.transaction_tag
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_stubbing_and_fake_requests
|
151
|
+
request = {:nonsense => "this is nonsense"}
|
152
|
+
fake_response = EWS::Transaction::FakeResponse.valid(request)
|
153
|
+
|
154
|
+
transporter = EWS::Transporter.new(LOCATION)
|
155
|
+
transporter.stubs(:submit).returns(fake_response)
|
156
|
+
|
157
|
+
response = transporter.submit(request)
|
158
|
+
assert_equal fake_response, response
|
159
|
+
assert response.approved?
|
160
|
+
assert_equal "Transaction Normal", response.exact_message
|
161
|
+
end
|
162
|
+
|
163
|
+
private
|
164
|
+
def basic_find_transaction(options = {})
|
165
|
+
params = {
|
166
|
+
:transaction_type => :transaction_details,
|
167
|
+
}.merge(options)
|
168
|
+
|
169
|
+
::EWS::Transaction::Request.new(params.merge(EMERGIS_BASIC_AUTH))
|
170
|
+
end
|
171
|
+
|
172
|
+
def basic_new_transaction(options = {})
|
173
|
+
params = {
|
174
|
+
:transaction_type => :purchase,
|
175
|
+
:amount => "10.13",
|
176
|
+
:cardholder_name => "Simon Brown",
|
177
|
+
:cc_number => "4111111111111111",
|
178
|
+
:cc_expiry => "1012",
|
179
|
+
:reference_no => "987987",
|
180
|
+
}.merge(options)
|
181
|
+
|
182
|
+
::EWS::Transaction::Request.new(params.merge(EMERGIS_BASIC_AUTH))
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|