require File.dirname(__FILE__) + '/../../test_helper'
require 'digest/sha1'
class RealexTest < Test::Unit::TestCase
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'
)
@credit_card = CreditCard.new(
:number => '4263971921001307',
:month => 8,
:year => 2008,
:first_name => 'Longbob',
:last_name => 'Longsen',
:type => 'visa'
)
@options = {
:order_id => '1'
}
@amount = 100
end
def test_in_test
assert_equal :test, MerbMerchant::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_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_success response
assert response.test?
end
def test_unsuccessful_purchase
@gateway.expects(:ssl_post).returns(unsuccessful_purchase_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_failure response
assert response.test?
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
def test_avs_result_not_supported
@gateway.expects(:ssl_post).returns(successful_purchase_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_nil response.avs_result['code']
end
def test_cvv_result
@gateway.expects(:ssl_post).returns(successful_purchase_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'M', response.cvv_result['code']
end
private
def successful_purchase_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_purchase_response
<<-RESPONSE
your merchant id
account to use
order id from request
authcode received
01
[ 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
end