require File.dirname(__FILE__) + '/../../test_helper'
require 'digest/sha1'
class RealexTest < Test::Unit::TestCase
AMOUNT = 100
def setup
@login = 'your_merchant_id'
@password = 'your_secret'
@gateway = RealexGateway.new(
:login => @merchant_id,
:password => @secret,
:account => ''
)
@gateway_with_account = RealexGateway.new(
:login => @merchant_id,
:password => @secret,
:account => 'bill_web_cengal'
)
@creditcard = CreditCard.new(
:number => '4263971921001307',
:month => 8,
:year => 2008,
:first_name => 'Longbob',
:last_name => 'Longsen',
:type => 'visa'
)
end
def test_in_test
assert_equal :test, ActiveMerchant::Billing::Base.gateway_mode
end
def test_hash
result = Digest::SHA1.hexdigest("20061213105925.your_merchant_id.1.400.EUR.4263971921001307")
assert_equal "6bbce4d13f8e830401db4ee530eecb060bc50f64", result
#add the secret to the end
result = Digest::SHA1.hexdigest(result + "." + @password)
assert_equal "06a8b619cbd76024676401e5a83e7e5453521af3", result
end
def test_successful_request
@creditcard.number = 1
assert response = @gateway.purchase(AMOUNT, @creditcard, :order_id => 1)
assert_success response
assert_equal '5555', response.authorization
assert response.test?
end
def test_unsuccessful_request
@creditcard.number = 2
assert response = @gateway.purchase(AMOUNT, @creditcard, :order_id => 1)
assert_failure response
assert response.test?
end
def test_request_error
@creditcard.number = 3
assert_raise(Error){ @gateway.purchase(AMOUNT, @creditcard, :order_id => 1) }
end
def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_response)
response = @gateway.purchase(AMOUNT, @creditcard, :order_id => 1)
assert_success response
end
def test_unsuccessful_purchase
@gateway.expects(:ssl_post).returns(unsuccessful_response)
response = @gateway.purchase(AMOUNT, @creditcard, :order_id => 1)
assert_failure response
end
def test_supported_countries
assert_equal ['IE', 'GB'], RealexGateway.supported_countries
end
def test_supported_card_types
assert_equal [ :visa, :master, :american_express, :diners_club, :switch, :solo, :laser ], RealexGateway.supported_cardtypes
end
private
def successful_response
<<-RESPONSE
your merchant id
account to use
order id from request
authcode received
00
[ test system ] message returned from system
realex payments reference
M
batch id for this transaction (if any)
Issuing Bank Name
Issuing Bank Country
Issuing Bank Country Code
Issuing Bank Region
89
9
9
7384ae67....ac7d7d
34e7....a77d
"
RESPONSE
end
def unsuccessful_response
<<-RESPONSE
your merchant id
account to use
order id from request
authcode received
01
message returned from system
realex payments reference
M
batch id for this transaction (if any)
Issuing Bank Name
Issuing Bank Country
Issuing Bank Country Code
Issuing Bank Region
89
9
9
7384ae67....ac7d7d
34e7....a77d
"
RESPONSE
end
end