require File.dirname(__FILE__) + '/../../test_helper'
class PaymentExpressTest < Test::Unit::TestCase
def setup
@gateway = PaymentExpressGateway.new(
:login => 'LOGIN',
:password => 'PASSWORD'
)
@visa = credit_card
@solo = credit_card("6334900000000005",
:type => "solo",
:issue_number => '01'
)
@options = {
:order_id => generate_unique_id,
:billing_address => address,
:email => 'cody@example.com',
:description => 'Store purchase'
}
@amount = 100
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(@amount, @visa, @options)
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(@amount, @visa, @options)
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(@amount, @solo, @options)
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(@amount, token, @options)
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
def test_avs_result_not_supported
@gateway.expects(:ssl_post).returns(successful_authorization_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_nil response.avs_result['code']
end
def test_cvv_result_not_supported
@gateway.expects(:ssl_post).returns(successful_authorization_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_nil response.cvv_result['code']
end
private
def invalid_credentials_response
'0Invalid Credentials'
end
def successful_authorization_response
<<-RESPONSE
1
Test Transaction
M
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