require 'test_helper'
class PsigateTest < Test::Unit::TestCase
def setup
@gateway = PsigateGateway.new(
:login => 'teststore',
:password => 'psigate1234'
)
@amount = 100
@credit_card = credit_card('4111111111111111')
@options = { :order_id => 1, :billing_address => address }
end
def test_successful_authorization
@gateway.expects(:ssl_post).returns(successful_authorization_response)
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_success response
assert_equal '1000', response.authorization
end
def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_success response
assert_equal '1000', response.authorization
end
def test_failed_purchase
@gateway.expects(:ssl_post).returns(failed_purchase_response)
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_failure response
end
def test_amount_style
assert_equal '10.34', @gateway.send(:amount, 1034)
assert_raise(ArgumentError) do
@gateway.send(:amount, '10.34')
end
end
def test_supported_countries
assert_equal ['CA'], PsigateGateway.supported_countries
end
def test_supported_card_types
assert_equal [:visa, :master, :american_express], PsigateGateway.supported_cardtypes
end
def test_avs_result
@gateway.expects(:ssl_post).returns(successful_authorization_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'X', response.avs_result['code']
end
def test_cvv_result
@gateway.expects(:ssl_post).returns(successful_authorization_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'M', response.cvv_result['code']
end
private
def successful_authorization_response
<<-RESPONSE
Sun Jan 06 23:10:53 EST 2008
1000
PREAUTH
APPROVED
Y:123456:0abcdef:M:X:NNN
0.00
0.00
24.00
24.00
CC
......4242
1bdde305d7658367
M
X
123456
0abcdef
VISA
NNN
UN
UNKNOWN
UNKNOWN
RESPONSE
end
def successful_purchase_response
<<-RESPONSE
Sun Jan 06 23:15:30 EST 2008
1000
SALE
APPROVED
Y:123456:0abcdef:M:X:NNN
0.00
0.00
24.00
24.00
CC
......4242
1bdde305da3ee234
M
X
123456
0abcdef
VISA
NNN
UN
UNKNOWN
UNKNOWN
RESPONSE
end
def failed_purchase_response
<<-RESPONSE
Sun Jan 06 23:24:29 EST 2008
b3dca49e3ec77e42ab80a0f0f590fff0
SALE
DECLINED
N:TESTDECLINE
0.00
0.00
24.00
24.00
CC
......4242
1bdde305df991f89
M
X
TEST
TESTTRANS
VISA
NNN
UN
UNKNOWN
UNKNOWN
RESPONSE
end
def xml_purchase_fixture
'New York1004U.S.A.0123 fairweather LaneteststoreNY4111111111111111CC20.00psigate123408Apt B10010Longbob Longsen07jack@yahoo.com'
end
def xml_capture_fixture
'10042teststoreCC20.00psigate1234'
end
end