-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathcams_test.rb
209 lines (165 loc) · 7.68 KB
/
cams_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
require 'test_helper'
class CamsTest < Test::Unit::TestCase
def setup
@gateway = CamsGateway.new(
username: 'testintegrationc',
password: 'password9'
)
@credit_card = credit_card('4111111111111111', month: 5, year: 10)
@bad_credit_card = credit_card('4242424245555555', month: 5, year: 10)
@amount = 100
@options = {
order_id: Time.now.to_s,
billing_address: address,
description: 'Store Purchase'
}
end
def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert_equal '2654605773#54321', response.authorization
end
def test_failed_purchase
@gateway.expects(:ssl_post).returns(failed_purchase_response)
response = @gateway.purchase(@amount, @bad_credit_card, @options)
assert_failure response
assert_equal Gateway::STANDARD_ERROR_CODE[:card_declined], response.error_code
end
def test_successful_authorize
@gateway.expects(:ssl_post).returns(successful_authorize_response)
response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
end
def test_failed_authorize
@gateway.expects(:ssl_post).returns(successful_authorize_response)
response = @gateway.authorize(@amount, @bad_credit_card, @options)
assert_success response
end
def test_successful_capture
authorization = '12345678#54321'
@gateway.expects(:ssl_post).returns(successful_capture_response)
assert capture = @gateway.capture(@amount, authorization)
assert_success capture
end
def test_failed_capture
@gateway.expects(:ssl_post).returns(failed_capture_response)
response = @gateway.capture(nil, '')
assert_failure response
end
def test_successful_refund
authorization = '12345678#54321'
@gateway.expects(:ssl_post).returns(successful_refund_response)
assert refund = @gateway.refund(nil, authorization)
assert_success refund
end
def test_failed_refund
@gateway.expects(:ssl_post).returns(failed_refund_response)
response = @gateway.refund(nil, '')
assert_failure response
end
def test_successful_void
authorization = '12345678#54321'
@gateway.expects(:ssl_post).returns(successful_void_response)
assert void = @gateway.void(authorization)
assert_success void
end
def test_failed_void
@gateway.expects(:ssl_post).returns(failed_void_response)
response = @gateway.void('')
assert_failure response
end
def test_successful_verify
@gateway.expects(:ssl_post).returns(successful_verify_response)
assert verify = @gateway.verify(@credit_card, @options)
assert_success verify
end
def test_failed_verify
@gateway.expects(:ssl_post).returns(failed_verify_response)
assert verify = @gateway.verify(@bad_credit_card, @options)
assert_failure verify
end
def test_scrub
assert @gateway.supports_scrubbing?
assert_equal @gateway.scrub(pre_scrubbed), post_scrubbed
end
private
def pre_scrubbed
<<~PRE_SCRUBBED
opening connection to secure.centralams.com:443...
opened
starting SSL for secure.centralams.com:443...
SSL established
<- "POST /gw/api/transact.php HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: secure.centralams.com\r\nContent-Length: 249\r\n\r\n"
<- "amount=1.03¤cy=USD&ccnumber=4111111111111111&ccexp=0916&firstname=Longbob&lastname=Longsen&address1=1234 My Street&address2=Apt 1&city=Ottawa&state=ON&zip=K1C2N6&country=US&phone=(555)555-5555&type=&password=password9&username=testintegrationc"
-> "HTTP/1.1 200 OK\r\n"
-> "Date: Tue, 21 Apr 2015 23:27:05 GMT\r\n"
-> "Server: Apache\r\n"
-> "Content-Length: 132\r\n"
-> "Connection: close\r\n"
-> "Content-Type: text/html; charset=UTF-8\r\n"
-> "\r\n"
reading 132 bytes...
-> "response=1&responsetext=SUCCESS&authcode=123456&transactionid=2654605773&avsresponse=N&cvvresponse=&orderid=&type=&response_code=100"
read 132 bytes
Conn close
PRE_SCRUBBED
end
def post_scrubbed
<<~POST_SCRUBBED
opening connection to secure.centralams.com:443...
opened
starting SSL for secure.centralams.com:443...
SSL established
<- "POST /gw/api/transact.php HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: secure.centralams.com\r\nContent-Length: 249\r\n\r\n"
<- "amount=1.03¤cy=USD&ccnumber=[FILTERED]&ccexp=0916&firstname=Longbob&lastname=Longsen&address1=1234 My Street&address2=Apt 1&city=Ottawa&state=ON&zip=K1C2N6&country=US&phone=(555)555-5555&type=&password=[FILTERED]&username=testintegrationc"
-> "HTTP/1.1 200 OK\r\n"
-> "Date: Tue, 21 Apr 2015 23:27:05 GMT\r\n"
-> "Server: Apache\r\n"
-> "Content-Length: 132\r\n"
-> "Connection: close\r\n"
-> "Content-Type: text/html; charset=UTF-8\r\n"
-> "\r\n"
reading 132 bytes...
-> "response=1&responsetext=SUCCESS&authcode=123456&transactionid=2654605773&avsresponse=N&cvvresponse=&orderid=&type=&response_code=100"
read 132 bytes
Conn close
POST_SCRUBBED
end
def successful_purchase_response
%(response=1&responsetext=SUCCESS&authcode=54321&transactionid=2654605773&avsresponse=N&cvvresponse=&orderid=&type=&response_code=100)
end
def failed_purchase_response
%(response=3&responsetext=Invalid Credit Card Number REFID:3154273850&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=&response_code=300)
end
def successful_authorize_response
%(response=1&responsetext=SUCCESS&authcode=123456&transactionid=2655819372&avsresponse=N&cvvresponse=N&orderid=&type=auth&response_code=100)
end
def failed_authorize_response
%(response=3&responsetext=Invalid Credit Card Number REFID:3154292176&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=auth&response_code=300)
end
def successful_capture_response
%(response=1&responsetext=SUCCESS&authcode=123456&transactionid=2655840929&avsresponse=&cvvresponse=&orderid=&type=capture&response_code=100)
end
def failed_capture_response
%(response=3&responsetext=Invalid Transaction ID / Object ID specified: REFID:3154293596&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=capture&response_code=300)
end
def successful_refund_response
%(response=1&responsetext=SUCCESS&authcode=&transactionid=2655841010&avsresponse=&cvvresponse=&orderid=&type=refund&response_code=100)
end
def failed_refund_response
%(response=3&responsetext=Invalid Transaction ID / Object ID specified: REFID:3154293755&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=refund&response_code=300)
end
def successful_void_response
%(response=1&responsetext=Transaction Void Successful&authcode=123456&transactionid=2655848058&avsresponse=&cvvresponse=&orderid=&type=void&response_code=100)
end
def failed_void_response
%(response=3&responsetext=Invalid Transaction ID / Object ID specified: REFID:3154293864&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=void&response_code=300)
end
def successful_verify_response
%(response=1&responsetext=&authcode=&transactionid=2656803675&avsresponse=&cvvresponse=&orderid=&type=verify&response_code=100)
end
def failed_verify_response
%(response=3&responsetext=Invalid Credit Card Number REFID:3154354764&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=verify&response_code=300)
end
end