activemerchant 1.2.1 → 1.3.0

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 (206) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +310 -294
  3. data/CONTRIBUTERS +13 -0
  4. data/README +55 -31
  5. data/Rakefile +21 -13
  6. data/lib/active_merchant.rb +7 -0
  7. data/lib/active_merchant/billing/avs_result.rb +95 -0
  8. data/lib/active_merchant/billing/base.rb +8 -3
  9. data/lib/active_merchant/billing/check.rb +61 -0
  10. data/lib/active_merchant/billing/credit_card.rb +104 -80
  11. data/lib/active_merchant/billing/credit_card_formatting.rb +11 -8
  12. data/lib/active_merchant/billing/credit_card_methods.rb +76 -32
  13. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  14. data/lib/active_merchant/billing/expiry_date.rb +28 -0
  15. data/lib/active_merchant/billing/gateway.rb +47 -111
  16. data/lib/active_merchant/billing/gateways/authorize_net.rb +508 -121
  17. data/lib/active_merchant/billing/gateways/bogus.rb +26 -32
  18. data/lib/active_merchant/billing/gateways/brain_tree.rb +82 -70
  19. data/lib/active_merchant/billing/gateways/card_stream.rb +43 -15
  20. data/lib/active_merchant/billing/gateways/cyber_source.rb +9 -29
  21. data/lib/active_merchant/billing/gateways/data_cash.rb +18 -38
  22. data/lib/active_merchant/billing/gateways/efsnet.rb +23 -50
  23. data/lib/active_merchant/billing/gateways/eway.rb +8 -19
  24. data/lib/active_merchant/billing/gateways/exact.rb +17 -25
  25. data/lib/active_merchant/billing/gateways/linkpoint.rb +18 -25
  26. data/lib/active_merchant/billing/gateways/moneris.rb +9 -39
  27. data/lib/active_merchant/billing/gateways/net_registry.rb +113 -182
  28. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  29. data/lib/active_merchant/billing/gateways/pay_junction.rb +52 -73
  30. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  31. data/lib/active_merchant/billing/gateways/payflow.rb +13 -14
  32. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +55 -37
  33. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +4 -0
  34. data/lib/active_merchant/billing/gateways/payflow_express.rb +2 -4
  35. data/lib/active_merchant/billing/gateways/payment_express.rb +11 -30
  36. data/lib/active_merchant/billing/gateways/paypal.rb +3 -14
  37. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +36 -16
  38. data/lib/active_merchant/billing/gateways/paypal_express.rb +1 -2
  39. data/lib/active_merchant/billing/gateways/plugnpay.rb +7 -15
  40. data/lib/active_merchant/billing/gateways/protx.rb +24 -25
  41. data/lib/active_merchant/billing/gateways/psigate.rb +34 -71
  42. data/lib/active_merchant/billing/gateways/psl_card.rb +24 -19
  43. data/lib/active_merchant/billing/gateways/quickpay.rb +10 -24
  44. data/lib/active_merchant/billing/gateways/realex.rb +7 -19
  45. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  46. data/lib/active_merchant/billing/gateways/skip_jack.rb +437 -0
  47. data/lib/active_merchant/billing/gateways/trans_first.rb +5 -14
  48. data/lib/active_merchant/billing/gateways/trust_commerce.rb +100 -39
  49. data/lib/active_merchant/billing/gateways/usa_epay.rb +60 -55
  50. data/lib/active_merchant/billing/gateways/verifi.rb +32 -39
  51. data/lib/active_merchant/billing/gateways/viaklix.rb +31 -37
  52. data/lib/active_merchant/billing/integrations.rb +2 -0
  53. data/lib/active_merchant/billing/integrations/bogus.rb +5 -0
  54. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  55. data/lib/active_merchant/billing/integrations/chronopay.rb +5 -0
  56. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  57. data/lib/active_merchant/billing/integrations/gestpay.rb +5 -0
  58. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  59. data/lib/active_merchant/billing/integrations/hi_trust.rb +26 -0
  60. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  61. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +57 -0
  62. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  63. data/lib/active_merchant/billing/integrations/nochex.rb +5 -0
  64. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  65. data/lib/active_merchant/billing/integrations/paypal.rb +5 -0
  66. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  67. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  68. data/lib/active_merchant/billing/integrations/two_checkout.rb +5 -0
  69. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  70. data/lib/active_merchant/billing/response.rb +12 -8
  71. data/lib/active_merchant/lib/posts_data.rb +39 -7
  72. data/lib/active_merchant/lib/requires_parameters.rb +2 -3
  73. data/lib/active_merchant/lib/utils.rb +18 -0
  74. data/lib/active_merchant/lib/validateable.rb +3 -3
  75. data/lib/support/gateway_support.rb +22 -9
  76. data/script/destroy +14 -0
  77. data/script/generate +7 -7
  78. data/test/fixtures.yml +25 -3
  79. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  80. data/test/remote/gateways/remote_brain_tree_test.rb +118 -0
  81. data/test/{remote_tests → remote/gateways}/remote_card_stream_test.rb +56 -68
  82. data/test/{remote_tests → remote/gateways}/remote_cyber_source_test.rb +21 -32
  83. data/test/{remote_tests → remote/gateways}/remote_data_cash_test.rb +2 -2
  84. data/test/{remote_tests → remote/gateways}/remote_efsnet_test.rb +22 -34
  85. data/test/{remote_tests → remote/gateways}/remote_eway_test.rb +18 -15
  86. data/test/{remote_tests → remote/gateways}/remote_exact_test.rb +20 -19
  87. data/test/{remote_tests → remote/gateways}/remote_linkpoint_test.rb +31 -63
  88. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  89. data/test/{remote_tests → remote/gateways}/remote_net_registry_test.rb +19 -54
  90. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  91. data/test/{remote_tests → remote/gateways}/remote_pay_junction_test.rb +41 -60
  92. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  93. data/test/{remote_tests → remote/gateways}/remote_payflow_express_test.rb +2 -2
  94. data/test/{remote_tests → remote/gateways}/remote_payflow_test.rb +34 -38
  95. data/test/{remote_tests → remote/gateways}/remote_payflow_uk_test.rb +13 -12
  96. data/test/{remote_tests → remote/gateways}/remote_payment_express_test.rb +26 -36
  97. data/test/{remote_tests → remote/gateways}/remote_paypal_express_test.rb +3 -3
  98. data/test/{remote_tests → remote/gateways}/remote_paypal_test.rb +25 -21
  99. data/test/{remote_tests → remote/gateways}/remote_plugnpay_test.rb +18 -16
  100. data/test/{remote_tests → remote/gateways}/remote_protx_test.rb +33 -33
  101. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  102. data/test/{remote_tests → remote/gateways}/remote_psl_card_test.rb +27 -26
  103. data/test/{remote_tests → remote/gateways}/remote_quickpay_test.rb +48 -48
  104. data/test/{remote_tests → remote/gateways}/remote_realex_test.rb +30 -33
  105. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  106. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  107. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  108. data/test/{remote_tests → remote/gateways}/remote_trans_first_test.rb +7 -10
  109. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  110. data/test/{remote_tests → remote/gateways}/remote_usa_epay_test.rb +11 -22
  111. data/test/{remote_tests → remote/gateways}/remote_verifi_test.rb +27 -27
  112. data/test/{remote_tests → remote/gateways}/remote_viaklix_test.rb +8 -18
  113. data/test/{remote_tests → remote/integrations}/remote_gestpay_integration_test.rb +1 -1
  114. data/test/{remote_tests → remote/integrations}/remote_paypal_integration_test.rb +1 -1
  115. data/test/test_helper.rb +102 -61
  116. data/test/unit/avs_result_test.rb +59 -0
  117. data/test/unit/base_test.rb +33 -39
  118. data/test/unit/check_test.rb +76 -0
  119. data/test/unit/credit_card_formatting_test.rb +10 -15
  120. data/test/unit/credit_card_methods_test.rb +132 -17
  121. data/test/unit/credit_card_test.rb +157 -228
  122. data/test/unit/cvv_result_test.rb +33 -0
  123. data/test/unit/expiry_date_test.rb +21 -0
  124. data/test/unit/gateways/authorize_net_test.rb +180 -40
  125. data/test/unit/gateways/bogus_test.rb +2 -3
  126. data/test/unit/gateways/brain_tree_test.rb +63 -29
  127. data/test/unit/gateways/card_stream_test.rb +59 -6
  128. data/test/unit/gateways/cyber_source_test.rb +59 -40
  129. data/test/unit/gateways/data_cash_test.rb +82 -1
  130. data/test/unit/gateways/efsnet_test.rb +97 -44
  131. data/test/unit/gateways/eway_test.rb +55 -42
  132. data/test/unit/gateways/exact_test.rb +93 -55
  133. data/test/unit/gateways/gateway_test.rb +7 -0
  134. data/test/unit/gateways/linkpoint_test.rb +60 -58
  135. data/test/unit/gateways/moneris_test.rb +67 -76
  136. data/test/unit/gateways/net_registry_test.rb +351 -419
  137. data/test/unit/gateways/netbilling_test.rb +54 -0
  138. data/test/unit/gateways/pay_junction_test.rb +108 -46
  139. data/test/unit/gateways/pay_secure_test.rb +71 -0
  140. data/test/unit/gateways/payflow_express_test.rb +0 -8
  141. data/test/unit/gateways/payflow_test.rb +136 -65
  142. data/test/unit/gateways/payflow_uk_test.rb +0 -38
  143. data/test/unit/gateways/payment_express_test.rb +31 -51
  144. data/test/unit/gateways/paypal_express_test.rb +8 -2
  145. data/test/unit/gateways/paypal_test.rb +213 -54
  146. data/test/unit/gateways/plugnpay_test.rb +39 -32
  147. data/test/unit/gateways/protx_test.rb +45 -33
  148. data/test/unit/gateways/psigate_test.rb +146 -87
  149. data/test/unit/gateways/psl_card_test.rb +37 -24
  150. data/test/unit/gateways/quickpay_test.rb +33 -46
  151. data/test/unit/gateways/realex_test.rb +32 -31
  152. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  153. data/test/unit/gateways/secure_pay_test.rb +35 -26
  154. data/test/unit/gateways/skip_jack_test.rb +125 -0
  155. data/test/unit/gateways/trans_first_test.rb +24 -37
  156. data/test/unit/gateways/trust_commerce_test.rb +47 -26
  157. data/test/unit/gateways/usa_epay_test.rb +52 -41
  158. data/test/unit/gateways/verifi_test.rb +41 -35
  159. data/test/unit/gateways/viaklix_test.rb +38 -32
  160. data/test/unit/generators/test_gateway_generator.rb +46 -0
  161. data/test/unit/generators/test_generator_helper.rb +20 -0
  162. data/test/unit/generators/test_integration_generator.rb +53 -0
  163. data/test/unit/integrations/action_view_helper_test.rb +7 -14
  164. data/test/unit/integrations/bogus_module_test.rb +4 -0
  165. data/test/unit/integrations/chronopay_module_test.rb +4 -0
  166. data/test/unit/integrations/gestpay_module_test.rb +4 -0
  167. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  168. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  169. data/test/unit/integrations/nochex_module_test.rb +4 -0
  170. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +38 -0
  171. data/test/unit/integrations/paypal_module_test.rb +4 -0
  172. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  173. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  174. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  175. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  176. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  177. data/test/unit/integrations/returns/return_test.rb +11 -0
  178. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  179. data/test/unit/integrations/two_checkout_module_test.rb +4 -0
  180. data/test/unit/posts_data_test.rb +86 -0
  181. data/test/unit/response_test.rb +15 -1
  182. data/test/unit/utils_test.rb +7 -0
  183. data/test/unit/validateable_test.rb +10 -6
  184. metadata +180 -142
  185. metadata.gz.sig +0 -0
  186. data/lib/active_merchant/billing/gateways/paypal/api_cert_chain.crt +0 -35
  187. data/script/generator/base.rb +0 -45
  188. data/script/generator/generator.rb +0 -24
  189. data/script/generator/generators/gateway/gateway_generator.rb +0 -14
  190. data/script/generator/generators/gateway/templates/gateway.rb +0 -73
  191. data/script/generator/generators/gateway/templates/gateway_test.rb +0 -41
  192. data/script/generator/generators/gateway/templates/remote_gateway_test.rb +0 -56
  193. data/script/generator/generators/integration/integration_generator.rb +0 -25
  194. data/script/generator/generators/integration/templates/helper.rb +0 -34
  195. data/script/generator/generators/integration/templates/helper_test.rb +0 -54
  196. data/script/generator/generators/integration/templates/integration.rb +0 -18
  197. data/script/generator/generators/integration/templates/module_test.rb +0 -9
  198. data/script/generator/generators/integration/templates/notification.rb +0 -100
  199. data/script/generator/generators/integration/templates/notification_test.rb +0 -41
  200. data/script/generator/manifest.rb +0 -20
  201. data/test/remote_tests/remote_authorize_net_test.rb +0 -113
  202. data/test/remote_tests/remote_brain_tree_test.rb +0 -78
  203. data/test/remote_tests/remote_moneris_test.rb +0 -110
  204. data/test/remote_tests/remote_psigate_test.rb +0 -87
  205. data/test/remote_tests/remote_secure_pay_test.rb +0 -36
  206. data/test/remote_tests/remote_trust_commerce_test.rb +0 -136
