activemerchant 1.1.0 → 1.2.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.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +226 -0
- data/CONTRIBUTERS +52 -0
- data/README +34 -24
- data/Rakefile +152 -0
- data/gem-public_cert.pem +20 -0
- data/init.rb +3 -0
- data/lib/active_merchant.rb +3 -1
- data/lib/active_merchant/billing/credit_card.rb +21 -17
- data/lib/active_merchant/billing/credit_card_methods.rb +17 -19
- data/lib/active_merchant/billing/gateway.rb +160 -44
- data/lib/active_merchant/billing/gateways.rb +2 -15
- data/lib/active_merchant/billing/gateways/authorize_net.rb +21 -21
- data/lib/active_merchant/billing/gateways/bogus.rb +6 -6
- data/lib/active_merchant/billing/gateways/brain_tree.rb +191 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +207 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +402 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +41 -97
- data/lib/active_merchant/billing/gateways/efsnet.rb +256 -0
- data/lib/active_merchant/billing/gateways/eway.rb +77 -29
- data/lib/active_merchant/billing/gateways/exact.rb +230 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +6 -33
- data/lib/active_merchant/billing/gateways/moneris.rb +155 -125
- data/lib/active_merchant/billing/gateways/net_registry.rb +257 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +407 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +163 -25
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +56 -38
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +10 -1
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +9 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +36 -11
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +6 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +7 -3
- data/lib/active_merchant/billing/gateways/payment_express.rb +261 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +18 -4
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +31 -15
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +8 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +33 -8
- data/lib/active_merchant/billing/gateways/plugnpay.rb +300 -0
- data/lib/active_merchant/billing/gateways/protx.rb +285 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +13 -12
- data/lib/active_merchant/billing/gateways/psl_card.rb +297 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +197 -0
- data/lib/active_merchant/billing/gateways/realex.rb +212 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +136 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +43 -20
- data/lib/active_merchant/billing/gateways/usa_epay.rb +6 -5
- data/lib/active_merchant/billing/gateways/verifi.rb +235 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +0 -2
- data/lib/active_merchant/billing/integrations/helper.rb +8 -1
- data/lib/active_merchant/billing/integrations/nochex.rb +62 -1
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +9 -16
- data/lib/active_merchant/billing/integrations/notification.rb +1 -1
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +59 -46
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +14 -47
- data/lib/active_merchant/lib/error.rb +4 -0
- data/lib/active_merchant/lib/post_data.rb +22 -0
- data/lib/active_merchant/lib/posts_data.rb +23 -5
- data/lib/active_merchant/lib/requires_parameters.rb +2 -2
- data/lib/active_merchant/lib/validateable.rb +1 -1
- data/lib/support/gateway_support.rb +45 -0
- data/lib/tasks/cia.rb +1 -1
- data/script/generate +14 -0
- data/script/generator/base.rb +45 -0
- data/script/generator/generator.rb +24 -0
- data/script/generator/generators/gateway/gateway_generator.rb +14 -0
- data/script/generator/generators/gateway/templates/gateway.rb +73 -0
- data/script/generator/generators/gateway/templates/gateway_test.rb +41 -0
- data/script/generator/generators/gateway/templates/remote_gateway_test.rb +56 -0
- data/script/generator/generators/integration/integration_generator.rb +25 -0
- data/script/generator/generators/integration/templates/helper.rb +34 -0
- data/script/generator/generators/integration/templates/helper_test.rb +54 -0
- data/script/generator/generators/integration/templates/integration.rb +18 -0
- data/script/generator/generators/integration/templates/module_test.rb +9 -0
- data/script/generator/generators/integration/templates/notification.rb +100 -0
- data/script/generator/generators/integration/templates/notification_test.rb +41 -0
- data/script/generator/manifest.rb +20 -0
- data/test/extra/binding_of_caller.rb +80 -0
- data/test/extra/breakpoint.rb +547 -0
- data/test/fixtures.yml +251 -0
- data/test/remote_tests/remote_authorize_net_test.rb +113 -0
- data/test/remote_tests/remote_brain_tree_test.rb +78 -0
- data/test/remote_tests/remote_card_stream_test.rb +160 -0
- data/test/remote_tests/remote_cyber_source_test.rb +130 -0
- data/test/remote_tests/remote_data_cash_test.rb +155 -0
- data/test/remote_tests/remote_efsnet_test.rb +93 -0
- data/test/remote_tests/remote_eway_test.rb +71 -0
- data/test/remote_tests/remote_exact_test.rb +59 -0
- data/test/remote_tests/remote_gestpay_integration_test.rb +37 -0
- data/test/remote_tests/remote_linkpoint_test.rb +144 -0
- data/test/remote_tests/remote_moneris_test.rb +110 -0
- data/test/remote_tests/remote_net_registry_test.rb +120 -0
- data/test/remote_tests/remote_pay_junction_test.rb +162 -0
- data/test/remote_tests/remote_payflow_express_test.rb +50 -0
- data/test/remote_tests/remote_payflow_test.rb +241 -0
- data/test/remote_tests/remote_payflow_uk_test.rb +172 -0
- data/test/remote_tests/remote_payment_express_test.rb +136 -0
- data/test/remote_tests/remote_paypal_express_test.rb +49 -0
- data/test/remote_tests/remote_paypal_integration_test.rb +14 -0
- data/test/remote_tests/remote_paypal_test.rb +163 -0
- data/test/remote_tests/remote_plugnpay_test.rb +70 -0
- data/test/remote_tests/remote_protx_test.rb +184 -0
- data/test/remote_tests/remote_psigate_test.rb +87 -0
- data/test/remote_tests/remote_psl_card_test.rb +105 -0
- data/test/remote_tests/remote_quickpay_test.rb +182 -0
- data/test/remote_tests/remote_realex_test.rb +227 -0
- data/test/remote_tests/remote_secure_pay_test.rb +36 -0
- data/test/remote_tests/remote_trans_first_test.rb +37 -0
- data/test/remote_tests/remote_trust_commerce_test.rb +136 -0
- data/test/remote_tests/remote_usa_epay_test.rb +57 -0
- data/test/remote_tests/remote_verifi_test.rb +107 -0
- data/test/remote_tests/remote_viaklix_test.rb +53 -0
- data/test/test_helper.rb +132 -0
- data/test/unit/base_test.rb +61 -0
- data/test/unit/country_code_test.rb +33 -0
- data/test/unit/country_test.rb +64 -0
- data/test/unit/credit_card_formatting_test.rb +24 -0
- data/test/unit/credit_card_methods_test.rb +37 -0
- data/test/unit/credit_card_test.rb +365 -0
- data/test/unit/gateways/authorize_net_test.rb +140 -0
- data/test/unit/gateways/bogus_test.rb +43 -0
- data/test/unit/gateways/brain_tree_test.rb +77 -0
- data/test/unit/gateways/card_stream_test.rb +37 -0
- data/test/unit/gateways/cyber_source_test.rb +151 -0
- data/test/unit/gateways/data_cash_test.rb +23 -0
- data/test/unit/gateways/efsnet_test.rb +70 -0
- data/test/unit/gateways/eway_test.rb +105 -0
- data/test/unit/gateways/exact_test.rb +118 -0
- data/test/unit/gateways/gateway_test.rb +24 -0
- data/test/unit/gateways/linkpoint_test.rb +165 -0
- data/test/unit/gateways/moneris_test.rb +167 -0
- data/test/unit/gateways/net_registry_test.rb +478 -0
- data/test/unit/gateways/pay_junction_test.rb +61 -0
- data/test/unit/gateways/payflow_express_test.rb +165 -0
- data/test/unit/gateways/payflow_express_uk_test.rb +14 -0
- data/test/unit/gateways/payflow_test.rb +230 -0
- data/test/unit/gateways/payflow_uk_test.rb +68 -0
- data/test/unit/gateways/payment_express_test.rb +215 -0
- data/test/unit/gateways/paypal_express_test.rb +222 -0
- data/test/unit/gateways/paypal_test.rb +241 -0
- data/test/unit/gateways/plugnpay_test.rb +79 -0
- data/test/unit/gateways/protx_test.rb +110 -0
- data/test/unit/gateways/psigate_test.rb +110 -0
- data/test/unit/gateways/psl_card_test.rb +51 -0
- data/test/unit/gateways/quickpay_test.rb +125 -0
- data/test/unit/gateways/realex_test.rb +150 -0
- data/test/unit/gateways/secure_pay_test.rb +78 -0
- data/test/unit/gateways/trans_first_test.rb +125 -0
- data/test/unit/gateways/trust_commerce_test.rb +57 -0
- data/test/unit/gateways/usa_epay_test.rb +117 -0
- data/test/unit/gateways/verifi_test.rb +91 -0
- data/test/unit/gateways/viaklix_test.rb +72 -0
- data/test/unit/integrations/action_view_helper_test.rb +54 -0
- data/test/unit/integrations/bogus_module_test.rb +16 -0
- data/test/unit/integrations/chronopay_module_test.rb +9 -0
- data/test/unit/integrations/gestpay_module_test.rb +10 -0
- data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
- data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
- data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
- data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
- data/test/unit/integrations/helpers/paypal_helper_test.rb +162 -0
- data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
- data/test/unit/integrations/nochex_module_test.rb +9 -0
- data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
- data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
- data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
- data/test/unit/integrations/notifications/notification_test.rb +41 -0
- data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
- data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
- data/test/unit/integrations/paypal_module_test.rb +24 -0
- data/test/unit/integrations/two_checkout_module_test.rb +9 -0
- data/test/unit/post_data_test.rb +55 -0
- data/test/unit/response_test.rb +14 -0
- data/test/unit/validateable_test.rb +56 -0
- metadata +160 -7
- metadata.gz.sig +0 -0
- data/lib/active_merchant/billing/gateways/payflow/f73e89fd.0 +0 -17
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
|
2
|
+
|
|
3
|
+
class MonerisResponseTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@gateway = MonerisGateway.new(
|
|
6
|
+
:login => 'store1',
|
|
7
|
+
:password => 'yesguy'
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
@creditcard = credit_card('4242424242424242')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
Base.mode = :test
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_purchase_success
|
|
18
|
+
@creditcard.number = 1
|
|
19
|
+
|
|
20
|
+
assert response = @gateway.purchase(100, @creditcard, :order_id => 1)
|
|
21
|
+
assert_equal Response, response.class
|
|
22
|
+
assert_equal '#0001', response.params['receiptid']
|
|
23
|
+
assert_equal true, response.success?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_purchase_error
|
|
27
|
+
@creditcard.number = 2
|
|
28
|
+
|
|
29
|
+
assert response = @gateway.purchase(100, @creditcard, :order_id => 1)
|
|
30
|
+
assert_equal Response, response.class
|
|
31
|
+
assert_equal '#0001', response.params['receiptid']
|
|
32
|
+
assert_equal false, response.success?
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_purchase_exceptions
|
|
37
|
+
@creditcard.number = 3
|
|
38
|
+
|
|
39
|
+
assert_raise(Error) do
|
|
40
|
+
assert response = @gateway.purchase(100, @creditcard, :order_id => 1)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_amount_style
|
|
45
|
+
assert_equal '10.34', @gateway.send(:amount, 1034)
|
|
46
|
+
|
|
47
|
+
assert_raise(ArgumentError) do
|
|
48
|
+
@gateway.send(:amount, '10.34')
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_purchase_is_valid_xml
|
|
53
|
+
|
|
54
|
+
params = {
|
|
55
|
+
:order_id => "order1",
|
|
56
|
+
:amount => "1.01",
|
|
57
|
+
:pan => "4242424242424242",
|
|
58
|
+
:expdate => "0303",
|
|
59
|
+
:crypt_type => 7,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
assert data = @gateway.send(:post_data, 'preauth', params)
|
|
63
|
+
assert REXML::Document.new(data)
|
|
64
|
+
assert_equal xml_capture_fixture.size, data.size
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def xml_purchase_fixture
|
|
70
|
+
%q{<request><store_id>store1</store_id><api_token>yesguy</api_token><purchase><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></purchase></request>}
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def xml_capture_fixture
|
|
74
|
+
%q{<request><store_id>store1</store_id><api_token>yesguy</api_token><preauth><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></preauth></request>}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class MonerisRequestTest < Test::Unit::TestCase
|
|
81
|
+
def setup
|
|
82
|
+
@gateway = MonerisGateway.new(
|
|
83
|
+
:login => 'store1',
|
|
84
|
+
:password => 'yesguy'
|
|
85
|
+
)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_purchase_is_valid_xml
|
|
90
|
+
|
|
91
|
+
params = {
|
|
92
|
+
:order_id => "order1",
|
|
93
|
+
:amount => "1.01",
|
|
94
|
+
:pan => "4242424242424242",
|
|
95
|
+
:expdate => "0303",
|
|
96
|
+
:crypt_type => 7,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
assert data = @gateway.send(:post_data, 'purchase', params)
|
|
100
|
+
assert REXML::Document.new(data)
|
|
101
|
+
assert_equal xml_purchase_fixture.size, data.size
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_capture_is_valid_xml
|
|
105
|
+
|
|
106
|
+
params = {
|
|
107
|
+
:order_id => "order1",
|
|
108
|
+
:amount => "1.01",
|
|
109
|
+
:pan => "4242424242424242",
|
|
110
|
+
:expdate => "0303",
|
|
111
|
+
:crypt_type => 7,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
assert data = @gateway.send(:post_data, 'preauth', params)
|
|
115
|
+
assert REXML::Document.new(data)
|
|
116
|
+
assert_equal xml_capture_fixture.size, data.size
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_access_url_for_test_environment
|
|
120
|
+
Base.mode = :test
|
|
121
|
+
gateway = MonerisGateway.new(
|
|
122
|
+
:login => 'store1',
|
|
123
|
+
:password => 'yesguy'
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
assert_equal 'https://esqa.moneris.com/gateway2/servlet/MpgRequest', gateway.url
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_access_url_for_production_environment
|
|
130
|
+
Base.mode = :production
|
|
131
|
+
gateway = MonerisGateway.new(
|
|
132
|
+
:login => 'store1',
|
|
133
|
+
:password => 'yesguy'
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
assert_equal 'https://www3.moneris.com/gateway2/servlet/MpgRequest', gateway.url
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_supported_countries
|
|
140
|
+
assert_equal ['CA'], MonerisGateway.supported_countries
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def test_supported_card_types
|
|
144
|
+
assert_equal [:visa, :master], MonerisGateway.supported_cardtypes
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_should_raise_error_if_transaction_param_empty_on_credit_request
|
|
148
|
+
[nil, '', '1234'].each do |invalid_transaction_param|
|
|
149
|
+
assert_raise(ArgumentError) { @gateway.void(invalid_transaction_param) }
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def test_should_not_raise_error_if_transaction_param_is_not_empty_on_credit_request
|
|
154
|
+
assert_nothing_raised(ArgumentError) { @gateway.void('1234;456') }
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
private
|
|
158
|
+
|
|
159
|
+
def xml_purchase_fixture
|
|
160
|
+
%q{<request><store_id>store1</store_id><api_token>yesguy</api_token><purchase><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></purchase></request>}
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def xml_capture_fixture
|
|
164
|
+
%q{<request><store_id>store1</store_id><api_token>yesguy</api_token><preauth><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></preauth></request>}
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
end
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
|
3
|
+
require 'stringio'
|
|
4
|
+
|
|
5
|
+
class NetRegistryTest < Test::Unit::TestCase
|
|
6
|
+
include ActiveMerchant::Billing
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@log_io = StringIO.new
|
|
10
|
+
@gateway = NetRegistryGateway.new(
|
|
11
|
+
:login => 'X',
|
|
12
|
+
:password => 'Y',
|
|
13
|
+
:logger => Logger.new(@log_io)
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
@creditcard = CreditCard.new({
|
|
17
|
+
:number => '4111111111111111',
|
|
18
|
+
:month => 12,
|
|
19
|
+
:year => 2010,
|
|
20
|
+
:first_name => 'Longbob',
|
|
21
|
+
:last_name => 'Longsen',
|
|
22
|
+
:type => :visa,
|
|
23
|
+
})
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_purchase_success
|
|
27
|
+
@creditcard.number = 1
|
|
28
|
+
|
|
29
|
+
assert response = @gateway.purchase(100, @creditcard)
|
|
30
|
+
assert_equal Response, response.class
|
|
31
|
+
assert_equal '#0001', response.params['receiptid']
|
|
32
|
+
assert_equal true, response.success?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_purchase_error
|
|
36
|
+
@creditcard.number = 2
|
|
37
|
+
|
|
38
|
+
assert response = @gateway.purchase(100, @creditcard, :order_id => 1)
|
|
39
|
+
assert_equal Response, response.class
|
|
40
|
+
assert_equal '#0001', response.params['receiptid']
|
|
41
|
+
assert_equal false, response.success?
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_purchase_exceptions
|
|
46
|
+
@creditcard.number = 3
|
|
47
|
+
|
|
48
|
+
assert_raise(Error) do
|
|
49
|
+
assert response = @gateway.purchase(100, @creditcard, :order_id => 1)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_successful_purchase
|
|
54
|
+
stub_gateway_response 'successful_purchase'
|
|
55
|
+
response = @gateway.purchase(100, @creditcard)
|
|
56
|
+
assert_success response
|
|
57
|
+
assert_match /\A\d{16}\z/, response.authorization
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_successful_credit
|
|
61
|
+
stub_gateway_response 'successful_credit'
|
|
62
|
+
response = @gateway.credit(100, '0707161858000000')
|
|
63
|
+
assert_success response
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_successful_authorization
|
|
67
|
+
stub_gateway_response 'successful_authorization'
|
|
68
|
+
response = @gateway.authorize(100, @creditcard)
|
|
69
|
+
assert_success response
|
|
70
|
+
assert_match /\A\d{6}\z/, response.authorization
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_successful_authorization_and_capture
|
|
74
|
+
stub_gateway_response 'successful_authorization'
|
|
75
|
+
response = @gateway.authorize(100, @creditcard)
|
|
76
|
+
assert_success response
|
|
77
|
+
assert_match /\A\d{6}\z/, response.authorization
|
|
78
|
+
|
|
79
|
+
stub_gateway_response 'successful_capture'
|
|
80
|
+
response = @gateway.capture(100, response.authorization, :credit_card => @creditcard)
|
|
81
|
+
assert_success response
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_purchase_with_invalid_credit_card
|
|
85
|
+
stub_gateway_response 'purchase_with_invalid_credit_card'
|
|
86
|
+
response = @gateway.purchase(100, @creditcard)
|
|
87
|
+
assert_failure response
|
|
88
|
+
assert_equal 'INVALID CARD', response.message
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_purchase_with_expired_credit_card
|
|
92
|
+
stub_gateway_response 'purchase_with_expired_credit_card'
|
|
93
|
+
response = @gateway.purchase(100, @creditcard)
|
|
94
|
+
assert_failure response
|
|
95
|
+
assert_equal 'CARD EXPIRED', response.message
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_purchase_with_invalid_month
|
|
99
|
+
stub_gateway_response 'purchase_with_invalid_month'
|
|
100
|
+
response = @gateway.purchase(100, @creditcard)
|
|
101
|
+
assert_failure response
|
|
102
|
+
assert_equal 'Invalid month', response.message
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_transaction_with_logging
|
|
106
|
+
stub_gateway_response 'successful_purchase'
|
|
107
|
+
response = @gateway.purchase(100, @creditcard)
|
|
108
|
+
assert_success response
|
|
109
|
+
|
|
110
|
+
# check send line
|
|
111
|
+
sent_line = log_text.grep(/sending/).first
|
|
112
|
+
assert sent_line
|
|
113
|
+
sent_line.chomp!
|
|
114
|
+
|
|
115
|
+
# command should appear
|
|
116
|
+
assert_match /COMMAND=purchase/, sent_line
|
|
117
|
+
# card number should be masked
|
|
118
|
+
number = sent_line[/CCNUM=(.{16})/][6..-1]
|
|
119
|
+
assert_match /\*{12}/, sent_line
|
|
120
|
+
# card expiry should be masked
|
|
121
|
+
expiry = sent_line[/CCEXP=([^&]*)/][6..-1]
|
|
122
|
+
assert_match /\*+\/\*+/, expiry
|
|
123
|
+
|
|
124
|
+
# check received text
|
|
125
|
+
received_text = log_text.grep(/^ /).join
|
|
126
|
+
assert !received_text.empty?
|
|
127
|
+
# card number should be masked
|
|
128
|
+
received_text.scan(/card_(?:number|no)=(.*)$/) do
|
|
129
|
+
value = $1
|
|
130
|
+
assert_match /\*{12}/, value
|
|
131
|
+
end
|
|
132
|
+
# card_expiry should be masked
|
|
133
|
+
received_text.scan(/card_expiry=(.*)$/) do
|
|
134
|
+
value = $1
|
|
135
|
+
assert_match /\*+\/\*+/, value
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_transaction_without_logging
|
|
140
|
+
stub_gateway_response 'successful_purchase'
|
|
141
|
+
@gateway.logger = nil
|
|
142
|
+
response = @gateway.purchase(100, @creditcard)
|
|
143
|
+
assert_success response
|
|
144
|
+
assert log_text.empty?
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_bad_login
|
|
148
|
+
@gateway = NetRegistryGateway.new(:login => 'bad-login', :password => 'bad-login')
|
|
149
|
+
stub_gateway_response 'bad_login'
|
|
150
|
+
response = @gateway.purchase(100, @creditcard)
|
|
151
|
+
assert_failure response
|
|
152
|
+
assert_equal 'failed', response.params['status']
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
private # ---------------------------------------------------------
|
|
156
|
+
|
|
157
|
+
#
|
|
158
|
+
# Return the contents of the log file.
|
|
159
|
+
#
|
|
160
|
+
def log_text
|
|
161
|
+
@log_io.string
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
#
|
|
165
|
+
# Parse the response data to use in our simulations.
|
|
166
|
+
#
|
|
167
|
+
def parse_response_data
|
|
168
|
+
data = {}
|
|
169
|
+
current_key = nil
|
|
170
|
+
RESPONSE_DATA.each do |line|
|
|
171
|
+
if line =~ /^== (.*)$/
|
|
172
|
+
current_key = $1
|
|
173
|
+
data[current_key] = ''
|
|
174
|
+
else
|
|
175
|
+
line.sub!(/^ /, '')
|
|
176
|
+
data[current_key] << line
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
data
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
#
|
|
183
|
+
# Make the gateway pretend the named response data text is returned
|
|
184
|
+
# by the gateway server.
|
|
185
|
+
#
|
|
186
|
+
def stub_gateway_response(key)
|
|
187
|
+
response_data = parse_response_data
|
|
188
|
+
@gateway.stubs(:ssl_post).returns(response_data[key])
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
RESPONSE_DATA = <<EOS
|
|
192
|
+
== successful_purchase
|
|
193
|
+
approved
|
|
194
|
+
00015X000000
|
|
195
|
+
Transaction No: 00000000
|
|
196
|
+
------------------------
|
|
197
|
+
MERCHANTNAME
|
|
198
|
+
LOCATION AU
|
|
199
|
+
|
|
200
|
+
MERCH ID 10000000
|
|
201
|
+
TERM ID Y0TR00
|
|
202
|
+
COUNTRY CODE AU
|
|
203
|
+
16/07/07 18:59
|
|
204
|
+
RRN 00015X000000
|
|
205
|
+
VISA
|
|
206
|
+
411111-111
|
|
207
|
+
CREDIT A/C 12/10
|
|
208
|
+
|
|
209
|
+
AUTHORISATION NO: 000000
|
|
210
|
+
APPROVED 08
|
|
211
|
+
|
|
212
|
+
PURCHASE $1.00
|
|
213
|
+
TOTAL AUD $1.00
|
|
214
|
+
|
|
215
|
+
PLEASE RETAIN AS RECORD
|
|
216
|
+
OF PURCHASE
|
|
217
|
+
|
|
218
|
+
(SUBJECT TO CARDHOLDER'S
|
|
219
|
+
ACCEPTANCE)
|
|
220
|
+
------------------------
|
|
221
|
+
.
|
|
222
|
+
settlement_date=16/07/07
|
|
223
|
+
card_desc=VISA
|
|
224
|
+
status=approved
|
|
225
|
+
txn_ref=0707161858000000
|
|
226
|
+
refund_mode=0
|
|
227
|
+
transaction_no=000000
|
|
228
|
+
rrn=00015X000000
|
|
229
|
+
response_text=SIGNATURE REQUIRED
|
|
230
|
+
pld=0
|
|
231
|
+
total_amount=100
|
|
232
|
+
card_no=4111111111111111
|
|
233
|
+
version=V1.0
|
|
234
|
+
merchant_index=123
|
|
235
|
+
card_expiry=12/10
|
|
236
|
+
training_mode=0
|
|
237
|
+
operator_no=10000
|
|
238
|
+
response_code=08
|
|
239
|
+
card_type=6
|
|
240
|
+
approved=1
|
|
241
|
+
cashout_amount=0
|
|
242
|
+
receipt_array=ARRAY(0x83725cc)
|
|
243
|
+
account_type=CREDIT A/C
|
|
244
|
+
result=1
|
|
245
|
+
== successful_authorization
|
|
246
|
+
approved
|
|
247
|
+
00015X000000
|
|
248
|
+
Transaction No: 00000000
|
|
249
|
+
------------------------
|
|
250
|
+
MERCHANTNAME
|
|
251
|
+
LOCATION AU
|
|
252
|
+
|
|
253
|
+
MERCH ID 10000000
|
|
254
|
+
TERM ID Y0TR00
|
|
255
|
+
COUNTRY CODE AU
|
|
256
|
+
17/07/07 15:22
|
|
257
|
+
RRN 00015X000000
|
|
258
|
+
VISA
|
|
259
|
+
411111-111
|
|
260
|
+
CREDIT A/C 12/10
|
|
261
|
+
|
|
262
|
+
AUTHORISATION NO: 000000
|
|
263
|
+
APPROVED 08
|
|
264
|
+
|
|
265
|
+
PURCHASE $1.00
|
|
266
|
+
TOTAL AUD $1.00
|
|
267
|
+
|
|
268
|
+
PLEASE RETAIN AS RECORD
|
|
269
|
+
OF PURCHASE
|
|
270
|
+
|
|
271
|
+
(SUBJECT TO CARDHOLDER'S
|
|
272
|
+
ACCEPTANCE)
|
|
273
|
+
------------------------
|
|
274
|
+
.
|
|
275
|
+
settlement_date=17/07/07
|
|
276
|
+
card_desc=VISA
|
|
277
|
+
status=approved
|
|
278
|
+
txn_ref=0707171521000000
|
|
279
|
+
refund_mode=0
|
|
280
|
+
transaction_no=000000
|
|
281
|
+
rrn=00015X000000
|
|
282
|
+
response_text=SIGNATURE REQUIRED
|
|
283
|
+
pld=0
|
|
284
|
+
total_amount=100
|
|
285
|
+
card_no=4111111111111111
|
|
286
|
+
version=V1.0
|
|
287
|
+
merchant_index=123
|
|
288
|
+
card_expiry=12/10
|
|
289
|
+
training_mode=0
|
|
290
|
+
operator_no=10000
|
|
291
|
+
response_code=08
|
|
292
|
+
card_type=6
|
|
293
|
+
approved=1
|
|
294
|
+
cashout_amount=0
|
|
295
|
+
receipt_array=ARRAY(0x836a25c)
|
|
296
|
+
account_type=CREDIT A/C
|
|
297
|
+
result=1
|
|
298
|
+
== successful_capture
|
|
299
|
+
approved
|
|
300
|
+
00015X000000
|
|
301
|
+
Transaction No: 00000000
|
|
302
|
+
------------------------
|
|
303
|
+
MERCHANTNAME
|
|
304
|
+
LOCATION AU
|
|
305
|
+
|
|
306
|
+
MERCH ID 10000000
|
|
307
|
+
TERM ID Y0TR00
|
|
308
|
+
COUNTRY CODE AU
|
|
309
|
+
17/07/07 15:23
|
|
310
|
+
RRN 00015X000000
|
|
311
|
+
VISA
|
|
312
|
+
411111-111
|
|
313
|
+
CREDIT A/C 12/10
|
|
314
|
+
|
|
315
|
+
AUTHORISATION NO: 000000
|
|
316
|
+
APPROVED 08
|
|
317
|
+
|
|
318
|
+
PURCHASE $1.00
|
|
319
|
+
TOTAL AUD $1.00
|
|
320
|
+
|
|
321
|
+
PLEASE RETAIN AS RECORD
|
|
322
|
+
OF PURCHASE
|
|
323
|
+
|
|
324
|
+
(SUBJECT TO CARDHOLDER'S
|
|
325
|
+
ACCEPTANCE)
|
|
326
|
+
------------------------
|
|
327
|
+
.
|
|
328
|
+
settlement_date=17/07/07
|
|
329
|
+
card_desc=VISA
|
|
330
|
+
status=approved
|
|
331
|
+
txn_ref=0707171522000000
|
|
332
|
+
refund_mode=0
|
|
333
|
+
transaction_no=000000
|
|
334
|
+
rrn=00015X000000
|
|
335
|
+
response_text=SIGNATURE REQUIRED
|
|
336
|
+
pld=0
|
|
337
|
+
total_amount=100
|
|
338
|
+
card_no=4111111111111111
|
|
339
|
+
version=V1.0
|
|
340
|
+
merchant_index=123
|
|
341
|
+
card_expiry=12/10
|
|
342
|
+
training_mode=0
|
|
343
|
+
operator_no=10000
|
|
344
|
+
response_code=08
|
|
345
|
+
card_type=6
|
|
346
|
+
approved=1
|
|
347
|
+
cashout_amount=0
|
|
348
|
+
receipt_array=ARRAY(0x8378200)
|
|
349
|
+
account_type=CREDIT A/C
|
|
350
|
+
result=1
|
|
351
|
+
== successful_credit
|
|
352
|
+
approved
|
|
353
|
+
00015X000000
|
|
354
|
+
Transaction No: 00000000
|
|
355
|
+
------------------------
|
|
356
|
+
MERCHANTNAME
|
|
357
|
+
LOCATION AU
|
|
358
|
+
|
|
359
|
+
MERCH ID 10000000
|
|
360
|
+
TERM ID Y0TR00
|
|
361
|
+
COUNTRY CODE AU
|
|
362
|
+
16/07/07 19:03
|
|
363
|
+
RRN 00015X000000
|
|
364
|
+
VISA
|
|
365
|
+
411111-111
|
|
366
|
+
CREDIT A/C 12/10
|
|
367
|
+
|
|
368
|
+
AUTHORISATION NO:
|
|
369
|
+
APPROVED 08
|
|
370
|
+
|
|
371
|
+
** REFUND ** $1.00
|
|
372
|
+
TOTAL AUD $1.00
|
|
373
|
+
|
|
374
|
+
PLEASE RETAIN AS RECORD
|
|
375
|
+
OF REFUND
|
|
376
|
+
|
|
377
|
+
(SUBJECT TO CARDHOLDER'S
|
|
378
|
+
ACCEPTANCE)
|
|
379
|
+
------------------------
|
|
380
|
+
.
|
|
381
|
+
settlement_date=16/07/07
|
|
382
|
+
card_desc=VISA
|
|
383
|
+
status=approved
|
|
384
|
+
txn_ref=0707161902000000
|
|
385
|
+
refund_mode=1
|
|
386
|
+
transaction_no=000000
|
|
387
|
+
rrn=00015X000000
|
|
388
|
+
response_text=SIGNATURE REQUIRED
|
|
389
|
+
pld=0
|
|
390
|
+
total_amount=100
|
|
391
|
+
card_no=4111111111111111
|
|
392
|
+
version=V1.0
|
|
393
|
+
merchant_index=123
|
|
394
|
+
card_expiry=12/10
|
|
395
|
+
training_mode=0
|
|
396
|
+
operator_no=10000
|
|
397
|
+
response_code=08
|
|
398
|
+
card_type=6
|
|
399
|
+
approved=1
|
|
400
|
+
cashout_amount=0
|
|
401
|
+
receipt_array=ARRAY(0x837241c)
|
|
402
|
+
account_type=CREDIT A/C
|
|
403
|
+
result=1
|
|
404
|
+
== purchase_with_invalid_credit_card
|
|
405
|
+
declined
|
|
406
|
+
00015X000000
|
|
407
|
+
Transaction No: 00000000
|
|
408
|
+
------------------------
|
|
409
|
+
MERCHANTNAME
|
|
410
|
+
LOCATION AU
|
|
411
|
+
|
|
412
|
+
MERCH ID 10000000
|
|
413
|
+
TERM ID Y0TR40
|
|
414
|
+
COUNTRY CODE AU
|
|
415
|
+
16/07/07 19:20
|
|
416
|
+
RRN 00015X000000
|
|
417
|
+
VISA
|
|
418
|
+
411111-111
|
|
419
|
+
CREDIT A/C 12/10
|
|
420
|
+
|
|
421
|
+
AUTHORISATION NO:
|
|
422
|
+
DECLINED 31
|
|
423
|
+
|
|
424
|
+
PURCHASE $1.00
|
|
425
|
+
TOTAL AUD $1.00
|
|
426
|
+
|
|
427
|
+
(SUBJECT TO CARDHOLDER'S
|
|
428
|
+
ACCEPTANCE)
|
|
429
|
+
------------------------
|
|
430
|
+
.
|
|
431
|
+
settlement_date=16/07/07
|
|
432
|
+
card_desc=VISA
|
|
433
|
+
status=declined
|
|
434
|
+
txn_ref=0707161919000000
|
|
435
|
+
refund_mode=0
|
|
436
|
+
transaction_no=000000
|
|
437
|
+
rrn=00015X000000
|
|
438
|
+
response_text=INVALID CARD
|
|
439
|
+
pld=0
|
|
440
|
+
total_amount=100
|
|
441
|
+
card_no=4111111111111111
|
|
442
|
+
version=V1.0
|
|
443
|
+
merchant_index=123
|
|
444
|
+
card_expiry=12/10
|
|
445
|
+
training_mode=0
|
|
446
|
+
operator_no=10000
|
|
447
|
+
response_code=31
|
|
448
|
+
card_type=6
|
|
449
|
+
approved=0
|
|
450
|
+
cashout_amount=0
|
|
451
|
+
receipt_array=ARRAY(0x83752d0)
|
|
452
|
+
account_type=CREDIT A/C
|
|
453
|
+
result=0
|
|
454
|
+
== purchase_with_expired_credit_card
|
|
455
|
+
failed
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
.
|
|
459
|
+
response_text=CARD EXPIRED
|
|
460
|
+
approved=0
|
|
461
|
+
status=failed
|
|
462
|
+
txn_ref=0707161910000000
|
|
463
|
+
version=V1.0
|
|
464
|
+
pld=0
|
|
465
|
+
response_code=Q816
|
|
466
|
+
result=-1
|
|
467
|
+
== purchase_with_invalid_month
|
|
468
|
+
failed
|
|
469
|
+
Invalid month
|
|
470
|
+
== bad_login
|
|
471
|
+
failed
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
.
|
|
475
|
+
status=failed
|
|
476
|
+
result=-1
|
|
477
|
+
EOS
|
|
478
|
+
end
|