require File.dirname(__FILE__) + '/../../test_helper'
class PayflowExpressTest < Test::Unit::TestCase
def setup
Base.gateway_mode = :test
@gateway = PayflowExpressGateway.new(
:login => 'LOGIN',
:password => 'PASSWORD'
)
@address = { :address1 => '1234 My Street',
:address2 => 'Apt 1',
:company => 'Widgets Inc',
:city => 'Ottawa',
:state => 'ON',
:zip => 'K1C2N6',
:country => 'Canada',
:phone => '(555)555-5555'
}
end
def teardown
Base.gateway_mode = :test
end
def test_using_test_mode
assert @gateway.test?
end
def test_overriding_test_mode
Base.gateway_mode = :production
gateway = PayflowExpressGateway.new(
:login => 'LOGIN',
:password => 'PASSWORD',
:test => true
)
assert gateway.test?
end
def test_using_production_mode
Base.gateway_mode = :production
gateway = PayflowExpressGateway.new(
:login => 'LOGIN',
:password => 'PASSWORD'
)
assert !gateway.test?
end
def test_live_redirect_url
Base.gateway_mode = :production
assert_equal 'https://www.paypal.com/cgibin/webscr?cmd=_express-checkout&token=1234567890', @gateway.redirect_url_for('1234567890')
end
def test_test_redirect_url
assert_equal 'https://test-expresscheckout.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=1234567890', @gateway.redirect_url_for('1234567890')
end
def test_invalid_get_express_details_request
@gateway.expects(:ssl_post).returns(invalid_get_express_details_response)
response = @gateway.details_for('EC-2OPN7UJGFWK9OYFV')
assert_failure response
assert response.test?
assert_equal 'Field format error: Invalid Token', response.message
end
def test_get_express_details
@gateway.expects(:ssl_post).returns(successful_get_express_details_response)
response = @gateway.details_for('EC-2OPN7UJGFWK9OYFV')
assert_instance_of PayflowExpressResponse, response
assert_success response
assert response.test?
assert_equal 'EC-2OPN7UJGFWK9OYFV', response.token
assert_equal '12345678901234567', response.payer_id
assert_equal 'Buyer1@paypal.com', response.email
assert_equal 'Joe Smith', response.full_name
assert_equal 'US', response.payer_country
assert address = response.address
assert_equal 'Joe Smith', address['name']
assert_nil address['company']
assert_equal '111 Main St.', address['address1']
assert_nil address['address2']
assert_equal 'San Jose', address['city']
assert_equal 'CA', address['state']
assert_equal '95100', address['zip']
assert_equal 'US', address['country']
assert_nil address['phone']
end
def test_button_source
xml = Builder::XmlMarkup.new
@gateway.send(:add_paypal_details, xml, {})
xml_doc = REXML::Document.new(xml.target!)
assert_equal 'ActiveMerchant', REXML::XPath.first(xml_doc, '/PayPal/ButtonSource').text
end
private
def successful_get_express_details_response
<<-RESPONSE
TEST
verisign
0
Approved
Buyer1@paypal.com
12345678901234567
EC-2OPN7UJGFWK9OYFV
0
verified
Joe
111 Main St.
San Jose
CA
95100
US
9c3706997455e
RESPONSE
end
def invalid_get_express_details_response
<<-RESPONSE
TEST
verisign
7
Field format error: Invalid Token
RESPONSE
end
end