@@ -0,0 +1,125 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class SkipJackTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Base.gateway_mode = :test
7
+
8
+ @gateway = SkipJackGateway.new(:login => 'X', :password => 'Y')
9
+
10
+ @credit_card = credit_card('4242424242424242')
11
+
12
+ @billing_address = {
13
+ :address1 => '123 Any St.',
14
+ :address2 => 'Apt. B',
15
+ :city => 'Anytown',
16
+ :state => 'ST',
17
+ :country => 'US',
18
+ :zip => '51511-1234',
19
+ :phone => '616-555-1212',
20
+ :fax => '616-555-2121'
21
+ }
22
+
23
+ @shipping_address = {
24
+ :name => 'Stew Packman',
25
+ :address1 => 'Company',
26
+ :address2 => '321 No RD',
27
+ :city => 'Nowhereton',
28
+ :state => 'ZC',
29
+ :country => 'MX',
30
+ :phone => '0123231212'
31
+ }
32
+
33
+ @options = {
34
+ :order_id => 1,
35
+ :email => 'cody@example.com'
36
+ }
37
+
38
+ @amount = 100
39
+ end
40
+
41
+ def test_authorization_success
42
+ @gateway.expects(:ssl_post).returns(successful_authorization_response)
43
+
44
+ assert response = @gateway.authorize(@amount, @credit_card, @options)
45
+ assert_instance_of Response, response
46
+ assert_success response
47
+ assert_equal '9802853155172.022', response.authorization
48
+ end
49
+
50
+ def test_authorization_failure
51
+ @gateway.expects(:ssl_post).returns(unsuccessful_authorization_response)
52
+
53
+ assert response = @gateway.authorize(@amount, @credit_card, @options)
54
+ assert_instance_of Response, response
55
+ assert_failure response
56
+ end
57
+
58
+ def test_purchase_success
59
+ @gateway.expects(:ssl_post).times(2).returns(successful_authorization_response, successful_capture_response)
60
+
61
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
62
+ assert_success response
63
+ assert_equal "9802853155172.022", response.authorization
64
+ end
65
+
66
+ def test_split_line
67
+ keys = @gateway.send(:split_line, '"AUTHCODE","szSerialNumber","szTransactionAmount","szAuthorizationDeclinedMessage","szAVSResponseCode","szAVSResponseMessage","szOrderNumber","szAuthorizationResponseCode","szIsApproved","szCVV2ResponseCode","szCVV2ResponseMessage","szReturnCode","szTransactionFileName","szCAVVResponseCode"')
68
+
69
+ values = @gateway.send(:split_line, '"000067","999888777666","1900","","N","Card authorized, exact address match with 5 digit zipcode.","1","000067","1","","","1","10138083786558.009",""')
70
+
71
+ assert_equal keys.size, values.size
72
+
73
+ keyvals = keys.zip(values).flatten
74
+ map = Hash[*keyvals]
75
+
76
+ assert_equal '000067', map['AUTHCODE']
77
+ end
78
+
79
+ def test_turn_authorizeapi_response_into_hash
80
+ body = <<-EOS
81
+ "AUTHCODE","szSerialNumber","szTransactionAmount","szAuthorizationDeclinedMessage","szAVSResponseCode","szAVSResponseMessage","szOrderNumber","szAuthorizationResponseCode","szIsApproved","szCVV2ResponseCode","szCVV2ResponseMessage","szReturnCode","szTransactionFileName","szCAVVResponseCode"
82
+ "000067","999888777666","1900","","N","Card authorized, exact address match with 5 digit zipcode.","1","000067","1","","","1","10138083786558.009",""
83
+ EOS
84
+
85
+ map = @gateway.send(:authorize_response_map, body)
86
+
87
+ assert_equal 14, map.keys.size
88
+ assert_equal '10138083786558.009', map[:szTransactionFileName]
89
+ end
90
+
91
+ def test_avs_result
92
+ @gateway.expects(:ssl_post).returns(successful_authorization_response)
93
+
94
+ response = @gateway.authorize(@amount, @credit_card, @options)
95
+ assert_equal 'Y', response.avs_result['code']
96
+ end
97
+
98
+ def test_cvv_result
99
+ @gateway.expects(:ssl_post).returns(successful_authorization_response)
100
+
101
+ response = @gateway.authorize(@amount, @credit_card, @options)
102
+ assert_equal 'M', response.cvv_result['code']
103
+ end
104
+
105
+ private
106
+ def successful_authorization_response
107
+ <<-CSV
108
+ "AUTHCODE","szSerialNumber","szTransactionAmount","szAuthorizationDeclinedMessage","szAVSResponseCode","szAVSResponseMessage","szOrderNumber","szAuthorizationResponseCode","szIsApproved","szCVV2ResponseCode","szCVV2ResponseMessage","szReturnCode","szTransactionFileName","szCAVVResponseCode"
109
+ "TAS204","000386891209","100","","Y","Card authorized, exact address match with 5 digit zip code.","107a0fdb21ba42cf04f60274908085ea","TAS204","1","M","Match","1","9802853155172.022",""
110
+ CSV
111
+ end
112
+
113
+ def successful_capture_response
114
+ <<-CSV
115
+ "000386891209","0","1","","","","","","","","",""
116
+ "000386891209","1.0000","SETTLE","SUCCESSFUL","Valid","618844630c5fad658e95abfd5e1d4e22","9802853156029.022"
117
+ CSV
118
+ end
119
+
120
+ def unsuccessful_authorization_response
121
+ <<-CSV
122
+ "AUTHCODE","szSerialNumber","szTransactionAmount","szAuthorizationDeclinedMessage","szAVSResponseCode","szAVSResponseMessage","szOrderNumber","szAuthorizationResponseCode","szIsApproved","szCVV2ResponseCode","szCVV2ResponseMessage","szReturnCode","szTransactionFileName","szCAVVResponseCode"\r\n"EMPTY","000386891209","100","","","","b1eec256d0182f29375e0cbae685092d","","0","","","-35","",""
123
+ CSV
124
+ end
125
+ end
@@ -1,7 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  class TransFirstTest < Test::Unit::TestCase
4
- AMOUNT = 100
5
4
 
