require 'test_helper' class SecurePayAuTest < Test::Unit::TestCase def setup @gateway = SecurePayAuGateway.new( :login => 'login', :password => 'password' ) @credit_card = credit_card @amount = 100 @options = { :order_id => '1', :billing_address => address, :description => 'Store Purchase' } end def test_successful_purchase_with_live_data @gateway.expects(:ssl_post).returns(successful_live_purchase_response) assert response = @gateway.purchase(@amount, @credit_card, @options) assert_instance_of Response, response assert_success response assert_equal '000000', response.authorization assert response.test? end def test_successful_purchase @gateway.expects(:ssl_post).returns(successful_purchase_response) assert response = @gateway.purchase(@amount, @credit_card, @options) assert_instance_of Response, response assert_success response assert_equal '024259', response.authorization assert response.test? end def test_unsuccessful_purchase @gateway.expects(:ssl_post).returns(failed_purchase_response) assert response = @gateway.purchase(@amount, @credit_card, @options) assert_instance_of Response, response assert_failure response assert response.test? assert_equal "CARD EXPIRED", response.message end def test_failed_login @gateway.expects(:ssl_post).returns(failed_login_response) assert response = @gateway.purchase(@amount, @credit_card, @options) assert_instance_of Response, response assert_failure response assert_equal "Invalid merchant ID", response.message end private def failed_login_response '504Invalid merchant ID' end def successful_purchase_response <<-XML 8af793f9af34bea0cf40f5fb5c630c 20080802041625665000+660 xml-4.2 Payment XYZ0001 000 Normal 0 0 1000 AUD test Yes 00 Approved 100 000 000 Normal 20080208 024259 424242...242 07/11 6 Visa XML end def failed_purchase_response <<-XML 8af793f9af34bea0cf40f5fb5c630c 20080802040346380000+660 xml-4.2 Payment XYZ0001 000 Normal 0 0 1000 AUD test No 907 CARD EXPIRED 300 000 981 Error - Expired Card 000000 424242...242 07/06 6 Visa XML end def successful_live_purchase_response <<-XML 8af793f9af34bea0cf40f5fb5c630c 20080802041625665000+660 xml-4.2 Payment XYZ0001 000 Normal 0 23 211700 AUD #1047.5 Yes 77 Approved 100 000 000 Normal 20080525 000000 424242...242 07/11 6 Visa XML end end