Skip to content

Commit 3baa26e

Browse files
authored
Use SHIPTONAME instead of full_name for Payflow Express (activemerchant#2945)
* Remove whitespaces * Use primarily SHIPTONAME for Payflow Express `full_name` is not necessarily the person receiving the products being bought, it's the buyer account owner name, many time SHIPTONAME and `full_name` would be the same, but in others, products could be a gift to someone else, shipped to their address.
1 parent ab51e8c commit 3baa26e

File tree

3 files changed

+162
-30
lines changed

3 files changed

+162
-30
lines changed

lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ class PayflowExpressResponse < Response
44
def email
55
@params['e_mail']
66
end
7-
7+
88
def full_name
99
"#{@params['name']} #{@params['lastname']}"
1010
end
11-
11+
1212
def token
1313
@params['token']
1414
end
15-
15+
1616
def payer_id
1717
@params['payer_id']
1818
end
19-
19+
2020
# Really the shipping country, but it is all the information provided
2121
def payer_country
2222
address['country']
2323
end
24-
24+
2525
def address
26-
{ 'name' => full_name,
26+
{ 'name' => @params['shiptoname'] || full_name,
2727
'company' => nil,
2828
'address1' => @params['street'],
2929
'address2' => @params['shiptostreet2'] || @params['street2'],

test/unit/gateways/payflow_express_test.rb

+85-23
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ class PayflowExpressTest < Test::Unit::TestCase
55
TEST_REDIRECT_URL_MOBILE = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile&token=1234567890'
66
LIVE_REDIRECT_URL = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=1234567890'
77
LIVE_REDIRECT_URL_MOBILE = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile&token=1234567890'
8-
8+
99
TEST_REDIRECT_URL_WITHOUT_REVIEW = "#{TEST_REDIRECT_URL}&useraction=commit"
1010
LIVE_REDIRECT_URL_WITHOUT_REVIEW = "#{LIVE_REDIRECT_URL}&useraction=commit"
1111
TEST_REDIRECT_URL_MOBILE_WITHOUT_REVIEW = "#{TEST_REDIRECT_URL_MOBILE}&useraction=commit"
1212
LIVE_REDIRECT_URL_MOBILE_WITHOUT_REVIEW = "#{LIVE_REDIRECT_URL_MOBILE}&useraction=commit"
13-
13+
1414
def setup
1515
Base.mode = :test
16-
16+
1717
@gateway = PayflowExpressGateway.new(
1818
:login => 'LOGIN',
1919
:password => 'PASSWORD'
@@ -29,82 +29,82 @@ def setup
2929
:phone => '(555)555-5555'
3030
}
3131
end
32-
32+
3333
def teardown
3434
Base.mode = :test
3535
end
36-
36+
3737
def test_using_test_mode
3838
assert @gateway.test?
3939
end
40-
40+
4141
def test_overriding_test_mode
4242
Base.mode = :production
43-
43+
4444
gateway = PayflowExpressGateway.new(
4545
:login => 'LOGIN',
4646
:password => 'PASSWORD',
4747
:test => true
4848
)
49-
49+
5050
assert gateway.test?
5151
end
52-
52+
5353
def test_using_production_mode
5454
Base.mode = :production
55-
55+
5656
gateway = PayflowExpressGateway.new(
5757
:login => 'LOGIN',
5858
:password => 'PASSWORD'
5959
)
60-
60+
6161
assert !gateway.test?
6262
end
63-
63+
6464
def test_live_redirect_url
6565
Base.mode = :production
6666
assert_equal LIVE_REDIRECT_URL, @gateway.redirect_url_for('1234567890')
6767
assert_equal LIVE_REDIRECT_URL_MOBILE, @gateway.redirect_url_for('1234567890', :mobile => true)
6868
end
69-
69+
7070
def test_test_redirect_url
7171
assert_equal TEST_REDIRECT_URL, @gateway.redirect_url_for('1234567890')
7272
assert_equal TEST_REDIRECT_URL_MOBILE, @gateway.redirect_url_for('1234567890', :mobile => true)
7373
end
74-
74+
7575
def test_live_redirect_url_without_review
7676
Base.mode = :production
7777
assert_equal LIVE_REDIRECT_URL_WITHOUT_REVIEW, @gateway.redirect_url_for('1234567890', :review => false)
7878
assert_equal LIVE_REDIRECT_URL_MOBILE_WITHOUT_REVIEW, @gateway.redirect_url_for('1234567890', :review => false, :mobile => true)
7979
end
80-
80+
8181
def test_test_redirect_url_without_review
8282
assert_equal :test, Base.mode
8383
assert_equal TEST_REDIRECT_URL_WITHOUT_REVIEW, @gateway.redirect_url_for('1234567890', :review => false)
8484
assert_equal TEST_REDIRECT_URL_MOBILE_WITHOUT_REVIEW, @gateway.redirect_url_for('1234567890', :review => false, :mobile => true)
8585
end
86-
86+
8787
def test_invalid_get_express_details_request
8888
@gateway.expects(:ssl_post).returns(invalid_get_express_details_response)
8989
response = @gateway.details_for('EC-2OPN7UJGFWK9OYFV')
9090
assert_failure response
9191
assert response.test?
9292
assert_equal 'Field format error: Invalid Token', response.message
9393
end
94-
94+
9595
def test_get_express_details
9696
@gateway.expects(:ssl_post).returns(successful_get_express_details_response)
9797
response = @gateway.details_for('EC-2OPN7UJGFWK9OYFV')
9898
assert_instance_of PayflowExpressResponse, response
9999
assert_success response
100100
assert response.test?
101-
101+
102102
assert_equal 'EC-2OPN7UJGFWK9OYFV', response.token
103103
assert_equal '12345678901234567', response.payer_id
104104
assert_equal 'Buyer1@paypal.com', response.email
105105
assert_equal 'Joe Smith', response.full_name
106106
assert_equal 'US', response.payer_country
107-
107+
108108
assert address = response.address
109109
assert_equal 'Joe Smith', address['name']
110110
assert_nil address['company']
@@ -117,6 +117,31 @@ def test_get_express_details
117117
assert_nil address['phone']
118118
end
119119

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+
120145
def test_get_express_details_with_invalid_xml
121146
@gateway.expects(:ssl_post).returns(successful_get_express_details_response(:street => 'Main & Magic'))
122147
response = @gateway.details_for('EC-2OPN7UJGFWK9OYFV')
@@ -134,9 +159,9 @@ def test_button_source
134159
xml_doc = REXML::Document.new(xml.target!)
135160
assert_nil REXML::XPath.first(xml_doc, '/PayPal/ButtonSource')
136161
end
137-
162+
138163
private
139-
164+
140165
def successful_get_express_details_response(options={:street => '111 Main St.'})
141166
<<-RESPONSE
142167
<XMLPayResponse xmlns='http://www.verisign.com/XMLPay'>
@@ -172,7 +197,44 @@ def successful_get_express_details_response(options={:street => '111 Main St.'})
172197
</XMLPayResponse>
173198
RESPONSE
174199
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+
176238
def invalid_get_express_details_response
177239
<<-RESPONSE
178240
<XMLPayResponse xmlns='http://www.verisign.com/XMLPay'>
@@ -186,7 +248,7 @@ def invalid_get_express_details_response
186248
</TransactionResult>
187249
</TransactionResults>
188250
</ResponseData>
189-
</XMLPayResponse>
251+
</XMLPayResponse>
190252
RESPONSE
191253
end
192254
end

test/unit/gateways/payflow_express_uk_test.rb

+71-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ def test_get_express_details
3737
assert_nil address['phone']
3838
end
3939

40+
def test_get_express_details_with_ship_to_name
41+
@gateway.expects(:ssl_post).returns(successful_get_express_details_response_with_ship_to_name)
42+
response = @gateway.details_for('EC-2OPN7UJGFWK9OYFV')
43+
assert_instance_of PayflowExpressResponse, response
44+
assert_success response
45+
assert response.test?
46+
47+
assert_equal 'EC-2OPN7UJGFWK9OYFV', response.token
48+
assert_equal 'LYWCMEN4FA7ZQ', response.payer_id
49+
assert_equal 'paul@test.com', response.email
50+
assert_equal 'paul smith', response.full_name
51+
assert_equal 'GB', response.payer_country
52+
53+
assert address = response.address
54+
assert_equal 'John Joseph', address['name']
55+
assert_nil address['company']
56+
assert_equal '10 keyworth avenue', address['address1']
57+
assert_equal 'grangetown', address['address2']
58+
assert_equal 'hinterland', address['city']
59+
assert_equal 'Tyne and Wear', address['state']
60+
assert_equal 'sr5 2uh', address['zip']
61+
assert_equal 'GB', address['country']
62+
assert_nil address['phone']
63+
end
64+
4065
private
4166
def successful_get_express_details_response
4267
<<-RESPONSE
@@ -73,7 +98,52 @@ def successful_get_express_details_response
7398
</PayPalResult>
7499
<ExtData Name="LASTNAME" Value="smith"/>
75100
<ExtData Name="SHIPTOSTREET2" Value="grangetown"/>
76-
<ExtData Name="SHIPTONAME" Value="paul smith"/>
101+
<ExtData Name="STREET2" Value="ALLAWAY AVENUE"/>
102+
<ExtData Name="COUNTRYCODE" Value="GB"/>
103+
<ExtData Name="ADDRESSSTATUS" Value="Y"/>
104+
</TransactionResult>
105+
</TransactionResults>
106+
</ResponseData>
107+
</XMLPayResponse>
108+
RESPONSE
109+
end
110+
111+
def successful_get_express_details_response_with_ship_to_name
112+
<<-RESPONSE
113+
<?xml version="1.0"?>
114+
<XMLPayResponse xmlns="http://www.paypal.com/XMLPay">
115+
<ResponseData>
116+
<Vendor>markcoop</Vendor>
117+
<Partner>paypaluk</Partner>
118+
<TransactionResults>
119+
<TransactionResult>
120+
<Result>0</Result>
121+
<AVSResult>
122+
<StreetMatch>Match</StreetMatch>
123+
<ZipMatch>Match</ZipMatch>
124+
</AVSResult>
125+
<Message>Approved</Message>
126+
<PayPalResult>
127+
<EMail>paul@test.com</EMail>
128+
<PayerID>LYWCMEN4FA7ZQ</PayerID>
129+
<Token>EC-2OPN7UJGFWK9OYFV</Token>
130+
<FeeAmount>0</FeeAmount>
131+
<PayerStatus>unverified</PayerStatus>
132+
<Name>paul</Name>
133+
<ShipTo>
134+
<Address>
135+
<Street>10 keyworth avenue</Street>
136+
<City>hinterland</City>
137+
<State>Tyne and Wear</State>
138+
<Zip>sr5 2uh</Zip>
139+
<Country>GB</Country>
140+
</Address>
141+
</ShipTo>
142+
<CorrelationID>1ea22ef3873ba</CorrelationID>
143+
</PayPalResult>
144+
<ExtData Name="LASTNAME" Value="smith"/>
145+
<ExtData Name="SHIPTOSTREET2" Value="grangetown"/>
146+
<ExtData Name="SHIPTONAME" Value="John Joseph"/>
77147
<ExtData Name="STREET2" Value="ALLAWAY AVENUE"/>
78148
<ExtData Name="COUNTRYCODE" Value="GB"/>
79149
<ExtData Name="ADDRESSSTATUS" Value="Y"/>

0 commit comments

Comments
 (0)