6
5
  def setup
7
6
  @gateway = TransFirstGateway.new(
@@ -9,43 +8,17 @@ class TransFirstTest < Test::Unit::TestCase
9
8
  :password => 'PASSWORD'
10
9
  )
11
10
 
12
- @creditcard = credit_card('4242424242424242')
13
-
14
- @address = { :address1 => '1234 My Street',
15
- :address2 => 'Apt 1',
16
- :company => 'Widgets Inc',
17
- :city => 'Ottawa',
18
- :state => 'ON',
19
- :zip => 'K1C2N6',
20
- :country => 'Canada',
21
- :phone => '(555)555-5555'
22
- }
23
- end
24
-
25
- def test_successful_request
26
- @creditcard.number = 1
27
- assert response = @gateway.purchase(AMOUNT, @creditcard, {})
28
- assert_success response
29
- assert_equal '5555', response.authorization
30
- assert response.test?
31
- end
32
-
33
- def test_unsuccessful_request
34
- @creditcard.number = 2
35
- assert response = @gateway.purchase(AMOUNT, @creditcard, {})
36
- assert_failure response
37
- assert response.test?
38
- end
39
-
40
- def test_request_error
41
- @creditcard.number = 3
42
- assert_raise(Error){ @gateway.purchase(AMOUNT, @creditcard, {}) }
11
+ @credit_card = credit_card('4242424242424242')
12
+ @options = {
13
+ :billing_address => address
14
+ }
15
+ @amount = 100
43
16
  end
