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("4111111111111111")
@options = { :address => { :address1 => "1234 Testing Ave.",
:zip => "55555" } }
end
def test_successful_request
@credit_card.number = "1"
assert response = @gateway.purchase(100, @credit_card, {})
assert_success response
assert_equal '5555', response.authorization
assert response.test?
end
def test_unsuccessful_request
@credit_card.number = "2"
assert response = @gateway.purchase(100, @credit_card, {})
assert_failure response
assert response.test?
end
def test_request_error
@credit_card.number = "3"
assert_raise(Error){ @gateway.purchase(100, @credit_card, {}) }
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_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)
assert response = @gateway.purchase(100, @credit_card, {})
assert_success response
assert_equal 'ET0426;80928103', 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_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
private
def successful_purchase_response
<<-RESPONSE
A00427-01#######0010411111111111111112380928103ET04260909Active Merchant05555500000Processed by:
E-xact Transaction Gateway :- Version 8.4.0 B19
Copyright 2006
{34:2652}0falsetrue00Transaction Normal00VER UNAVAILABLE 431U200703280426E-xact ConnectionShopSuite 304 - 134 Abbott StreetVancouverBCCanadaV6B 2K4www.e-xact.com========== TRANSACTION RECORD =========
E-xact ConnectionShop
Suite 304 - 134 Abbott Street
Vancouver, BC V6B 2K4
www.e-xact.com
TYPE: Purchase
ACCT: Visa $1.00 USD
CARD NUMBER : ############1111
TRANS. REF. :
CARD HOLDER : Active Merchant
EXPIRY DATE : xx/xx
DATE/TIME : 28 Mar 07 12:04:26
REFERENCE # : 5999 431 M
AUTHOR.# : ET0426
Approved - Thank You 00
SIGNATURE
_______________________________________
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