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
data/doc/fr_class_index.html
CHANGED
@@ -20,9 +20,14 @@
|
|
20
20
|
<div id="index">
|
21
21
|
<h1 class="section-bar">Classes</h1>
|
22
22
|
<div id="index-entries">
|
23
|
+
<a href="classes/EWS/Transaction/FakeResponse.html">EWS::Transaction::FakeResponse</a><br />
|
23
24
|
<a href="classes/EWS/Transaction/Request.html">EWS::Transaction::Request</a><br />
|
24
25
|
<a href="classes/EWS/Transaction/Response.html">EWS::Transaction::Response</a><br />
|
25
|
-
<a href="classes/EWS/Transaction/
|
26
|
+
<a href="classes/EWS/Transaction/Validator.html">EWS::Transaction::Validator</a><br />
|
27
|
+
<a href="classes/EWS/Transporter.html">EWS::Transporter</a><br />
|
28
|
+
<a href="classes/REXML.html">REXML</a><br />
|
29
|
+
<a href="classes/REXML/Document.html">REXML::Document</a><br />
|
30
|
+
<a href="classes/REXML/Entity.html">REXML::Entity</a><br />
|
26
31
|
</div>
|
27
32
|
</div>
|
28
33
|
</body>
|
data/doc/fr_file_index.html
CHANGED
@@ -20,11 +20,16 @@
|
|
20
20
|
<div id="index">
|
21
21
|
<h1 class="section-bar">Files</h1>
|
22
22
|
<div id="index-entries">
|
23
|
+
<a href="files/CHANGELOG.html">CHANGELOG</a><br />
|
24
|
+
<a href="files/LICENCE.html">LICENCE</a><br />
|
23
25
|
<a href="files/README.html">README</a><br />
|
26
|
+
<a href="files/VERSION.html">VERSION</a><br />
|
27
|
+
<a href="files/lib/ews/transaction/fake_response_rb.html">lib/ews/transaction/fake_response.rb</a><br />
|
24
28
|
<a href="files/lib/ews/transaction/mapping_rb.html">lib/ews/transaction/mapping.rb</a><br />
|
25
29
|
<a href="files/lib/ews/transaction/request_rb.html">lib/ews/transaction/request.rb</a><br />
|
26
30
|
<a href="files/lib/ews/transaction/response_rb.html">lib/ews/transaction/response.rb</a><br />
|
27
|
-
<a href="files/lib/ews/transaction/
|
31
|
+
<a href="files/lib/ews/transaction/validator_rb.html">lib/ews/transaction/validator.rb</a><br />
|
32
|
+
<a href="files/lib/ews/transporter_rb.html">lib/ews/transporter.rb</a><br />
|
28
33
|
<a href="files/lib/exact4r_rb.html">lib/exact4r.rb</a><br />
|
29
34
|
</div>
|
30
35
|
</div>
|
data/doc/fr_method_index.html
CHANGED
@@ -20,13 +20,28 @@
|
|
20
20
|
<div id="index">
|
21
21
|
<h1 class="section-bar">Methods</h1>
|
22
22
|
<div id="index-entries">
|
23
|
-
<a href="classes/EWS/Transaction/Response.html#
|
24
|
-
<a href="classes/EWS/Transaction/
|
25
|
-
<a href="classes/
|
26
|
-
<a href="classes/EWS/Transaction/
|
27
|
-
<a href="classes/EWS/Transaction/
|
28
|
-
<a href="classes/EWS/Transaction/
|
29
|
-
<a href="classes/EWS/Transaction/
|
23
|
+
<a href="classes/EWS/Transaction/Response.html#M000013">approved? (EWS::Transaction::Response)</a><br />
|
24
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000003">declined (EWS::Transaction::FakeResponse)</a><br />
|
25
|
+
<a href="classes/REXML/Document.html#M000021">entity_expansion_limit= (REXML::Document)</a><br />
|
26
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000006">invalid_amount (EWS::Transaction::FakeResponse)</a><br />
|
27
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000008">invalid_auth_num (EWS::Transaction::FakeResponse)</a><br />
|
28
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000012">invalid_avs (EWS::Transaction::FakeResponse)</a><br />
|
29
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000007">invalid_cardholder_name (EWS::Transaction::FakeResponse)</a><br />
|
30
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000005">invalid_cc_expiry (EWS::Transaction::FakeResponse)</a><br />
|
31
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000004">invalid_cc_number (EWS::Transaction::FakeResponse)</a><br />
|
32
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000009">invalid_cc_verification_str (EWS::Transaction::FakeResponse)</a><br />
|
33
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000011">invalid_reference_no (EWS::Transaction::FakeResponse)</a><br />
|
34
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000010">invalid_transaction_code (EWS::Transaction::FakeResponse)</a><br />
|
35
|
+
<a href="classes/EWS/Transaction/Request.html#M000017">is_find_transaction? (EWS::Transaction::Request)</a><br />
|
36
|
+
<a href="classes/EWS/Transporter.html#M000018">new (EWS::Transporter)</a><br />
|
37
|
+
<a href="classes/EWS/Transaction/Request.html#M000015">new (EWS::Transaction::Request)</a><br />
|
38
|
+
<a href="classes/REXML/Document.html#M000022">record_entity_expansion! (REXML::Document)</a><br />
|
39
|
+
<a href="classes/EWS/Transporter.html#M000019">submit (EWS::Transporter)</a><br />
|
40
|
+
<a href="classes/EWS/Transaction/Response.html#M000014">transaction_error? (EWS::Transaction::Response)</a><br />
|
41
|
+
<a href="classes/EWS/Transaction/Request.html#M000016">transaction_type= (EWS::Transaction::Request)</a><br />
|
42
|
+
<a href="classes/REXML/Entity.html#M000020">unnormalized (REXML::Entity)</a><br />
|
43
|
+
<a href="classes/EWS/Transaction/FakeResponse.html#M000002">valid (EWS::Transaction::FakeResponse)</a><br />
|
44
|
+
<a href="classes/EWS/Transaction/Validator.html#M000001">valid? (EWS::Transaction::Validator)</a><br />
|
30
45
|
</div>
|
31
46
|
</div>
|
32
47
|
</body>
|
@@ -13,65 +13,66 @@ module EWS # :nodoc:
|
|
13
13
|
class Mapping # :nodoc:
|
14
14
|
|
15
15
|
XML_REQUEST_TAGS_TO_ATTRS = {
|
16
|
-
:ExactID => :gateway_id,
|
17
|
-
:Password => :password,
|
18
|
-
:Transaction_Type => :transaction_type,
|
19
|
-
:DollarAmount => :amount,
|
20
|
-
:SurchargeAmount => :surcharge_amount,
|
21
|
-
:Card_Number => :cc_number,
|
22
|
-
:Transaction_Tag => :transaction_tag,
|
23
|
-
:Track1 => :track1,
|
24
|
-
:Track2 => :track2,
|
25
|
-
:PAN => :pan,
|
26
16
|
:Authorization_Num => :authorization_num,
|
27
|
-
:Expiry_Date => :cc_expiry,
|
28
17
|
:CardHoldersName => :cardholder_name,
|
29
|
-
:
|
30
|
-
:
|
18
|
+
:Card_Number => :cc_number,
|
19
|
+
:CAVV => :cavv,
|
20
|
+
:CAVV_Algorithm => :cavv_algorithm,
|
21
|
+
:Client_Email => :client_email,
|
22
|
+
:Client_IP => :client_ip,
|
23
|
+
:Customer_Ref => :customer_ref,
|
31
24
|
:CVD_Presence_Ind => :cvd_presence_ind,
|
32
|
-
:
|
25
|
+
:DollarAmount => :amount,
|
26
|
+
:Ecommerce_Flag => :ecommerce_flag,
|
27
|
+
:ExactID => :gateway_id,
|
28
|
+
:Expiry_Date => :cc_expiry,
|
29
|
+
:Language => :language,
|
30
|
+
:PAN => :pan,
|
31
|
+
:Password => :password,
|
32
|
+
:Reference_3 => :reference_3,
|
33
|
+
:Reference_No => :reference_no,
|
34
|
+
:Secure_AuthRequired => :secure_auth_required,
|
35
|
+
:Secure_AuthResult => :secure_auth_result,
|
36
|
+
:SurchargeAmount => :surcharge_amount,
|
33
37
|
:Tax1Amount => :tax1_amount,
|
34
38
|
:Tax1Number => :tax1_number,
|
35
39
|
:Tax2Amount => :tax2_amount,
|
36
40
|
:Tax2Number => :tax2_number,
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
41
|
+
:Track1 => :track1,
|
42
|
+
:Track2 => :track2,
|
43
|
+
:Transaction_Tag => :transaction_tag,
|
44
|
+
:Transaction_Type => :transaction_type,
|
45
|
+
:VerificationStr1 => :cc_verification_str1,
|
46
|
+
:VerificationStr2 => :cc_verification_str2,
|
47
|
+
:User_Name => :user_name,
|
40
48
|
:XID => :xid,
|
41
|
-
:
|
42
|
-
:CAVV_Algorithm => :cavv_algorithm,
|
43
|
-
:Reference_No => :reference_no,
|
44
|
-
:Customer_Ref => :customer_ref,
|
45
|
-
:Reference_3 => :reference_3,
|
46
|
-
:Language => :language,
|
47
|
-
:Client_IP => :client_ip,
|
48
|
-
:Client_Email => :client_email
|
49
|
+
:ZipCode => :zip_code
|
49
50
|
} unless defined?(XML_REQUEST_TAGS_TO_ATTRS)
|
50
51
|
|
51
52
|
XML_RESPONSE_TAGS_TO_ATTRS = {
|
52
|
-
:
|
53
|
-
:Error_Number => :error_number,
|
54
|
-
:Error_Description => :error_description,
|
55
|
-
:Transaction_Error => :transaction_error,
|
56
|
-
:Transaction_Approved => :transaction_approved,
|
57
|
-
:EXact_Resp_Code => :exact_resp_code,
|
58
|
-
:EXact_Message => :exact_message,
|
59
|
-
:Bank_Resp_Code => :bank_resp_code,
|
53
|
+
:AVS => :avs,
|
60
54
|
:Bank_Message => :bank_message,
|
55
|
+
:Bank_Resp_Code => :bank_resp_code,
|
61
56
|
:Bank_Resp_Code_2 => :bank_resp_code_2,
|
62
|
-
:SequenceNo => :sequence_no,
|
63
|
-
:AVS => :avs,
|
64
|
-
:CVV2 => :cvv2,
|
65
|
-
:Retrieval_Ref_No => :retrieval_ref_no,
|
66
57
|
:CAVV_Response => :cavv_response,
|
67
|
-
:
|
58
|
+
:CTR => :ctr,
|
59
|
+
:CVV2 => :cvv2,
|
60
|
+
:Error_Description => :error_description,
|
61
|
+
:Error_Number => :error_number,
|
62
|
+
:EXact_Message => :exact_message,
|
63
|
+
:EXact_Resp_Code => :exact_resp_code,
|
64
|
+
:LogonMessage => :logon_message,
|
68
65
|
:MerchantAddress => :merchant_address,
|
69
66
|
:MerchantCity => :merchant_city,
|
70
|
-
:MerchantProvince => :merchant_province,
|
71
67
|
:MerchantCountry => :merchant_country,
|
68
|
+
:MerchantName => :merchant_name,
|
72
69
|
:MerchantPostal => :merchant_postal,
|
70
|
+
:MerchantProvince => :merchant_province,
|
73
71
|
:MerchantURL => :merchant_url,
|
74
|
-
:
|
72
|
+
:Retrieval_Ref_No => :retrieval_ref_no,
|
73
|
+
:SequenceNo => :sequence_no,
|
74
|
+
:Transaction_Approved => :transaction_approved,
|
75
|
+
:Transaction_Error => :transaction_error
|
75
76
|
}.merge(XML_REQUEST_TAGS_TO_ATTRS) unless defined?(XML_RESPONSE_TAGS_TO_ATTRS)
|
76
77
|
|
77
78
|
def self.request_to_json(request)
|
@@ -50,7 +50,7 @@ module EWS # :nodoc:
|
|
50
50
|
# yeah, it's ugly, but otherwise RDoc won't pick them up
|
51
51
|
attr_accessor :errors
|
52
52
|
attr_accessor :gateway_id, :password, :transaction_type, :amount, :surcharge_amount, :cc_number, :transaction_tag, :track1, :track2, :pan, :authorization_num, :cc_expiry, :cardholder_name
|
53
|
-
attr_accessor :cc_verification_str2, :cvd_presence_ind, :tax1_amount, :tax1_number, :tax2_amount, :tax2_number, :secure_auth_required, :secure_auth_result
|
53
|
+
attr_accessor :cc_verification_str2, :cvd_presence_ind, :tax1_amount, :tax1_number, :tax2_amount, :tax2_number, :secure_auth_required, :secure_auth_result, :user_name
|
54
54
|
|
55
55
|
# AVS - Address Verification,
|
56
56
|
attr_accessor :cc_verification_str1
|
@@ -63,7 +63,7 @@ module EWS # :nodoc:
|
|
63
63
|
@#{m.to_s} = v
|
64
64
|
calculate_verification_str1
|
65
65
|
end
|
66
|
-
|
66
|
+
METHOD_EOS
|
67
67
|
}
|
68
68
|
|
69
69
|
attr_accessor :ecommerce_flag, :xid, :cavv, :cavv_algorithm, :reference_no, :customer_ref, :reference_3, :language, :client_ip, :client_email, :zip_code
|
@@ -81,7 +81,7 @@ module EWS # :nodoc:
|
|
81
81
|
value = @@transaction_codes[type_sym]
|
82
82
|
# if nothing found, then maybe we were given an actual code?
|
83
83
|
if(value.nil?)
|
84
|
-
raise "invalid transaction_type supplied #{type_sym}" unless @@transaction_codes.values.include?(type_sym)
|
84
|
+
raise ArgumentError, "invalid transaction_type supplied #{type_sym}" unless @@transaction_codes.values.include?(type_sym)
|
85
85
|
value = type_sym
|
86
86
|
end
|
87
87
|
|
@@ -108,7 +108,6 @@ module EWS # :nodoc:
|
|
108
108
|
:tagged_purchase => '30',
|
109
109
|
:tagged_pre_auth => '31',
|
110
110
|
:tagged_pre_auth_completion => '32',
|
111
|
-
:tagged_void => '33',
|
112
111
|
:tagged_refund => '34',
|
113
112
|
:tagged_online_debit_refund => '35',
|
114
113
|
:recurring_seed_pre_auth => '40',
|
@@ -30,16 +30,30 @@ module EWS # :nodoc:
|
|
30
30
|
def valid?
|
31
31
|
@errors = {}
|
32
32
|
|
33
|
-
validate_lengths
|
34
|
-
|
35
|
-
validate_mandatory_fields
|
36
|
-
|
37
33
|
append_error(:transaction_type, "transaction_type must be supplied") if self.transaction_type.blank?
|
38
34
|
|
39
35
|
# need to authenticate
|
40
36
|
append_error(:gateway_id, "gateway_id must be supplied") if self.gateway_id.blank?
|
41
37
|
append_error(:password, "password must be supplied") if self.password.blank?
|
42
38
|
|
39
|
+
validate_lengths
|
40
|
+
|
41
|
+
if self.transaction_type == "CR"
|
42
|
+
append_error(:transaction_tag, "transaction_tag must be supplied") if self.transaction_tag.to_i < 1
|
43
|
+
elsif %w(50 54).include?(self.transaction_type)
|
44
|
+
validate_for_pan
|
45
|
+
elsif !self.transaction_tag.blank?
|
46
|
+
validate_for_transaction_tag
|
47
|
+
elsif !self.cc_number.blank?
|
48
|
+
validate_for_cc_number
|
49
|
+
elsif !self.track1.blank?
|
50
|
+
validate_for_track1
|
51
|
+
elsif !self.track2.blank?
|
52
|
+
validate_for_track2
|
53
|
+
else
|
54
|
+
append_error(:base, "One of the following must be supplied: cc_number, track1, track2 or transaction_tag.")
|
55
|
+
end
|
56
|
+
|
43
57
|
# ensure we've been given valid amounts
|
44
58
|
append_error(:amount, "invalid amount supplied") unless valid_amount?(self.amount)
|
45
59
|
append_error(:surcharge_amount, "invalid surcharge_amount supplied") unless valid_amount?(self.surcharge_amount)
|
@@ -67,21 +81,6 @@ module EWS # :nodoc:
|
|
67
81
|
end
|
68
82
|
end
|
69
83
|
|
70
|
-
# which fields are mandatory and which optional depends on the transaction_type and
|
71
|
-
# also how the credit card information is supplied.
|
72
|
-
#
|
73
|
-
# it can be supplied either
|
74
|
-
# a) via the cc_number field
|
75
|
-
# b) via a tagged transaction
|
76
|
-
# c) encoded in a track1 value, or
|
77
|
-
# d) encoded in a track2 value
|
78
|
-
def validate_mandatory_fields
|
79
|
-
validate_for_card unless self.cc_number.blank?
|
80
|
-
validate_for_transaction_tag unless self.transaction_tag.blank?
|
81
|
-
validate_for_track1 unless self.track1.blank?
|
82
|
-
validate_for_track2 unless self.track2.blank?
|
83
|
-
end
|
84
|
-
|
85
84
|
def valid_amount?(amount)
|
86
85
|
return true if amount.blank?
|
87
86
|
|
@@ -143,19 +142,15 @@ module EWS # :nodoc:
|
|
143
142
|
end
|
144
143
|
|
145
144
|
# validate presence of mandatory fields when cc_number present
|
146
|
-
def
|
145
|
+
def validate_for_cc_number
|
147
146
|
tt = self.transaction_type.to_i
|
148
147
|
|
149
148
|
# mandatory: transaction_type must != (30, 31, 32, 34, 35)
|
150
149
|
append_error(:cc_number, "cc_number must not be set for tagged transactions") if [30,31,32,34,35].include?(tt)
|
150
|
+
append_error(:cc_number, "cc_number must not be set for debit transactions") if [50,54].include?(tt)
|
151
151
|
|
152
152
|
# amount, cardholder_name always mandaory
|
153
|
-
mandatory = [:amount, :cardholder_name]
|
154
|
-
|
155
|
-
# card_number & expiry_date mandatory for all except 50, 54
|
156
|
-
# pan mandatory for only 50, 54
|
157
|
-
mandatory << ([50,54].include?(tt) ? :pan : [:cc_number, :cc_expiry])
|
158
|
-
mandatory.flatten!
|
153
|
+
mandatory = [:amount, :cardholder_name, :cc_number, :cc_expiry]
|
159
154
|
|
160
155
|
# reference_no mandatory for 60
|
161
156
|
mandatory << :reference_no if tt == 60
|
@@ -176,6 +171,11 @@ module EWS # :nodoc:
|
|
176
171
|
mandatory = [:transaction_tag]
|
177
172
|
mandatory << [:authorization_num, :amount] unless tt == 'CR'
|
178
173
|
|
174
|
+
# ensure no cc details sent
|
175
|
+
append_error(:cc_number, "do not set cc_number for tagged transactions") unless self.cc_number.blank?
|
176
|
+
append_error(:cc_expiry, "do not set cc_expiry for tagged transactions") unless self.cc_expiry.blank?
|
177
|
+
append_error(:cardholder_name, "do not set cardholder_name for tagged transactions") unless self.cardholder_name.blank?
|
178
|
+
|
179
179
|
check_mandatory(mandatory.flatten)
|
180
180
|
end
|
181
181
|
|
@@ -184,13 +184,10 @@ module EWS # :nodoc:
|
|
184
184
|
|
185
185
|
# mandatory: transaction_type must != (30, 31, 32, 34, 35)
|
186
186
|
append_error(:track1, "track1 must not be set for tagged transactions") if [30,31,32,34,35].include?(tt)
|
187
|
+
append_error(:track1, "track1 must not be set for debit transactions") if [50,54].include?(tt)
|
187
188
|
|
188
189
|
# amount mandatory for all
|
189
|
-
mandatory = [:amount]
|
190
|
-
|
191
|
-
# track1 mandatory, except 50,54
|
192
|
-
# pan mandatory 50,54 only
|
193
|
-
mandatory << ([50,54].include?(tt) ? :pan : :track1)
|
190
|
+
mandatory = [:track1, :amount]
|
194
191
|
|
195
192
|
# reference_no mandatory for 60
|
196
193
|
mandatory << :reference_no if tt == 60
|
@@ -204,10 +201,11 @@ module EWS # :nodoc:
|
|
204
201
|
tt = self.transaction_type.to_i
|
205
202
|
|
206
203
|
# mandatory: transaction_type must != (30, 31, 32, 34, 35, 50, 54)
|
207
|
-
append_error(:track2, "track2 must not be set for tagged transactions") if [30,31,32,34,35
|
204
|
+
append_error(:track2, "track2 must not be set for tagged transactions") if [30,31,32,34,35].include?(tt)
|
205
|
+
append_error(:track2, "track2 must not be set for debit transactions") if [50,54].include?(tt)
|
208
206
|
|
209
207
|
# track2, expiry_date, cardholder_name, amount mandatory
|
210
|
-
mandatory = [:track2, :
|
208
|
+
mandatory = [:track2, :cardholder_name, :amount]
|
211
209
|
|
212
210
|
# auth_number mandatory for (02, 03, 11, 12, 13)
|
213
211
|
mandatory << :authorization_num if [02, 03, 11, 12, 13].include?(tt)
|
@@ -215,9 +213,21 @@ module EWS # :nodoc:
|
|
215
213
|
check_mandatory(mandatory)
|
216
214
|
end
|
217
215
|
|
216
|
+
def validate_for_pan
|
217
|
+
tt = self.transaction_type.to_i
|
218
|
+
|
219
|
+
# mandatory: transaction_type must == (50, 54)
|
220
|
+
append_error(:pan, "pan must not be set for non-debit transactions") unless [50,54].include?(tt)
|
221
|
+
|
222
|
+
# track2, expiry_date, cardholder_name, amount mandatory
|
223
|
+
mandatory = [:pan, :cardholder_name, :amount]
|
224
|
+
|
225
|
+
check_mandatory(mandatory)
|
226
|
+
end
|
227
|
+
|
218
228
|
def check_mandatory(mandatory)
|
219
229
|
mandatory.each do |key|
|
220
|
-
append_error(key, "#{key}
|
230
|
+
append_error(key, "#{key} must be supplied") if self.send(key).blank?
|
221
231
|
end
|
222
232
|
end
|
223
233
|
end
|
data/lib/ews/transporter.rb
CHANGED
@@ -40,19 +40,19 @@ module EWS # :nodoc:
|
|
40
40
|
# <tt>transaction</tt>:: the Request object to encode for transmission to the server
|
41
41
|
# <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
|
42
42
|
def submit(transaction, transport_type = nil)
|
43
|
-
raise "Request not supplied" if transaction.nil?
|
43
|
+
raise ArgumentError, "Request not supplied" if transaction.nil?
|
44
44
|
return false unless transaction.valid?
|
45
45
|
|
46
46
|
transport_type ||= @transport_type
|
47
47
|
|
48
|
-
raise "Transport type #{transport_type} is not supported" unless @@transport_types.include? transport_type
|
48
|
+
raise ArgumentError, "Transport type #{transport_type} is not supported" unless @@transport_types.include? transport_type
|
49
49
|
|
50
50
|
transport_details = @@transport_types[transport_type]
|
51
51
|
|
52
52
|
request = build_http_request(transaction, transport_type, transport_details[:suffix])
|
53
53
|
request.basic_auth(transaction.gateway_id, transaction.password)
|
54
54
|
request.add_field "Accept", transport_details[:content_type]
|
55
|
-
request.add_field "User-Agent", "exact4r v0.9"
|
55
|
+
request.add_field "User-Agent", "exact4r v0.9.1"
|
56
56
|
request.add_field "Content-type", "#{transport_details[:content_type]}; charset=UTF-8"
|
57
57
|
|
58
58
|
response = get_connection.request(request)
|
data/lib/exact4r.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
class ForcedPostTest < 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 => :forced_post)
|
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 => :forced_post))
|
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 => :forced_post))
|
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 => :forced_post))
|
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
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
class OnlineDebitPurchaseTest < 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
|
+
end
|
10
|
+
|
11
|
+
def test_mandatory
|
12
|
+
request = EWS::Transaction::Request.new(:transaction_type => :idebit_purchase)
|
13
|
+
assert !request.valid?
|
14
|
+
assert_equal "gateway_id must be supplied", request.errors[:gateway_id]
|
15
|
+
|
16
|
+
request.gateway_id = CHASE_BASIC_AUTH[:gateway_id]
|
17
|
+
assert !request.valid?
|
18
|
+
assert_equal "password must be supplied", request.errors[:password]
|
19
|
+
|
20
|
+
request.password = CHASE_BASIC_AUTH[:password]
|
21
|
+
assert !request.valid?
|
22
|
+
assert_equal "pan must be supplied", request.errors[:pan]
|
23
|
+
|
24
|
+
request.pan = "4111111111111111"
|
25
|
+
assert !request.valid?
|
26
|
+
assert_equal "cardholder_name must be supplied", request.errors[:cardholder_name]
|
27
|
+
|
28
|
+
request.cardholder_name = "Simon Jones"
|
29
|
+
assert !request.valid?
|
30
|
+
assert_equal "amount must be supplied", request.errors[:amount]
|
31
|
+
|
32
|
+
request.amount = 10
|
33
|
+
assert request.valid?
|
34
|
+
end
|
35
|
+
|
36
|
+
# PAN may be specificed as a simple account number...
|
37
|
+
def test_by_pan_as_cc_number
|
38
|
+
request = EWS::Transaction::Request.new({
|
39
|
+
:transaction_type => :idebit_purchase,
|
40
|
+
:amount => 11.25,
|
41
|
+
:pan => TEST_CARD_NUMBER,
|
42
|
+
:cardholder_name => TEST_CARD_HOLDER
|
43
|
+
}.merge(CHASE_BASIC_AUTH))
|
44
|
+
assert request.valid?, request.errors.inspect
|
45
|
+
|
46
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
47
|
+
assert_details_correct request, @transporter.submit(request, :rest)
|
48
|
+
assert_details_correct request, @transporter.submit(request, :soap)
|
49
|
+
end
|
50
|
+
|
51
|
+
# ...or in track2 format
|
52
|
+
def test_by_pan_as_cc_number
|
53
|
+
request = EWS::Transaction::Request.new({
|
54
|
+
:transaction_type => :idebit_purchase,
|
55
|
+
:amount => 11.25,
|
56
|
+
:pan => TEST_TRACK2,
|
57
|
+
:cardholder_name => TEST_CARD_HOLDER
|
58
|
+
}.merge(CHASE_BASIC_AUTH))
|
59
|
+
assert request.valid?, request.errors.inspect
|
60
|
+
|
61
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
62
|
+
assert_details_correct request, @transporter.submit(request, :rest)
|
63
|
+
assert_details_correct request, @transporter.submit(request, :soap)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
class OnlineDebitRefundTest < 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
|
+
end
|
10
|
+
|
11
|
+
def test_mandatory
|
12
|
+
request = EWS::Transaction::Request.new(:transaction_type => :idebit_refund)
|
13
|
+
assert !request.valid?
|
14
|
+
assert_equal "gateway_id must be supplied", request.errors[:gateway_id]
|
15
|
+
|
16
|
+
request.gateway_id = CHASE_BASIC_AUTH[:gateway_id]
|
17
|
+
assert !request.valid?
|
18
|
+
assert_equal "password must be supplied", request.errors[:password]
|
19
|
+
|
20
|
+
request.password = CHASE_BASIC_AUTH[:password]
|
21
|
+
assert !request.valid?
|
22
|
+
assert_equal "pan must be supplied", request.errors[:pan]
|
23
|
+
|
24
|
+
request.pan = "4111111111111111"
|
25
|
+
assert !request.valid?
|
26
|
+
assert_equal "cardholder_name must be supplied", request.errors[:cardholder_name]
|
27
|
+
|
28
|
+
request.cardholder_name = "Simon Jones"
|
29
|
+
assert !request.valid?
|
30
|
+
assert_equal "amount must be supplied", request.errors[:amount]
|
31
|
+
|
32
|
+
request.amount = 10
|
33
|
+
assert request.valid?
|
34
|
+
end
|
35
|
+
|
36
|
+
# PAN may be specificed as a simple account number...
|
37
|
+
def test_by_pan_as_cc_number
|
38
|
+
request = EWS::Transaction::Request.new({
|
39
|
+
:transaction_type => :idebit_refund,
|
40
|
+
:amount => 11.25,
|
41
|
+
:pan => TEST_CARD_NUMBER,
|
42
|
+
:cardholder_name => TEST_CARD_HOLDER
|
43
|
+
}.merge(CHASE_BASIC_AUTH))
|
44
|
+
assert request.valid?, request.errors.inspect
|
45
|
+
|
46
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
47
|
+
assert_details_correct request, @transporter.submit(request, :rest)
|
48
|
+
assert_details_correct request, @transporter.submit(request, :soap)
|
49
|
+
end
|
50
|
+
|
51
|
+
# ...or in track2 format
|
52
|
+
def test_by_pan_as_cc_number
|
53
|
+
request = EWS::Transaction::Request.new({
|
54
|
+
:transaction_type => :idebit_refund,
|
55
|
+
:amount => 11.25,
|
56
|
+
:pan => TEST_TRACK2,
|
57
|
+
:cardholder_name => TEST_CARD_HOLDER
|
58
|
+
}.merge(CHASE_BASIC_AUTH))
|
59
|
+
assert request.valid?, request.errors.inspect
|
60
|
+
|
61
|
+
assert_details_correct request, @transporter.submit(request, :json)
|
62
|
+
assert_details_correct request, @transporter.submit(request, :rest)
|
63
|
+
assert_details_correct request, @transporter.submit(request, :soap)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|