44
17
 
45
18
  def test_missing_field_response
46
19
  @gateway.stubs(:ssl_post).returns(missing_field_response)
47
20
 
48
- response = @gateway.purchase(AMOUNT, @creditcard)
21
+ response = @gateway.purchase(@amount, @credit_card, @options)
49
22
 
50
23
  assert_failure response
51
24
  assert response.test?
@@ -55,7 +28,7 @@ class TransFirstTest < Test::Unit::TestCase
55
28
  def test_successful_purchase
56
29
  @gateway.stubs(:ssl_post).returns(successful_purchase_response)
57
30
 
58
- response = @gateway.purchase(AMOUNT, @creditcard)
31
+ response = @gateway.purchase(@amount, @credit_card, @options)
59
32
 
60
33
  assert_success response
61
34
  assert response.test?
@@ -66,7 +39,7 @@ class TransFirstTest < Test::Unit::TestCase
66
39
  def test_failed_purchase
67
40
  @gateway.stubs(:ssl_post).returns(failed_purchase_response)
68
41
 
69
- response = @gateway.purchase(AMOUNT, @creditcard)
42
+ response = @gateway.purchase(@amount, @credit_card, @options)
70
43
 
71
44
  assert_failure response
72
45
  assert response.test?
@@ -74,6 +47,20 @@ class TransFirstTest < Test::Unit::TestCase
74
47
  assert_equal 'Invalid cardholder number', response.message
