test/unit/gateways/efsnet_test.rb in activemerchant-1.2.1 vs test/unit/gateways/efsnet_test.rb in activemerchant-1.3.0
- old
+ new
@@ -1,70 +1,123 @@
require File.dirname(__FILE__) + '/../../test_helper'
class EfsnetTest < Test::Unit::TestCase
- AMOUNT = 100
def setup
@gateway = EfsnetGateway.new(
:login => 'LOGIN',
:password => 'PASSWORD'
)
- @creditcard = credit_card('4242424242424242')
-
- @address = { :address1 => '1234 My Street',
- :address2 => 'Apt 1',
- :company => 'Widgets Inc',
- :city => 'Ottawa',
- :state => 'ON',
- :zip => 'K1C2N6',
- :country => 'Canada',
- :phone => '(555)555-5555'
- }
- @options = {:order_id => 1}
+ @credit_card = credit_card('4242424242424242')
+ @amount = 100
+ @options = { :order_id => 1, :billing_address => address }
end
- def test_successful_request
- @creditcard.number = 1
- assert response = @gateway.purchase(AMOUNT, @creditcard, @options)
+ def test_successful_purchase
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
+
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
+ assert_instance_of Response, response
assert_success response
- assert_equal '5555', response.authorization
assert response.test?
+ assert_equal '100018347764;1.00', response.authorization
+ assert_equal 'Approved', response.message
+
end
- def test_unsuccessful_request
- @creditcard.number = 2
- assert response = @gateway.purchase(AMOUNT, @creditcard, @options)
+ def test_unsuccessful_purchase
+ @gateway.expects(:ssl_post).returns(unsuccessful_purchase_response)
+
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
+ assert_instance_of Response, response
assert_failure response
assert response.test?
+ assert_equal 'Declined', response.message
end
- def test_request_error
- @creditcard.number = 3
- assert_raise(Error){ @gateway.purchase(AMOUNT, @creditcard, @options) }
- end
-
def test_authorize_is_valid_xml
- params = {
- :order_id => "order1",
- :transaction_amount => "1.01",
- :account_number => "4242424242424242",
- :expiration_month => "12",
- :expiration_year => "2029",
- }
-
- assert data = @gateway.send(:post_data, :credit_card_authorize, params)
- assert REXML::Document.new(data)
+ params = {
+ :order_id => "order1",
+ :transaction_amount => "1.01",
+ :account_number => "4242424242424242",
+ :expiration_month => "12",
+ :expiration_year => "2029",
+ }
+
+ assert data = @gateway.send(:post_data, :credit_card_authorize, params)
+ assert REXML::Document.new(data)
end
def test_settle_is_valid_xml
- params = {
- :order_id => "order1",
- :transaction_amount => "1.01",
- :original_transaction_amount => "1.01",
- :original_transaction_id => "1",
- }
-
- assert data = @gateway.send(:post_data, :credit_card_settle, params)
- assert REXML::Document.new(data)
+ params = {
+ :order_id => "order1",
+ :transaction_amount => "1.01",
+ :original_transaction_amount => "1.01",
+ :original_transaction_id => "1",
+ }
+
+ assert data = @gateway.send(:post_data, :credit_card_settle, params)
+ assert REXML::Document.new(data)
+ end
+
+ def test_avs_result
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
+
+ response = @gateway.purchase(@amount, @credit_card, @options)
+ assert_equal 'N', 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
+ <<-XML
+<?xml version="1.0"?>
+<Reply>
+ <TransactionReply>
+ <ResponseCode>0</ResponseCode>
+ <ResultCode>00</ResultCode>
+ <ResultMessage>APPROVED</ResultMessage>
+ <TransactionID>100018347764</TransactionID>
+ <AVSResponseCode>N</AVSResponseCode>
+ <CVVResponseCode>M</CVVResponseCode>
+ <ApprovalNumber>123456</ApprovalNumber>
+ <AuthorizationNumber>123456</AuthorizationNumber>
+ <TransactionDate>080117</TransactionDate>
+ <TransactionTime>163222</TransactionTime>
+ <ReferenceNumber>1</ReferenceNumber>
+ <AccountNumber>XXXXXXXXXXXX2224</AccountNumber>
+ <TransactionAmount>1.00</TransactionAmount>
+ </TransactionReply>
+</Reply>
+ XML
+ end
+
+ def unsuccessful_purchase_response
+ <<-XML
+<?xml version="1.0"?>
+<Reply>
+ <TransactionReply>
+ <ResponseCode>256</ResponseCode>
+ <ResultCode>04</ResultCode>
+ <ResultMessage>DECLINED</ResultMessage>
+ <TransactionID>100018347784</TransactionID>
+ <AVSResponseCode>N</AVSResponseCode>
+ <CVVResponseCode/>
+ <ApprovalNumber/>
+ <AuthorizationNumber/>
+ <TransactionDate>080117</TransactionDate>
+ <TransactionTime>163946</TransactionTime>
+ <ReferenceNumber>1</ReferenceNumber>
+ <AccountNumber>XXXXXXXXXXXX2224</AccountNumber>
+ <TransactionAmount>1.56</TransactionAmount>
+ </TransactionReply>
+</Reply>
+ XML
end
end