Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Remove test_result_from_cc_number from eWay gateway.
Browse files Browse the repository at this point in the history
git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@564 6513ea26-6c20-0410-8a68-89cd7235086d
  • Loading branch information
codyfauser committed Jan 18, 2008
1 parent a1195fa commit 5cccfca
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,5 +1,6 @@
= ActiveMerchant CHANGELOG

* Remove test_result_from_cc_number from eWay gateway. [cody]
* Remove duplicate attr_reader definitions from all gateways [cody]
* Remove useless tests raising Error [cody]
* Update gateway templates [cody]
Expand Down
10 changes: 2 additions & 8 deletions lib/active_merchant/billing/gateways/eway.rb
Expand Up @@ -191,16 +191,10 @@ def add_optional_data(post)
post[:Option3] = nil
end

def commit(money, parameters)

def commit(money, parameters)
parameters[:TotalAmount] = amount(money)

if result = test_result_from_cc_number(parameters[:CardNumber])
return result
end

data = ssl_post gateway_url(parameters[:CVN], test?), post_data(parameters)

@response = parse(data)

success = (response[:ewaytrxnstatus] == "True")
Expand Down
31 changes: 17 additions & 14 deletions test/remote/gateways/remote_eway_test.rb
Expand Up @@ -5,65 +5,68 @@ def setup
Base.gateway_mode = :test
@gateway = EwayGateway.new(fixtures(:eway))

@creditcard_success = credit_card('4444333322221111')
@credit_card_success = credit_card('4444333322221111')

@creditcard_fail = credit_card('1234567812345678',
@credit_card_fail = credit_card('1234567812345678',
:month => Time.now.month,
:year => Time.now.year
)

@params = {
:order_id => '1230123',
:email => 'bob@testbob.com',
:address => { :address1 => '47 Bobway, Bobville, WA, Australia',
:zip => '2000'
} ,
:billing_address => { :address1 => '47 Bobway',
:city => 'Bobville',
:state => 'WA',
:country => 'AU',
:zip => '2000'
} ,
:description => 'purchased items'
}
end

def test_invalid_amount
assert response = @gateway.purchase(101, @creditcard_success, @params)
assert response = @gateway.purchase(101, @credit_card_success, @params)
assert_failure response
assert response.test?
assert_equal EwayGateway::MESSAGES["01"], response.message
end

def test_purchase_success_with_verification_value
assert response = @gateway.purchase(100, @creditcard_success, @params)
assert response = @gateway.purchase(100, @credit_card_success, @params)
assert_equal '123456', response.authorization
assert_success response
assert response.test?
assert_equal EwayGateway::MESSAGES["00"], response.message
end

def test_invalid_expiration_date
@creditcard_success.year = 2005
assert response = @gateway.purchase(100, @creditcard_success, @params)
@credit_card_success.year = 2005
assert response = @gateway.purchase(100, @credit_card_success, @params)
assert_failure response
assert response.test?
end

def test_purchase_with_invalid_verification_value
@creditcard_success.verification_value = 'AAA'
assert response = @gateway.purchase(100, @creditcard_success, @params)
@credit_card_success.verification_value = 'AAA'
assert response = @gateway.purchase(100, @credit_card_success, @params)
assert_nil response.authorization
assert_failure response
assert response.test?
end

def test_purchase_success_without_verification_value
@creditcard_success.verification_value = nil
@credit_card_success.verification_value = nil

assert response = @gateway.purchase(100, @creditcard_success, @params)
assert response = @gateway.purchase(100, @credit_card_success, @params)
assert_equal '123456', response.authorization
assert_success response
assert response.test?
assert_equal EwayGateway::MESSAGES["00"], response.message
end

def test_purchase_error
assert response = @gateway.purchase(100, @creditcard_fail, @params)
assert response = @gateway.purchase(100, @credit_card_fail, @params)
assert_nil response.authorization
assert_equal false, response.success?
assert response.test?
Expand Down
88 changes: 55 additions & 33 deletions test/unit/gateways/eway_test.rb
Expand Up @@ -6,9 +6,9 @@ def setup
:login => '87654321'
)

@creditcard = credit_card('4646464646464646')
@credit_card = credit_card('4646464646464646')