75
48
  end
76
49
 
50
+ def test_avs_result
51
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
52
+
53
+ response = @gateway.purchase(@amount, @credit_card, @options)
54
+ assert_equal 'X', response.avs_result['code']
55
+ end
56
+
57
+ def test_cvv_result
58
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
59
+
60
+ response = @gateway.purchase(@amount, @credit_card, @options)
61
+ assert_equal 'M', response.cvv_result['code']
62
+ end
63
+
77
64
  private
78
65
  def missing_field_response
79
66
  "Missing parameter: UserId.\r\n"
@@ -88,9 +75,9 @@ class TransFirstTest < Test::Unit::TestCase
88
75
  <Amount>1.00</Amount>
89
76
  <AuthCode>Test00</AuthCode>
90
77
  <Status>Authorized</Status>
91
- <AVSCode />
78
+ <AVSCode>X</AVSCode>
92
79
  <Message>test transaction</Message>
93
- <CVV2Code />
80
+ <CVV2Code>M</CVV2Code>
94
81
  <ACI />
95
82
  <AuthSource />
96
83
  <TransactionIdentifier />
@@ -2,41 +2,30 @@ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  class TrustCommerceTest < Test::Unit::TestCase
4
4
  def setup
5
- #TCLink rescue NameError assert false, 'Trust Commerce test cases require "tclink" library from http://www.trustcommerce.com/tclink.html'
6
-
7
5
  @gateway = TrustCommerceGateway.new(
8
6
  :login => 'TestMerchant',
9
7
  :password => 'password'
10
8
  )
