@@ -5,15 +5,15 @@ class PayflowExpressTest < Test::Unit::TestCase
5
5
TEST_REDIRECT_URL_MOBILE = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile&token=1234567890'
6
6
LIVE_REDIRECT_URL = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=1234567890'
7
7
LIVE_REDIRECT_URL_MOBILE = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile&token=1234567890'
8
-
8
+
9
9
TEST_REDIRECT_URL_WITHOUT_REVIEW = "#{ TEST_REDIRECT_URL } &useraction=commit"
10
10
LIVE_REDIRECT_URL_WITHOUT_REVIEW = "#{ LIVE_REDIRECT_URL } &useraction=commit"
11
11
TEST_REDIRECT_URL_MOBILE_WITHOUT_REVIEW = "#{ TEST_REDIRECT_URL_MOBILE } &useraction=commit"
12
12
LIVE_REDIRECT_URL_MOBILE_WITHOUT_REVIEW = "#{ LIVE_REDIRECT_URL_MOBILE } &useraction=commit"
13
-
13
+
14
14
def setup
15
15
Base . mode = :test
16
-
16
+
17
17
@gateway = PayflowExpressGateway . new (
18
18
:login => 'LOGIN' ,
19
19
:password => 'PASSWORD'
@@ -29,82 +29,82 @@ def setup
29
29
:phone => '(555)555-5555'
30
30
}
31
31
end
32
-
32
+
33
33
def teardown
34
34
Base . mode = :test
35
35
end
36
-
36
+
37
37
def test_using_test_mode
38
38
assert @gateway . test?
39
39
end
40
-
40
+
41
41
def test_overriding_test_mode
42
42
Base . mode = :production
43
-
43
+
44
44
gateway = PayflowExpressGateway . new (
45
45
:login => 'LOGIN' ,
46
46
:password => 'PASSWORD' ,
47
47
:test => true
48
48
)
49
-
49
+
50
50
assert gateway . test?
51
51
end
52
-
52
+
53
53
def test_using_production_mode
54
54
Base . mode = :production
55
-
55
+
56
56
gateway = PayflowExpressGateway . new (
57
57
:login => 'LOGIN' ,
58
58
:password => 'PASSWORD'
59
59
)
60
-
60
+
61
61
assert !gateway . test?
62
62
end
63
-
63
+
64
64
def test_live_redirect_url
65
65
Base . mode = :production
66
66
assert_equal LIVE_REDIRECT_URL , @gateway . redirect_url_for ( '1234567890' )
67
67
assert_equal LIVE_REDIRECT_URL_MOBILE , @gateway . redirect_url_for ( '1234567890' , :mobile => true )
68
68
end
69
-
69
+
70
70
def test_test_redirect_url
71
71
assert_equal TEST_REDIRECT_URL , @gateway . redirect_url_for ( '1234567890' )
72
72
assert_equal TEST_REDIRECT_URL_MOBILE , @gateway . redirect_url_for ( '1234567890' , :mobile => true )
73
73
end
74
-
74
+
75
75
def test_live_redirect_url_without_review
76
76
Base . mode = :production
77
77
assert_equal LIVE_REDIRECT_URL_WITHOUT_REVIEW , @gateway . redirect_url_for ( '1234567890' , :review => false )
78
78
assert_equal LIVE_REDIRECT_URL_MOBILE_WITHOUT_REVIEW , @gateway . redirect_url_for ( '1234567890' , :review => false , :mobile => true )
79
79
end
80
-
80
+
81
81
def test_test_redirect_url_without_review
82
82
assert_equal :test , Base . mode
83
83
assert_equal TEST_REDIRECT_URL_WITHOUT_REVIEW , @gateway . redirect_url_for ( '1234567890' , :review => false )
84
84
assert_equal TEST_REDIRECT_URL_MOBILE_WITHOUT_REVIEW , @gateway . redirect_url_for ( '1234567890' , :review => false , :mobile => true )
85
85
end
86
-
86
+
87
87
def test_invalid_get_express_details_request
88
88
@gateway . expects ( :ssl_post ) . returns ( invalid_get_express_details_response )
89
89
response = @gateway . details_for ( 'EC-2OPN7UJGFWK9OYFV' )
90
90
assert_failure response
91
91
assert response . test?
92
92
assert_equal 'Field format error: Invalid Token' , response . message
93
93
end
94
-
94
+
95
95
def test_get_express_details
96
96
@gateway . expects ( :ssl_post ) . returns ( successful_get_express_details_response )
97
97
response = @gateway . details_for ( 'EC-2OPN7UJGFWK9OYFV' )
98
98
assert_instance_of PayflowExpressResponse , response
99
99
assert_success response
100
100
assert response . test?
101
-
101
+
102
102
assert_equal 'EC-2OPN7UJGFWK9OYFV' , response . token
103
103
assert_equal '12345678901234567' , response . payer_id
104
104
assert_equal 'Buyer1@paypal.com' , response . email
105
105
assert_equal 'Joe Smith' , response . full_name
106
106
assert_equal 'US' , response . payer_country
107
-
107
+
108
108
assert address = response . address
109
109
assert_equal 'Joe Smith' , address [ 'name' ]
110
110
assert_nil address [ 'company' ]
@@ -117,6 +117,31 @@ def test_get_express_details
117
117
assert_nil address [ 'phone' ]
118
118
end
119
119
120
+ def test_get_express_details_with_ship_to_name
121
+ @gateway . expects ( :ssl_post ) . returns ( successful_get_express_details_response_with_ship_to_name )
122
+ response = @gateway . details_for ( 'EC-2OPN7UJGFWK9OYFV' )
123
+ assert_instance_of PayflowExpressResponse , response
124
+ assert_success response
125
+ assert response . test?
126
+
127
+ assert_equal 'EC-2OPN7UJGFWK9OYFV' , response . token
128
+ assert_equal '12345678901234567' , response . payer_id
129
+ assert_equal 'Buyer1@paypal.com' , response . email
130
+ assert_equal 'Joe Smith' , response . full_name
131
+ assert_equal 'US' , response . payer_country
132
+
133
+ assert address = response . address
134
+ assert_equal 'John Joseph' , address [ 'name' ]
135
+ assert_nil address [ 'company' ]
136
+ assert_equal '111 Main St.' , address [ 'address1' ]
137
+ assert_nil address [ 'address2' ]
138
+ assert_equal 'San Jose' , address [ 'city' ]
139
+ assert_equal 'CA' , address [ 'state' ]
140
+ assert_equal '95100' , address [ 'zip' ]
141
+ assert_equal 'US' , address [ 'country' ]
142
+ assert_nil address [ 'phone' ]
143
+ end
144
+
120
145
def test_get_express_details_with_invalid_xml
121
146
@gateway . expects ( :ssl_post ) . returns ( successful_get_express_details_response ( :street => 'Main & Magic' ) )
122
147
response = @gateway . details_for ( 'EC-2OPN7UJGFWK9OYFV' )
@@ -134,9 +159,9 @@ def test_button_source
134
159
xml_doc = REXML ::Document . new ( xml . target! )
135
160
assert_nil REXML ::XPath . first ( xml_doc , '/PayPal/ButtonSource' )
136
161
end
137
-
162
+
138
163
private
139
-
164
+
140
165
def successful_get_express_details_response ( options = { :street => '111 Main St.' } )
141
166
<<-RESPONSE
142
167
<XMLPayResponse xmlns='http://www.verisign.com/XMLPay'>
@@ -172,7 +197,44 @@ def successful_get_express_details_response(options={:street => '111 Main St.'})
172
197
</XMLPayResponse>
173
198
RESPONSE
174
199
end
175
-
200
+
201
+ def successful_get_express_details_response_with_ship_to_name
202
+ <<-RESPONSE
203
+ <XMLPayResponse xmlns='http://www.verisign.com/XMLPay'>
204
+ <ResponseData>
205
+ <Vendor>TEST</Vendor>
206
+ <Partner>verisign</Partner>
207
+ <TransactionResults>
208
+ <TransactionResult>
209
+ <Result>0</Result>
210
+ <Message>Approved</Message>
211
+ <PayPalResult>
212
+ <EMail>Buyer1@paypal.com</EMail>
213
+ <PayerID>12345678901234567</PayerID>
214
+ <Token>EC-2OPN7UJGFWK9OYFV</Token>
215
+ <FeeAmount>0</FeeAmount>
216
+ <PayerStatus>verified</PayerStatus>
217
+ <Name>Joe</Name>
218
+ <ShipTo>
219
+ <Address>
220
+ <Street>111 Main St.</Street>
221
+ <City>San Jose</City>
222
+ <State>CA</State>
223
+ <Zip>95100</Zip>
224
+ <Country>US</Country>
225
+ </Address>
226
+ </ShipTo>
227
+ <CorrelationID>9c3706997455e</CorrelationID>
228
+ </PayPalResult>
229
+ <ExtData Name='LASTNAME' Value='Smith'/>
230
+ <ExtData Name='SHIPTONAME' Value='John Joseph'/>
231
+ </TransactionResult>
232
+ </TransactionResults>
233
+ </ResponseData>
234
+ </XMLPayResponse>
235
+ RESPONSE
236
+ end
237
+
176
238
def invalid_get_express_details_response
177
239
<<-RESPONSE
178
240
<XMLPayResponse xmlns='http://www.verisign.com/XMLPay'>
@@ -186,7 +248,7 @@ def invalid_get_express_details_response
186
248
</TransactionResult>
187
249
</TransactionResults>
188
250
</ResponseData>
189
- </XMLPayResponse>
251
+ </XMLPayResponse>
190
252
RESPONSE
191
253
end
192
254
end
0 commit comments