@test_params_success = {
@options = {
:order_id => '1230123',
:email => 'bob@testbob.com',
:address => {
Expand All @@ -20,28 +20,26 @@ def setup
:zip => '12345'
},
:description => 'purchased items'
}

@xml_test_parameters = {
:CustomerID => @test_params_success[:login],
:CustomerInvoiceRef => @test_params_success[:order_id],
:TotalAmount => 100,
:CardNumber => @creditcard.number,
:CardExpiryMonth => sprintf("%.2i", @creditcard.month),
:CardExpiryYear => sprintf("%.4i", @creditcard.year)[-2..-1],
:CustomerFirstName => @creditcard.first_name,
:CustomerLastName => @creditcard.last_name,
:CustomerEmail => @test_params_success[:email],
:CustomerAddress => @test_params_success[:address][:address1],
:CustomerPostcode => @test_params_success[:address][:zip],
:CustomerInvoiceDescription => @test_params_success[:description],
:CardHoldersName => @creditcard.name,
:TrxnNumber => @test_params_success[:order_id],
:Option1 => '',
:Option2 => '',
:Option3 => ''
}
}
end

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 '123456', response.authorization
end

def test_failed_purchase
@gateway.expects(:ssl_post).returns(failed_purchase_response)

assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_failure response
end


def test_amount_style
assert_equal '1034', @gateway.send(:amount, 1034)
Expand All @@ -51,11 +49,6 @@ def test_amount_style
end
end

def test_purchase_is_valid_xml
assert data = @gateway.send(:post_data, @xml_test_parameters)
assert REXML::Document.new(data)
end

def test_ensure_does_not_respond_to_authorize
assert !@gateway.respond_to?(:authorize)
end
Expand All @@ -82,15 +75,44 @@ def test_live_url_with_cvn

def test_add_address
post = {}
@gateway.send(:add_address, post, @test_params_success)
@gateway.send(:add_address, post, @options)
assert_equal '1234 First St., Apt. 1, Melbourne, ACT, AU', post[:CustomerAddress]
assert_equal @test_params_success[:address][:zip], post[:CustomerPostcode]
assert_equal @options[:address][:zip], post[:CustomerPostcode]
end

private

def xml_purchase_fixture
%q{<ewaygateway><ewayCustomerID>87654321</ewayCustomerID><ewayOption3></ewayOption3><ewayCustomerFirstName>Longbob</ewayCustomerFirstName><ewayCustomerAddress>47 Bobway, Bobville, WA, Australia</ewayCustomerAddress><ewayCustomerInvoiceRef>1230123</ewayCustomerInvoiceRef><ewayCardHoldersName>Longbob Longsen</ewayCardHoldersName><ewayTotalAmount>100</ewayTotalAmount><ewayTrxnNumber>1230123</ewayTrxnNumber><ewayCustomerLastName>Longsen</ewayCustomerLastName><ewayCustomerPostcode>2000</ewayCustomerPostcode><ewayCardNumber>4646464646464646</ewayCardNumber><ewayOption1></ewayOption1><ewayCardExpiryMonth>08</ewayCardExpiryMonth><ewayOption2></ewayOption2><ewayCustomerEmail>bob@testbob.com</ewayCustomerEmail><ewayCustomerInvoiceDescription>purchased items</ewayCustomerInvoiceDescription><ewayCardExpiryYear>07</ewayCardExpiryYear></ewaygateway>}
def successful_purchase_response
<<-XML
<?xml version="1.0"?>
<ewayResponse>
<ewayTrxnStatus>True</ewayTrxnStatus>
<ewayTrxnNumber>11292</ewayTrxnNumber>
<ewayTrxnReference/>
<ewayTrxnOption1/>
<ewayTrxnOption2/>
<ewayTrxnOption3/>
<ewayAuthCode>123456</ewayAuthCode>
<ewayReturnAmount>100</ewayReturnAmount>
<ewayTrxnError>00,Transaction Approved(Test CVN Gateway)</ewayTrxnError>
</ewayResponse>
XML
end

def failed_purchase_response
<<-XML
<?xml version="1.0"?>
<ewayResponse>
<ewayTrxnStatus>False</ewayTrxnStatus>
<ewayTrxnNumber>11290</ewayTrxnNumber>
<ewayTrxnReference/>
<ewayTrxnOption1/>
<ewayTrxnOption2/>
<ewayTrxnOption3/>
<ewayAuthCode/>
<ewayReturnAmount>100</ewayReturnAmount>
<ewayTrxnError>eWAY Error: Invalid Expiry Date. Your credit card has not been billed for this transaction.(Test CVN Gateway)</ewayTrxnError>
</ewayResponse>
XML
end
end

Expand Down

0 comments on commit 5cccfca

Please sign in to comment.