9
+ # Force SSL post
10
+ @gateway.stubs(:tclink?).returns(false)
11
11
 
12
- @creditcard = credit_card('4111111111111111')
13
- end
14
-
15
- def test_purchase_success
16
- @creditcard.number = '1'
17
-
18
- assert response = @gateway.purchase(100, @creditcard, :demo => 'y')
19
- assert_equal Response, response.class
20
- assert_equal '#0001', response.params['receiptid']
21
- assert_equal true, response.success?
12
+ @amount = 100
13
+ @credit_card = credit_card('4111111111111111')
22
14
  end
23
15
 
24
- def test_purchase_error
25
- @creditcard.number = '2'
26
-
27
- assert response = @gateway.purchase(100, @creditcard, :demo => 'y')
28
- assert_equal Response, response.class
29
- assert_equal '#0001', response.params['receiptid']
30
- assert_equal false, response.success?
31
-
16
+ def test_successful_purchase
17
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
18
+ assert response = @gateway.purchase(@amount, @credit_card)
19
+ assert_instance_of Response, response
20
+ assert_success response
21
+ assert_equal '025-0007423614', response.authorization
32
22
  end
33
23
 
34
- def test_purchase_exceptions
35
- @creditcard.number = '3'
36
-
37
- assert_raise(Error) do
38
- assert response = @gateway.purchase(100, @creditcard, :demo => 'y')
39
- end
24
+ def test_unsuccessful_purchase
25
+ @gateway.expects(:ssl_post).returns(unsuccessful_purchase_response)
26
+ assert response = @gateway.purchase(@amount, @credit_card)
27
+ assert_instance_of Response, response
28
+ assert_failure response
40
29
  end
41
30
 
42
31
  def test_amount_style
@@ -47,6 +36,20 @@ class TrustCommerceTest < Test::Unit::TestCase
47
36
  end
48
37
  end
49
38
 
