require File.dirname(__FILE__) + '/../../test_helper'
class ExactTest < Test::Unit::TestCase
def setup
@gateway = ExactGateway.new( :login => "A00427-01",
:password => "testus" )
@credit_card = credit_card
@amount = 100
@options = {
:order_id => '1',
:billing_address => address,
:description => 'Store Purchase'
}
end
def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert_equal 'ET1700;106625152', response.authorization
assert response.test?
assert_equal 'Transaction Normal - VER UNAVAILABLE', response.message
ExactGateway::SENSITIVE_FIELDS.each{ |f| assert !response.params.has_key?(f.to_s) }
end
def test_failed_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
end
def test_expdate
assert_equal( "%02d%s" % [ @credit_card.month,
@credit_card.year.to_s[-2..-1] ],
@gateway.send(:expdate, @credit_card) )
end
def test_soap_fault
@gateway.expects(:ssl_post).returns(soap_fault_response)
assert response = @gateway.purchase(100, @credit_card, {})
assert_failure response
assert response.test?
assert_equal 'Unable to handle request without a valid action parameter. Please supply a valid soap action.', response.message
end
def test_supported_countries
assert_equal ['CA', 'US'], ExactGateway.supported_countries
end
def test_supported_card_types
assert_equal [:visa, :master, :american_express, :jcb, :discover], ExactGateway.supported_cardtypes
end
def test_avs_result
@gateway.expects(:ssl_post).returns(successful_purchase_response)
response = @gateway.purchase(@amount, @credit_card)
assert_equal 'U', response.avs_result['code']
end
def test_cvv_result
@gateway.expects(:ssl_post).returns(successful_purchase_response)
response = @gateway.purchase(@amount, @credit_card)
assert_equal 'M', response.cvv_result['code']
end
private
def successful_purchase_response
<<-RESPONSE
A00427-01#######00104242424242424242106625152ET17000909Longbob Longsen123100001Store Purchase0Processed by:
E-xact Transaction Gateway :- Version 8.4.0 B19b
Copyright 2006
{34:2652}0falsetrue00Transaction Normal00VER UNAVAILABLE 377UM200801181700E-xact ConnectionShopSuite 400 - 1152 Mainland St.VancouverBCCanadaV6B 4X2www.e-xact.com========== TRANSACTION RECORD =========
E-xact ConnectionShop
Suite 400 - 1152 Mainland St.
Vancouver, BC V6B 4X2
www.e-xact.com
TYPE: Purchase
ACCT: Visa $1.00 USD
CARD NUMBER : ############4242
TRANS. REF. : 1
CARD HOLDER : Longbob Longsen
EXPIRY DATE : xx/xx
DATE/TIME : 18 Jan 08 14:17:00
REFERENCE # : 5999 377 M
AUTHOR.# : ET1700
Approved - Thank You 00
SIGNATURE
_______________________________________
RESPONSE
end
def failed_purchase_response
<<-RESPONSE
A00427-01#######005013041111111111111111066246680909Longbob Longsen123100001Store Purchase0Processed by:
E-xact Transaction Gateway :- Version 8.4.0 B19b
Copyright 2006
{34:2652}0falsefalse00Transaction Normal13AMOUNT ERR376UME-xact ConnectionShopSuite 400 - 1152 Mainland St.VancouverBCCanadaV6B 4X2www.e-xact.com========== TRANSACTION RECORD =========
E-xact ConnectionShop
Suite 400 - 1152 Mainland St.
Vancouver, BC V6B 4X2
www.e-xact.com
TYPE: Purchase
ACCT: Visa $5,013.00 USD
CARD NUMBER : ############1111
TRANS. REF. : 1
CARD HOLDER : Longbob Longsen
EXPIRY DATE : xx/xx
DATE/TIME : 18 Jan 08 14:11:09
REFERENCE # : 5999 376 M
AUTHOR.# :
Transaction not Approved 13
RESPONSE
end
def soap_fault_response
<<-RESPONSE
soap:Client
Unable to handle request without a valid action parameter. Please supply a valid soap action.
RESPONSE
end
end