activemerchant 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +226 -0
  3. data/CONTRIBUTERS +52 -0
  4. data/README +34 -24
  5. data/Rakefile +152 -0
  6. data/gem-public_cert.pem +20 -0
  7. data/init.rb +3 -0
  8. data/lib/active_merchant.rb +3 -1
  9. data/lib/active_merchant/billing/credit_card.rb +21 -17
  10. data/lib/active_merchant/billing/credit_card_methods.rb +17 -19
  11. data/lib/active_merchant/billing/gateway.rb +160 -44
  12. data/lib/active_merchant/billing/gateways.rb +2 -15
  13. data/lib/active_merchant/billing/gateways/authorize_net.rb +21 -21
  14. data/lib/active_merchant/billing/gateways/bogus.rb +6 -6
  15. data/lib/active_merchant/billing/gateways/brain_tree.rb +191 -0
  16. data/lib/active_merchant/billing/gateways/card_stream.rb +207 -0
  17. data/lib/active_merchant/billing/gateways/cyber_source.rb +402 -0
  18. data/lib/active_merchant/billing/gateways/data_cash.rb +41 -97
  19. data/lib/active_merchant/billing/gateways/efsnet.rb +256 -0
  20. data/lib/active_merchant/billing/gateways/eway.rb +77 -29
  21. data/lib/active_merchant/billing/gateways/exact.rb +230 -0
  22. data/lib/active_merchant/billing/gateways/linkpoint.rb +6 -33
  23. data/lib/active_merchant/billing/gateways/moneris.rb +155 -125
  24. data/lib/active_merchant/billing/gateways/net_registry.rb +257 -0
  25. data/lib/active_merchant/billing/gateways/pay_junction.rb +407 -0
  26. data/lib/active_merchant/billing/gateways/payflow.rb +163 -25
  27. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +56 -38
  28. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +10 -1
  29. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +9 -0
  30. data/lib/active_merchant/billing/gateways/payflow_express.rb +36 -11
  31. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +6 -0
  32. data/lib/active_merchant/billing/gateways/payflow_uk.rb +7 -3
  33. data/lib/active_merchant/billing/gateways/payment_express.rb +261 -0
  34. data/lib/active_merchant/billing/gateways/paypal.rb +18 -4
  35. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +31 -15
  36. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +8 -0
  37. data/lib/active_merchant/billing/gateways/paypal_express.rb +33 -8
  38. data/lib/active_merchant/billing/gateways/plugnpay.rb +300 -0
  39. data/lib/active_merchant/billing/gateways/protx.rb +285 -0
  40. data/lib/active_merchant/billing/gateways/psigate.rb +13 -12
  41. data/lib/active_merchant/billing/gateways/psl_card.rb +297 -0
  42. data/lib/active_merchant/billing/gateways/quickpay.rb +197 -0
  43. data/lib/active_merchant/billing/gateways/realex.rb +212 -0
  44. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  45. data/lib/active_merchant/billing/gateways/trans_first.rb +136 -0
  46. data/lib/active_merchant/billing/gateways/trust_commerce.rb +43 -20
  47. data/lib/active_merchant/billing/gateways/usa_epay.rb +6 -5
  48. data/lib/active_merchant/billing/gateways/verifi.rb +235 -0
  49. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  50. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +0 -2
  51. data/lib/active_merchant/billing/integrations/helper.rb +8 -1
  52. data/lib/active_merchant/billing/integrations/nochex.rb +62 -1
  53. data/lib/active_merchant/billing/integrations/nochex/notification.rb +9 -16
  54. data/lib/active_merchant/billing/integrations/notification.rb +1 -1
  55. data/lib/active_merchant/billing/integrations/paypal/helper.rb +59 -46
  56. data/lib/active_merchant/billing/integrations/paypal/notification.rb +14 -47
  57. data/lib/active_merchant/lib/error.rb +4 -0
  58. data/lib/active_merchant/lib/post_data.rb +22 -0
  59. data/lib/active_merchant/lib/posts_data.rb +23 -5
  60. data/lib/active_merchant/lib/requires_parameters.rb +2 -2
  61. data/lib/active_merchant/lib/validateable.rb +1 -1
  62. data/lib/support/gateway_support.rb +45 -0
  63. data/lib/tasks/cia.rb +1 -1
  64. data/script/generate +14 -0
  65. data/script/generator/base.rb +45 -0
  66. data/script/generator/generator.rb +24 -0
  67. data/script/generator/generators/gateway/gateway_generator.rb +14 -0
  68. data/script/generator/generators/gateway/templates/gateway.rb +73 -0
  69. data/script/generator/generators/gateway/templates/gateway_test.rb +41 -0
  70. data/script/generator/generators/gateway/templates/remote_gateway_test.rb +56 -0
  71. data/script/generator/generators/integration/integration_generator.rb +25 -0
  72. data/script/generator/generators/integration/templates/helper.rb +34 -0
  73. data/script/generator/generators/integration/templates/helper_test.rb +54 -0
  74. data/script/generator/generators/integration/templates/integration.rb +18 -0
  75. data/script/generator/generators/integration/templates/module_test.rb +9 -0
  76. data/script/generator/generators/integration/templates/notification.rb +100 -0
  77. data/script/generator/generators/integration/templates/notification_test.rb +41 -0
  78. data/script/generator/manifest.rb +20 -0
  79. data/test/extra/binding_of_caller.rb +80 -0
  80. data/test/extra/breakpoint.rb +547 -0
  81. data/test/fixtures.yml +251 -0
  82. data/test/remote_tests/remote_authorize_net_test.rb +113 -0
  83. data/test/remote_tests/remote_brain_tree_test.rb +78 -0
  84. data/test/remote_tests/remote_card_stream_test.rb +160 -0
  85. data/test/remote_tests/remote_cyber_source_test.rb +130 -0
  86. data/test/remote_tests/remote_data_cash_test.rb +155 -0
  87. data/test/remote_tests/remote_efsnet_test.rb +93 -0
  88. data/test/remote_tests/remote_eway_test.rb +71 -0
  89. data/test/remote_tests/remote_exact_test.rb +59 -0
  90. data/test/remote_tests/remote_gestpay_integration_test.rb +37 -0
  91. data/test/remote_tests/remote_linkpoint_test.rb +144 -0
  92. data/test/remote_tests/remote_moneris_test.rb +110 -0
  93. data/test/remote_tests/remote_net_registry_test.rb +120 -0
  94. data/test/remote_tests/remote_pay_junction_test.rb +162 -0
  95. data/test/remote_tests/remote_payflow_express_test.rb +50 -0
  96. data/test/remote_tests/remote_payflow_test.rb +241 -0
  97. data/test/remote_tests/remote_payflow_uk_test.rb +172 -0
  98. data/test/remote_tests/remote_payment_express_test.rb +136 -0
  99. data/test/remote_tests/remote_paypal_express_test.rb +49 -0
  100. data/test/remote_tests/remote_paypal_integration_test.rb +14 -0
  101. data/test/remote_tests/remote_paypal_test.rb +163 -0
  102. data/test/remote_tests/remote_plugnpay_test.rb +70 -0
  103. data/test/remote_tests/remote_protx_test.rb +184 -0
  104. data/test/remote_tests/remote_psigate_test.rb +87 -0
  105. data/test/remote_tests/remote_psl_card_test.rb +105 -0
  106. data/test/remote_tests/remote_quickpay_test.rb +182 -0
  107. data/test/remote_tests/remote_realex_test.rb +227 -0
  108. data/test/remote_tests/remote_secure_pay_test.rb +36 -0
  109. data/test/remote_tests/remote_trans_first_test.rb +37 -0
  110. data/test/remote_tests/remote_trust_commerce_test.rb +136 -0
  111. data/test/remote_tests/remote_usa_epay_test.rb +57 -0
  112. data/test/remote_tests/remote_verifi_test.rb +107 -0
  113. data/test/remote_tests/remote_viaklix_test.rb +53 -0
  114. data/test/test_helper.rb +132 -0
  115. data/test/unit/base_test.rb +61 -0
  116. data/test/unit/country_code_test.rb +33 -0
  117. data/test/unit/country_test.rb +64 -0
  118. data/test/unit/credit_card_formatting_test.rb +24 -0
  119. data/test/unit/credit_card_methods_test.rb +37 -0
  120. data/test/unit/credit_card_test.rb +365 -0
  121. data/test/unit/gateways/authorize_net_test.rb +140 -0
  122. data/test/unit/gateways/bogus_test.rb +43 -0
  123. data/test/unit/gateways/brain_tree_test.rb +77 -0
  124. data/test/unit/gateways/card_stream_test.rb +37 -0
  125. data/test/unit/gateways/cyber_source_test.rb +151 -0
  126. data/test/unit/gateways/data_cash_test.rb +23 -0
  127. data/test/unit/gateways/efsnet_test.rb +70 -0
  128. data/test/unit/gateways/eway_test.rb +105 -0
  129. data/test/unit/gateways/exact_test.rb +118 -0
  130. data/test/unit/gateways/gateway_test.rb +24 -0
  131. data/test/unit/gateways/linkpoint_test.rb +165 -0
  132. data/test/unit/gateways/moneris_test.rb +167 -0
  133. data/test/unit/gateways/net_registry_test.rb +478 -0
  134. data/test/unit/gateways/pay_junction_test.rb +61 -0
  135. data/test/unit/gateways/payflow_express_test.rb +165 -0
  136. data/test/unit/gateways/payflow_express_uk_test.rb +14 -0
  137. data/test/unit/gateways/payflow_test.rb +230 -0
  138. data/test/unit/gateways/payflow_uk_test.rb +68 -0
  139. data/test/unit/gateways/payment_express_test.rb +215 -0
  140. data/test/unit/gateways/paypal_express_test.rb +222 -0
  141. data/test/unit/gateways/paypal_test.rb +241 -0
  142. data/test/unit/gateways/plugnpay_test.rb +79 -0
  143. data/test/unit/gateways/protx_test.rb +110 -0
  144. data/test/unit/gateways/psigate_test.rb +110 -0
  145. data/test/unit/gateways/psl_card_test.rb +51 -0
  146. data/test/unit/gateways/quickpay_test.rb +125 -0
  147. data/test/unit/gateways/realex_test.rb +150 -0
  148. data/test/unit/gateways/secure_pay_test.rb +78 -0
  149. data/test/unit/gateways/trans_first_test.rb +125 -0
  150. data/test/unit/gateways/trust_commerce_test.rb +57 -0
  151. data/test/unit/gateways/usa_epay_test.rb +117 -0
  152. data/test/unit/gateways/verifi_test.rb +91 -0
  153. data/test/unit/gateways/viaklix_test.rb +72 -0
  154. data/test/unit/integrations/action_view_helper_test.rb +54 -0
  155. data/test/unit/integrations/bogus_module_test.rb +16 -0
  156. data/test/unit/integrations/chronopay_module_test.rb +9 -0
  157. data/test/unit/integrations/gestpay_module_test.rb +10 -0
  158. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  159. data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
  160. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  161. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  162. data/test/unit/integrations/helpers/paypal_helper_test.rb +162 -0
  163. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  164. data/test/unit/integrations/nochex_module_test.rb +9 -0
  165. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  166. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  167. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  168. data/test/unit/integrations/notifications/notification_test.rb +41 -0
  169. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  170. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  171. data/test/unit/integrations/paypal_module_test.rb +24 -0
  172. data/test/unit/integrations/two_checkout_module_test.rb +9 -0
  173. data/test/unit/post_data_test.rb +55 -0
  174. data/test/unit/response_test.rb +14 -0
  175. data/test/unit/validateable_test.rb +56 -0
  176. metadata +160 -7
  177. metadata.gz.sig +0 -0
  178. data/lib/active_merchant/billing/gateways/payflow/f73e89fd.0 +0 -17
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RemoteExactTest < Test::Unit::TestCase
4
+ def setup
5
+
6
+
7
+ @gateway = ExactGateway.new(fixtures(:exact))
8
+
9
+ @credit_card = credit_card("4111111111111111")
10
+
11
+ @options = { :address => { :address1 => "1234 Testing Ave.",
12
+ :zip => "55555" } }
13
+ end
14
+
15
+ def test_successful_purchase
16
+ assert response = @gateway.purchase(100, @credit_card, @options)
17
+ assert_equal "Transaction Normal - VER UNAVAILABLE", response.message
18
+ assert_success response
19
+ end
20
+
21
+ def test_unsuccessful_purchase
22
+ # ask for error 13 response (Amount Error) via dollar amount 5,000 + error
23
+ assert response = @gateway.purchase(501300, @credit_card, @options )
24
+ assert_equal "Transaction Normal - AMOUNT ERR", response.message
25
+ assert_failure response
26
+ end
27
+
28
+ def test_purchase_and_credit
29
+ amount = 100
30
+ assert purchase = @gateway.purchase(amount, @credit_card, @options)
31
+ assert_success purchase
32
+ assert purchase.authorization
33
+ assert credit = @gateway.credit(amount, purchase.authorization)
34
+ assert_success credit
35
+ end
36
+
37
+ def test_authorize_and_capture
38
+ amount = 100
39
+ assert auth = @gateway.authorize(amount, @credit_card, @options)
40
+ assert_success auth
41
+ assert auth.authorization
42
+ assert capture = @gateway.capture(amount, auth.authorization)
43
+ assert_success capture
44
+ end
45
+
46
+ def test_failed_capture
47
+ assert response = @gateway.capture(100, String.new)
48
+ assert_failure response
49
+ assert_match /Precondition Failed/i, response.message
50
+ end
51
+
52
+ def test_invalid_login
53
+ gateway = ExactGateway.new( :login => "NotARealUser",
54
+ :password => "NotARealPassword" )
55
+ assert response = gateway.purchase(100, @credit_card, @options)
56
+ assert_equal "Invalid Logon", response.message
57
+ assert_failure response
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RemoteGestpayIntegrationTest < Test::Unit::TestCase
4
+ include ActiveMerchant::Billing::Integrations
5
+
6
+ def setup
7
+ # Your Gestpay ShopLogin
8
+ @shop_login = 'SHOPLOGIN'
9
+
10
+ @helper = Gestpay::Helper.new('order-500', @shop_login, :amount => '5.00', :currency => 'EUR')
11
+ end
12
+
13
+ def test_get_encryption_string
14
+ # Extra fields don't work yet
15
+ # @helper.customer :first_name => 'Cody', :last_name => 'Fauser', :email => 'codyfauser@gmail.com'
16
+ response = @helper.send(:get_encrypted_string)
17
+ assert !response.blank?
18
+ end
19
+
20
+ def test_get_encryption_string_fails
21
+ @helper = Gestpay::Helper.new('order-500','99999999', :amount => '5.00', :currency => 'EUR')
22
+ assert_raise(StandardError) do
23
+ assert @helper.send(:get_encrypted_string).blank?
24
+ end
25
+ end
26
+
27
+ def test_unknown_shop_for_decryption_request
28
+ assert_raise(StandardError) do
29
+ Gestpay::Notification.new(raw_query_string)
30
+ end
31
+ end
32
+
33
+ private
34
+ def raw_query_string
35
+ "a=900000&b=F7DEB36478FD84760F9134F23C922697272D57DE6D4518EB9B4D468B769D9A3A8071B6EB160B35CB412FC1820C7CC12D17B3141855B1ED55468613702A2E213DDE9DE5B0209E13C416448AE833525959F05693172D7F0656"
36
+ end
37
+ end
@@ -0,0 +1,144 @@
1
+ #
2
+ # In order for this test to pass, a valid store number and PEM file
3
+ # are required. Unfortunately, with LinkPoint YOU CAN'T JUST USE ANY
4
+ # OLD STORE NUMBER. Also, you can't just generate your own PEM file.
5
+ # You'll need to use a special PEM file provided by LinkPoint.
6
+ #
7
+ # Go to http://www.linkpoint.com/support/sup_teststore.asp to set up
8
+ # a test account. Once you receive your test account you can get your
9
+ # pem file by clicking the Support link on the navigation menu and then
10
+ # clicking the Download Center link.
11
+ #
12
+ # You will also want to change your test account's fraud settings
13
+ # while running these tests. Click the admin link at the top of
14
+ # LinkPoint Central. Then click "set lockout times" under Fraud Settings
15
+ # You will want to set Duplicate lockout time to 0 so that you can run
16
+ # the tests more than once without triggering this fraud detection.
17
+
18
+ require File.dirname(__FILE__) + '/../test_helper'
19
+
20
+ class LinkpointTest < Test::Unit::TestCase
21
+ def setup
22
+ Base.gateway_mode = :test
23
+
24
+ @gateway = LinkpointGateway.new(fixtures(:linkpoint))
25
+
26
+ # Test credit card numbers
27
+ # American Express: 371111111111111
28
+ # Discover: 6011-1111-1111-1111
29
+ # JCB: 311111111111111
30
+ # MasterCard: 5111-1111-1111-1111
31
+ # MasterCard: 5419-8400-0000-0003
32
+ # Visa: 4111-1111-1111-1111
33
+
34
+ @creditcard = credit_card('4111111111111111')
35
+
36
+ @address = {
37
+ :address1 => '1313 lucky lane',
38
+ :city => 'Lost Angeles',
39
+ :state => 'ON',
40
+ :zip => 'K2P2A6',
41
+ :country => 'CA',
42
+ :address2 => 'Apartment 1',
43
+ :phone => '(555)555-5555'
44
+ }
45
+ end
46
+
47
+ def test_successful_authorization
48
+ assert response = @gateway.authorize(1000, @creditcard,
49
+ :order_id => generate_order_id,
50
+ :address => @address
51
+ )
52
+
53
+ assert_equal Response, response.class
54
+ assert_equal true, response.success?
55
+ assert_equal "APPROVED", response.params["approved"]
56
+ end
57
+
58
+ def test_successful_authorization_and_capture
59
+ assert authorization = @gateway.authorize(100, @creditcard,
60
+ :order_id => generate_order_id,
61
+ :address => @address
62
+ )
63
+
64
+ assert_success authorization
65
+ assert authorization.test?
66
+ assert capture = @gateway.capture(100, authorization.authorization)
67
+ assert_success capture
68
+ assert_equal 'ACCEPTED', capture.message
69
+ end
70
+
71
+ def test_successful_purchase_without_cvv2_code
72
+ @creditcard.verification_value = nil
73
+
74
+ assert response = @gateway.purchase(2400, @creditcard,
75
+ :order_id => generate_order_id,
76
+ :address => @address
77
+ )
78
+ assert_equal Response, response.class
79
+ assert_equal true, response.success?
80
+ assert_equal "APPROVED", response.params["approved"]
81
+ assert_equal 'NNN', response.params["avs"]
82
+ end
83
+
84
+ def test_successful_purchase_with_cvv2_code
85
+ assert response = @gateway.purchase(2400, @creditcard,
86
+ :order_id => generate_order_id,
87
+ :address => @address
88
+ )
89
+ assert_equal Response, response.class
90
+ assert_equal true, response.success?
91
+ assert_equal "APPROVED", response.params["approved"]
92
+ assert_equal 'NNNM', response.params["avs"]
93
+ end
94
+
95
+ def test_successful_purchase_and_void
96
+ purchase = @gateway.purchase(100, @creditcard,
97
+ :order_id => generate_order_id,
98
+ :address => @address
99
+ )
100
+ assert_success purchase
101
+
102
+ assert void = @gateway.void(purchase.authorization)
103
+ assert_success void
104
+ end
105
+
106
+ def test_successfull_purchase_and_credit
107
+ assert purchase = @gateway.purchase(2400, @creditcard,
108
+ :order_id => generate_order_id,
109
+ :address => @address
110
+ )
111
+ assert_equal true, purchase.success?
112
+
113
+ assert credit = @gateway.credit(2400, purchase.authorization)
114
+ assert_success credit
115
+ end
116
+
117
+
118
+ def test_successful_recurring_payment
119
+ assert response = @gateway.recurring(2400, @creditcard,
120
+ :order_id => generate_order_id,
121
+ :installments => 12,
122
+ :startdate => "immediate",
123
+ :periodicity => :monthly,
124
+ :address => @address
125
+ )
126
+
127
+ assert_equal Response, response.class
128
+ assert_equal true, response.success?
129
+ assert_equal "APPROVED", response.params["approved"]
130
+ end
131
+
132
+
133
+ def test_declined_purchase_with_invalid_credit_card
134
+ @creditcard.number = '1111111111111111'
135
+ assert response = @gateway.purchase(100, @creditcard,
136
+ :order_id => generate_order_id,
137
+ :address => @address
138
+ )
139
+
140
+ assert_equal Response, response.class
141
+ assert_equal false, response.success?
142
+ assert_equal "DECLINED", response.params["approved"]
143
+ end
144
+ end
@@ -0,0 +1,110 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class MonerisRemoteTest < Test::Unit::TestCase
4
+ def setup
5
+ Base.gateway_mode = :test
6
+
7
+ @gateway = MonerisGateway.new(fixtures(:moneris))
8
+ @creditcard = credit_card('4242424242424242')
9
+ @expected_response_headers = [
10
+ "auth_code",
11
+ "bank_totals",
12
+ "card_type",
13
+ "complete",
14
+ "iso",
15
+ "message",
16
+ "receipt_id",
17
+ "reference_num",
18
+ "response_code",
19
+ "ticket",
20
+ "timed_out",
21
+ "trans_amount",
22
+ "trans_date",
23
+ "trans_id",
24
+ "trans_time",
25
+ "trans_type"
26
+ ]
27
+ end
28
+
29
+ def test_should_be_a_successful_remote_purchase
30
+ order_id = generate_order_id
31
+ assert response = @gateway.purchase(100, @creditcard, :order_id => order_id)
32
+ assert_equal Response, response.class
33
+ assert_equal @expected_response_headers, response.params.keys.sort
34
+ assert_match /APPROVED/, response.params['message']
35
+ assert_equal 'Approved', response.message
36
+ assert_equal true, response.params['complete']
37
+ assert_equal true, response.success? # Checking for type-casting of XML, not actual success
38
+ assert_equal order_id, response.params['receipt_id']
39
+ assert_equal "#{response.params['trans_id']};#{response.params['receipt_id']}", response.authorization
40
+ end
41
+
42
+ def test_should_be_a_successful_authorization
43
+ response = @gateway.authorize(100, @creditcard, :order_id => generate_order_id)
44
+ assert_success response
45
+ assert response.authorization
46
+ end
47
+
48
+ def test_should_not_be_a_successful_authorization
49
+ response = @gateway.authorize(105, @creditcard, :order_id => generate_order_id)
50
+ assert_failure response
51
+ end
52
+
53
+ def test_should_be_a_successful_authorization_and_capture
54
+ response = @gateway.authorize(100, @creditcard, :order_id => generate_order_id)
55
+ assert_success response
56
+ assert response.authorization
57
+
58
+ response = @gateway.capture(100, response.authorization)
59
+ assert_success response
60
+ end
61
+
62
+ def test_should_be_a_successful_capture_and_void
63
+ # First perform a successful authorization and capture
64
+ response = @gateway.authorize(100, @creditcard, :order_id => generate_order_id)
65
+ assert_success response
66
+ assert response.authorization
67
+
68
+ capture = @gateway.capture(100, response.authorization)
69
+ assert_success capture
70
+ assert capture.authorization
71
+
72
+ # Now void it
73
+ void = @gateway.void(capture.authorization)
74
+ assert_success void
75
+ end
76
+
77
+ def test_should_be_a_successful_purchase_and_void
78
+ purchase = @gateway.purchase(100, @creditcard, :order_id => generate_order_id)
79
+ assert_success purchase
80
+
81
+ void = @gateway.void(purchase.authorization)
82
+ assert_success void
83
+ end
84
+
85
+ def test_should_not_be_a_successful_purchase_and_void
86
+ purchase = @gateway.purchase(101, @creditcard, :order_id => generate_order_id)
87
+ assert_failure purchase
88
+
89
+ void = @gateway.void(purchase.authorization)
90
+ assert_failure void
91
+ end
92
+
93
+ def test_should_be_a_successful_purchase_and_refund
94
+ purchase = @gateway.purchase(100, @creditcard, :order_id => generate_order_id)
95
+ assert_success purchase
96
+
97
+ credit = @gateway.credit(100, purchase.authorization)
98
+ assert_success credit
99
+ end
100
+
101
+ def test_should_be_a_remote_error
102
+ assert response = @gateway.purchase(150, @creditcard, :order_id => generate_order_id)
103
+ assert_equal Response, response.class
104
+ assert_equal @expected_response_headers, response.params.keys.sort
105
+ assert_match /DECLINED/, response.params['message']
106
+ assert_equal 'Declined', response.message
107
+ assert_equal true, response.params['complete']
108
+ assert_equal false, response.success? # Checking for XML type-casting, not failure
109
+ end
110
+ end
@@ -0,0 +1,120 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+
4
+ ######################################################################
5
+ #
6
+ # To run these tests, set the variables at the top of the class
7
+ # definition.
8
+ #
9
+ # Note that NetRegistry does not provide any sort of test
10
+ # server/account, so you'll probably want to refund any uncredited
11
+ # purchases through the NetRegistry console at www.netregistry.com .
12
+ # All purchases made in these tests are $1, so hopefully you won't be
13
+ # sent broke if you forget...
14
+ #
15
+ ######################################################################
16
+
17
+ class NetRegistryTest < Test::Unit::TestCase
18
+ #
19
+ # Provide valid data here to run the tests.
20
+ #
21
+ # LOG_FILE_NAME may be nil, or a filename to write messages sent to
22
+ # and received from the gateway
23
+ #
24
+
25
+ LOG_FILE_NAME = nil
26
+ VALID_CARD_DETAILS = {
27
+ :number => '4111111111111111',
28
+ :month => 12,
29
+ :year => 2010,
30
+ :first_name => 'Longbob',
31
+ :last_name => 'Longsen',
32
+ :type => :visa,
33
+ }
34
+
35
+ def setup
36
+ if LOG_FILE_NAME
37
+ @log_file = open(LOG_FILE_NAME, 'a')
38
+ @logger = Logger.new(@log_file)
39
+ end
40
+
41
+ @gateway = NetRegistryGateway.new(fixtures(:net_registry))
42
+
43
+ @valid_creditcard = CreditCard.new(VALID_CARD_DETAILS)
44
+ @invalid_creditcard = CreditCard.new(
45
+ VALID_CARD_DETAILS.merge(:type => :visa, :number => '4111111111111111')
46
+ )
47
+ @expired_creditcard = CreditCard.new(
48
+ VALID_CARD_DETAILS.merge(:year => 2000)
49
+ )
50
+ @invalid_month_creditcard = CreditCard.new(
51
+ VALID_CARD_DETAILS.merge(:month => 13)
52
+ )
53
+ end
54
+
55
+ def teardown
56
+ @log_file.close if @log_file
57
+ end
58
+
59
+ def test_successful_purchase_and_credit
60
+ response = @gateway.purchase(100, @valid_creditcard)
61
+ assert_equal 'approved', response.params['status']
62
+ assert_success response
63
+ assert_match(/\A\d{16}\z/, response.authorization)
64
+
65
+ response = @gateway.credit(100, response.authorization)
66
+ assert_equal 'approved', response.params['status']
67
+ assert_success response
68
+ end
69
+
70
+ #
71
+ # # authorize and #capture haven't been tested because the author's
72
+ # account hasn't been setup to support these methods (see the
73
+ # documentation for the NetRegistry gateway class). There is no
74
+ # mention of a #void transaction in NetRegistry's documentation,
75
+ # either.
76
+ #
77
+ if ENV['TEST_AUTHORIZE_AND_CAPTURE']
78
+ def test_successful_authorization_and_capture
79
+ response = @gateway.authorize(100, @valid_creditcard)
80
+ assert_success response
81
+ assert_equal 'approved', response.params['status']
82
+ assert_match(/\A\d{6}\z/, response.authorization)
83
+
84
+ response = @gateway.capture(100,
85
+ response.authorization,
86
+ :credit_card => @valid_creditcard)
87
+ assert_success response
88
+ assert_equal 'approved', response.params['status']
89
+ end
90
+ end
91
+
92
+ def test_purchase_with_invalid_credit_card
93
+ response = @gateway.purchase(100, @invalid_creditcard)
94
+ assert_equal 'declined', response.params['status']
95
+ assert_equal 'INVALID CARD', response.message
96
+ assert_failure response
97
+ end
98
+
99
+ def test_purchase_with_expired_credit_card
100
+ response = @gateway.purchase(100, @expired_creditcard)
101
+ assert_equal 'failed', response.params['status']
102
+ assert_equal 'CARD EXPIRED', response.message
103
+ assert_failure response
104
+ end
105
+
106
+ def test_purchase_with_invalid_month
107
+ response = @gateway.purchase(100, @invalid_month_creditcard)
108
+ assert_equal 'failed', response.params['status']
109
+ assert_equal 'Invalid month', response.message
110
+ assert_failure response
111
+ end
112
+
113
+ def test_bad_login
114
+ @gateway = NetRegistryGateway.new(:login => 'bad-login',
115
+ :password => 'bad-login')
116
+ response = @gateway.purchase(100, @valid_creditcard)
117
+ assert_equal 'failed', response.params['status']
118
+ assert_failure response
119
+ end
120
+ end