39
+ def test_avs_result
40
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
41
+
42
+ response = @gateway.purchase(@amount, @credit_card)
43
+ assert_equal 'Y', response.avs_result['code']
44
+ end
45
+
46
+ def test_cvv_result
47
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
48
+
49
+ response = @gateway.purchase(@amount, @credit_card)
50
+ assert_equal 'P', response.cvv_result['code']
51
+ end
52
+
50
53
  def test_supported_countries
51
54
  assert_equal ['US'], TrustCommerceGateway.supported_countries
52
55
  end
@@ -54,4 +57,22 @@ class TrustCommerceTest < Test::Unit::TestCase
54
57
  def test_supported_card_types
55
58
  assert_equal [:visa, :master, :discover, :american_express, :diners_club, :jcb], TrustCommerceGateway.supported_cardtypes
56
59
  end
60
+
61
+ def successful_purchase_response
62
+ <<-RESPONSE
63
+ transid=025-0007423614
64
+ status=approved
65
+ avs=Y
66
+ cvv=P
67
+ RESPONSE
68
+ end
69
+
70
+ def unsuccessful_purchase_response
71
+ <<-RESPONSE
72
+ transid=025-0007423827
73
+ declinetype=cvv
74
+ status=decline
75
+ cvv=N
76
+ RESPONSE
77
+ end
57
78
  end
@@ -3,42 +3,34 @@ require File.dirname(__FILE__) + '/../../test_helper'
3
3
  class UsaEpayTest < Test::Unit::TestCase
4
4
  def setup
5
5
  @gateway = UsaEpayGateway.new(
6
- :login => 'LOGIN'
7
- )
6
+ :login => 'LOGIN'
7
+ )
8
8
 
9
- @creditcard = credit_card('4242424242424242')
10
-
11
- @address = { :address1 => '1234 My Street',
12
- :address2 => 'Apt 1',
13
- :company => 'Widgets Inc',
14
- :city => 'Ottawa',
15
- :state => 'ON',
16
- :zip => 'K1C2N6',
17
- :country => 'Canada',
18
- :phone => '(555)555-5555'
19
- }
9
+ @credit_card = credit_card('4242424242424242')
10
+ @options = {
11
+ :billing_address => address,
12
+ :shipping_address => address
13
+ }
14
+ @amount = 100
20
15
  end
21
16
 
22
17
  def test_successful_request
23
- @creditcard.number = 1
24
- assert response = @gateway.purchase(100, @creditcard, {})
18
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
19
+
20
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
25
21
  assert_success response
26
- assert_equal '5555', response.authorization
22
+ assert_equal '55074409', response.authorization
27
23
  assert response.test?
28
24
  end
29
25
 
30
26
  def test_unsuccessful_request
31
- @creditcard.number = 2
32
- assert response = @gateway.purchase(100, @creditcard, {})
27
+ @gateway.expects(:ssl_post).returns(unsuccessful_purchase_response)
28
+
29
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
33
30
  assert_failure response
34
31
  assert response.test?
35
32
  end
36
33
 
37
- def test_request_error
38
- @creditcard.number = 3
39
- assert_raise(Error){ @gateway.purchase(100, @creditcard, {}) }
40
- end
41
-
42
34
  def test_address_key_prefix
43
35
  assert_equal 'bill', @gateway.send(:address_key_prefix, :billing)
44
36
  assert_equal 'ship', @gateway.send(:address_key_prefix, :shipping)
@@ -51,26 +43,21 @@ class UsaEpayTest < Test::Unit::TestCase
51
43
 
52
44
  def test_add_address
53
45
  post = {}
54
- options = { :address => @address }
55
- @gateway.send(:add_address, post, @creditcard, options)
46
+ @gateway.send(:add_address, post, @credit_card, @options)
56
47
  assert_address(:shipping, post)
57
48
  assert_equal 20, post.keys.size
58
49
  end
59
50
 
60
51
  def test_add_billing_address
61
52
  post = {}
62
- options = { :billing_address => @address }
63
- @gateway.send(:add_address, post, @creditcard, options)
53
+ @gateway.send(:add_address, post, @credit_card, @options)
64
54
  assert_address(:billing, post)
65
55
  assert_equal 20, post.keys.size
66
56
  end
67
57
 
68
58
  def test_add_billing_and_shipping_addresses
69
59
  post = {}
