require File.dirname(__FILE__) + '/../../test_helper'
class PaymentExpressTest < Test::Unit::TestCase
def setup
@gateway = PaymentExpressGateway.new(
:login => 'LOGIN',
:password => 'PASSWORD'
)
@visa = CreditCard.new(
:number => '4242424242424242',
:month => 8,
:year => 2008,
:first_name => 'Longbob',
:last_name => 'Longsen',
:type => 'visa'
)
@solo = CreditCard.new(
:type => "solo",
:number => "6334900000000005",
:month => 11,
:year => 2012,
:first_name => "Test",
:last_name => "Mensch",
:issue_number => '01'
)
@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 test_successful_request
@visa.number = 1
assert response = @gateway.purchase(100, @visa)
assert_success response
assert_equal '5555', response.authorization
assert response.test?
end
def test_unsuccessful_request
@visa.number = 2
assert response = @gateway.purchase(100, @visa)
assert_failure response
assert response.test?
end
def test_request_error
@visa.number = 3
assert_raise(Error){ @gateway.purchase(100, @visa) }
end
def test_default_currency
assert_equal 'NZD', PaymentExpressGateway.default_currency
end
def test_invalid_credentials
@gateway.expects(:ssl_post).returns(invalid_credentials_response)
assert response = @gateway.purchase(100, @visa)
assert_equal 'Invalid Credentials', response.message
assert_failure response
end
def test_successful_authorization
@gateway.expects(:ssl_post).returns(successful_authorization_response)
assert response = @gateway.purchase(100, @visa)
assert_success response
assert response.test?
assert_equal 'APPROVED', response.message
assert_equal '00000004011a2478', response.authorization
end
def test_successful_solo_authorization
@gateway.expects(:ssl_post).returns(successful_authorization_response)
assert response = @gateway.purchase(100, @solo)
assert_success response
assert response.test?
assert_equal 'APPROVED', response.message
assert_equal '00000004011a2478', response.authorization
end
def test_successful_card_store
@gateway.expects(:ssl_post).returns( successful_store_response )
assert response = @gateway.store(@visa)
assert_success response
assert response.test?
assert_equal '0000030000141581', response.token
end
def test_successful_card_store_with_custom_billing_id
@gateway.expects(:ssl_post).returns( successful_store_response(:billing_id => "my-custom-id") )
assert response = @gateway.store(@visa, :billing_id => "my-custom-id")
assert_success response
assert response.test?
assert_equal 'my-custom-id', response.token
end
def test_unsuccessful_card_store
@gateway.expects(:ssl_post).returns( unsuccessful_store_response )
@visa.number = 2
assert response = @gateway.store(@visa)
assert_failure response
end
def test_purchase_using_token
@gateway.expects(:ssl_post).returns( successful_store_response )
assert response = @gateway.store(@visa)
token = response.token
@gateway.expects(:ssl_post).returns( successful_token_purchase_response )
assert response = @gateway.purchase(100, token)
assert_success response
assert_equal 'APPROVED', response.message
assert_equal '0000000303ace8db', response.authorization
end
def test_supported_countries
assert_equal ['AU','MY','NZ','SG','ZA','GB','US'], PaymentExpressGateway.supported_countries
end
def test_supported_card_types
assert_equal [ :visa, :master, :american_express, :diners_club, :jcb ], PaymentExpressGateway.supported_cardtypes
end
private
def invalid_credentials_response
'0Invalid Credentials'
end
def successful_authorization_response
<<-RESPONSE
1
Test Transaction
Visa
0
0
015921
1.23
1
NZD
WestpacTrust
1
NZD
1.00
WestpacTrust
30102000
1
DPS
20050811
Purchase
411111
0807
20050811
060039
9000
Test
1
2
APPROVED
The Transaction was approved
The Transaction was approved
APPROVED
The Transaction was approved
The Transaction was approved
9997
00000004011a2478
0
011a2478
00
APPROVED
The Transaction was approved
1
00000004011a2478
RESPONSE
end
def successful_store_response(options = {})
%(1Visa0002381203accf5c000000030.01554554NZD1.00NZDBOB BOBSEN20070323Auth424242........420809200703230238129000Test12APPROVEDThe Transaction was approvedThe Transaction was approvedAPPROVEDThe Transaction was approvedThe Transaction was approved09999999999-999999991283599970000000303accf5c00000030000141581#{options[:billing_id]}03accf5c0000000300APPROVEDThe Transaction was approved10000000303accf5c)
end
def unsuccessful_store_response(options = {})
%(0000.01554554NZD1.00NZDLONGBOB LONGSEN19800101Validate000000........000808900000INVALID CARD NUMBERAn Invalid Card Number was entered. Check the card numberAn Invalid Card Number was entered. Check the card numberINVALID CARD NUMBERAn Invalid Card Number was entered. Check the card numberAn Invalid Card Number was entered. Check the card number09999999999-999999990999700000000000000003QKINVALID CARD NUMBERAn Invalid Card Number was entered. Check the card number0)
end
def successful_token_purchase_response
%(1Visa0003081710.00554554NZD1.00NZDLONGBOB LONGSEN20070323Purchase424242........420808200703230308179000Test12APPROVEDThe Transaction was approvedThe Transaction was approvedAPPROVEDThe Transaction was approvedThe Transaction was approved09999999999-999999991285999970000000303ace8db0000003000014158103ace8db0000000300APPROVEDThe Transaction was approved10000000303ace8db)
end
end