70
- options = { :address => @address,
71
- :billing_address => @address
72
- }
73
- @gateway.send(:add_address, post, @creditcard, options)
60
+ @gateway.send(:add_address, post, @credit_card, @options)
74
61
  assert_address(:shipping, post)
75
62
  assert_address(:billing, post)
76
63
  assert_equal 20, post.keys.size
@@ -91,20 +78,36 @@ class UsaEpayTest < Test::Unit::TestCase
91
78
  def test_supported_card_types
92
79
  assert_equal [:visa, :master, :american_express], UsaEpayGateway.supported_cardtypes
93
80
  end
81
+
82
+ def test_avs_result
83
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
84
+
85
+ response = @gateway.purchase(@amount, @credit_card, @options)
86
+ assert_equal 'Y', response.avs_result['code']
87
+ assert_equal 'Y', response.avs_result['street_match']
88
+ assert_equal 'Y', response.avs_result['postal_match']
89
+ end
90
+
91
+ def test_cvv_result
92
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
93
+
94
+ response = @gateway.purchase(@amount, @credit_card, @options)
95
+ assert_equal 'M', response.cvv_result['code']
96
+ end
94
97
 
95
98
  private
96
99
  def assert_address(type, post)
97
100
  prefix = key_prefix(type)
98
- assert_equal @creditcard.first_name, post[key(prefix, 'fname')]
99
- assert_equal @creditcard.last_name, post[key(prefix, 'lname')]
100
- assert_equal @address[:company], post[key(prefix, 'company')]
101
- assert_equal @address[:address1], post[key(prefix, 'street')]
102
- assert_equal @address[:address2], post[key(prefix, 'street2')]
103
- assert_equal @address[:city], post[key(prefix, 'city')]
104
- assert_equal @address[:state], post[key(prefix, 'state')]
105
- assert_equal @address[:zip], post[key(prefix, 'zip')]
106
- assert_equal @address[:country], post[key(prefix, 'country')]
107
- assert_equal @address[:phone], post[key(prefix, 'phone')]
101
+ assert_equal @credit_card.first_name, post[key(prefix, 'fname')]
102
+ assert_equal @credit_card.last_name, post[key(prefix, 'lname')]
103
+ assert_equal @options[:billing_address][:company], post[key(prefix, 'company')]
104
+ assert_equal @options[:billing_address][:address1], post[key(prefix, 'street')]
105
+ assert_equal @options[:billing_address][:address2], post[key(prefix, 'street2')]
106
+ assert_equal @options[:billing_address][:city], post[key(prefix, 'city')]
107
+ assert_equal @options[:billing_address][:state], post[key(prefix, 'state')]
108
+ assert_equal @options[:billing_address][:zip], post[key(prefix, 'zip')]
109
+ assert_equal @options[:billing_address][:country], post[key(prefix, 'country')]
110
+ assert_equal @options[:billing_address][:phone], post[key(prefix, 'phone')]
108
111
  end
109
112
 
110
113
  def key_prefix(type)
@@ -114,4 +117,12 @@ class UsaEpayTest < Test::Unit::TestCase
114
117
  def key(prefix, key)
115
118
  @gateway.send(:address_key, prefix, key)
116
119
  end
120
+
121
+ def successful_purchase_response
122
+ "UMversion=2.9&UMstatus=Approved&UMauthCode=001716&UMrefNum=55074409&UMavsResult=Address%3A%20Match%20%26%205%20Digit%20Zip%3A%20Match&UMavsResultCode=YYY&UMcvv2Result=Match&UMcvv2ResultCode=M&UMresult=A&UMvpasResultCode=&UMerror=Approved&UMerrorcode=00000&UMcustnum=&UMbatch=596&UMisDuplicate=N&UMconvertedAmount=&UMconvertedAmountCurrency=840&UMconversionRate=&UMcustReceiptResult=No%20Receipt%20Sent&UMfiller=filled"
123
+ end
124
+
125
+ def unsuccessful_purchase_response
126
+ "UMversion=2.9&UMstatus=Declined&UMauthCode=000000&UMrefNum=55076060&UMavsResult=Address%3A%20Match%20%26%205%20Digit%20Zip%3A%20Match&UMavsResultCode=YYY&UMcvv2Result=Not%20Processed&UMcvv2ResultCode=P&UMvpasResultCode=&UMresult=D&UMerror=Card%20Declined&UMerrorcode=10127&UMbatch=596&UMfiller=filled"
127
+ end
117
128
  end