From 3ce2856a82a0903c427ab8d8f21e40e13e523550 Mon Sep 17 00:00:00 2001 From: codyfauser Date: Fri, 18 Jan 2008 22:27:00 +0000 Subject: [PATCH] Update ExactGateway to support avs and cvv data. Remove test_result_from_cc_number. git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@565 6513ea26-6c20-0410-8a68-89cd7235086d --- CHANGELOG | 1 + lib/active_merchant/billing/gateways/exact.rb | 32 ++-- test/remote/gateways/remote_exact_test.rb | 33 ++-- test/unit/gateways/eway_test.rb | 3 +- test/unit/gateways/exact_test.rb | 143 ++++++++++++------ 5 files changed, 125 insertions(+), 87 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 786aa48a935..ae0b7c73d1f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = ActiveMerchant CHANGELOG +* Update ExactGateway to support avs and cvv data. Remove test_result_from_cc_number. [cody] * 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] diff --git a/lib/active_merchant/billing/gateways/exact.rb b/lib/active_merchant/billing/gateways/exact.rb index 927924eb77e..224fefe8c44 100644 --- a/lib/active_merchant/billing/gateways/exact.rb +++ b/lib/active_merchant/billing/gateways/exact.rb @@ -56,18 +56,10 @@ def test? end def authorize(money, credit_card, options = {}) - if result = test_result_from_cc_number(credit_card.number) - return result - end - commit(:authorization, build_sale_or_authorization_request(money, credit_card, options)) end def purchase(money, credit_card, options = {}) - if result = test_result_from_cc_number(credit_card.number) - return result - end - commit(:sale, build_sale_or_authorization_request(money, credit_card, options)) end @@ -173,23 +165,25 @@ def expdate(credit_card) def commit(action, request) data = ssl_post(URL, build_request(action, request), POST_HEADERS) - + @response = parse(data) - success = @response[:transaction_approved] == SUCCESS - - authorization = if @response[:authorization_num] && @response[:transaction_tag] - "#{response[:authorization_num]};#{response[:transaction_tag]}" - else - '' - end - - Response.new(success, message_from(@response), @response, + Response.new(@response[:transaction_approved] == SUCCESS, message_from(@response), @response, :test => test?, - :authorization => authorization + :authorization => authorization_from(@response), + :avs_result => { :code => @response[:avs] }, + :cvv_result => @response[:cvv2] ) end + def authorization_from(response) + if response[:authorization_num] && response[:transaction_tag] + "#{response[:authorization_num]};#{response[:transaction_tag]}" + else + '' + end + end + def message_from(response) if response[:faultcode] && response[:faultstring] response[:faultstring] diff --git a/test/remote/gateways/remote_exact_test.rb b/test/remote/gateways/remote_exact_test.rb index fba017ac365..e3b3e54d000 100644 --- a/test/remote/gateways/remote_exact_test.rb +++ b/test/remote/gateways/remote_exact_test.rb @@ -1,50 +1,51 @@ require File.dirname(__FILE__) + '/../../test_helper' class RemoteExactTest < Test::Unit::TestCase + def setup - @gateway = ExactGateway.new(fixtures(:exact)) - - @credit_card = credit_card("4111111111111111") - - @options = { :address => { :address1 => "1234 Testing Ave.", - :zip => "55555" } } + @credit_card = credit_card + @amount = 100 + @options = { + :order_id => '1', + :billing_address => address, + :description => 'Store Purchase' + } end def test_successful_purchase - assert response = @gateway.purchase(100, @credit_card, @options) + assert response = @gateway.purchase(@amount, @credit_card, @options) assert_equal "Transaction Normal - VER UNAVAILABLE", response.message assert_success response end def test_unsuccessful_purchase # ask for error 13 response (Amount Error) via dollar amount 5,000 + error - assert response = @gateway.purchase(501300, @credit_card, @options ) + @amount = 501300 + assert response = @gateway.purchase(@amount, @credit_card, @options ) assert_equal "Transaction Normal - AMOUNT ERR", response.message assert_failure response end def test_purchase_and_credit - amount = 100 - assert purchase = @gateway.purchase(amount, @credit_card, @options) + assert purchase = @gateway.purchase(@amount, @credit_card, @options) assert_success purchase assert purchase.authorization - assert credit = @gateway.credit(amount, purchase.authorization) + assert credit = @gateway.credit(@amount, purchase.authorization) assert_success credit end def test_authorize_and_capture - amount = 100 - assert auth = @gateway.authorize(amount, @credit_card, @options) + assert auth = @gateway.authorize(@amount, @credit_card, @options) assert_success auth assert auth.authorization - assert capture = @gateway.capture(amount, auth.authorization) + assert capture = @gateway.capture(@amount, auth.authorization) assert_success capture end def test_failed_capture - assert response = @gateway.capture(100, String.new) + assert response = @gateway.capture(@amount, '') assert_failure response assert_match /Precondition Failed/i, response.message end @@ -52,7 +53,7 @@ def test_failed_capture def test_invalid_login gateway = ExactGateway.new( :login => "NotARealUser", :password => "NotARealPassword" ) - assert response = gateway.purchase(100, @credit_card, @options) + assert response = gateway.purchase(@amount, @credit_card, @options) assert_equal "Invalid Logon", response.message assert_failure response end diff --git a/test/unit/gateways/eway_test.rb b/test/unit/gateways/eway_test.rb index bcb309397e0..d4942f668e8 100644 --- a/test/unit/gateways/eway_test.rb +++ b/test/unit/gateways/eway_test.rb @@ -39,8 +39,7 @@ def test_failed_purchase assert_instance_of Response, response assert_failure response end - - + def test_amount_style assert_equal '1034', @gateway.send(:amount, 1034) diff --git a/test/unit/gateways/exact_test.rb b/test/unit/gateways/exact_test.rb index ecf27c0dfe2..86fafc45d66 100644 --- a/test/unit/gateways/exact_test.rb +++ b/test/unit/gateways/exact_test.rb @@ -5,44 +5,41 @@ def setup @gateway = ExactGateway.new( :login => "A00427-01", :password => "testus" ) - @credit_card = credit_card("4111111111111111") - - @options = { :address => { :address1 => "1234 Testing Ave.", - :zip => "55555" } } + @credit_card = credit_card + @amount = 100 + @options = { + :order_id => '1', + :billing_address => address, + :description => 'Store Purchase' + } end - def test_successful_request - @credit_card.number = "1" - assert response = @gateway.purchase(100, @credit_card, {}) + def test_successful_purchase + @gateway.expects(:ssl_post).returns(successful_purchase_response) + assert response = @gateway.purchase(@amount, @credit_card, @options) assert_success response - assert_equal '5555', response.authorization + assert_equal 'ET1700;106625152', response.authorization assert response.test? + assert_equal 'Transaction Normal - VER UNAVAILABLE', response.message + + ExactGateway::SENSITIVE_FIELDS.each{ |f| assert !response.params.has_key?(f.to_s) } end - - def test_unsuccessful_request - @credit_card.number = "2" - assert response = @gateway.purchase(100, @credit_card, {}) + + 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 - assert response.test? end + def test_expdate assert_equal( "%02d%s" % [ @credit_card.month, @credit_card.year.to_s[-2..-1] ], @gateway.send(:expdate, @credit_card) ) end - - def test_successful_purchase - @gateway.expects(:ssl_post).returns(successful_purchase_response) - assert response = @gateway.purchase(100, @credit_card, {}) - assert_success response - assert_equal 'ET0426;80928103', response.authorization - assert response.test? - assert_equal 'Transaction Normal - VER UNAVAILABLE', response.message - ExactGateway::SENSITIVE_FIELDS.each{ |f| assert !response.params.has_key?(f.to_s) } - end - def test_soap_fault @gateway.expects(:ssl_post).returns(soap_fault_response) assert response = @gateway.purchase(100, @credit_card, {}) @@ -59,42 +56,88 @@ def test_supported_card_types assert_equal [:visa, :master, :american_express, :jcb, :discover], ExactGateway.supported_cardtypes end + def test_avs_result + @gateway.expects(:ssl_post).returns(successful_purchase_response) + + response = @gateway.purchase(@amount, @credit_card) + assert_equal 'U', response.avs_result['code'] + end + + def test_cvv_result + @gateway.expects(:ssl_post).returns(successful_purchase_response) + + response = @gateway.purchase(@amount, @credit_card) + assert_equal 'M', response.cvv_result['code'] + end + + private def successful_purchase_response <<-RESPONSE -A00427-01#######0010411111111111111112380928103ET04260909Active Merchant05555500000Processed by: -E-xact Transaction Gateway :- Version 8.4.0 B19 -Copyright 2006 -{34:2652}0falsetrue00Transaction Normal00VER UNAVAILABLE 431U200703280426E-xact ConnectionShopSuite 304 - 134 Abbott StreetVancouverBCCanadaV6B 2K4www.e-xact.com========== TRANSACTION RECORD ========= - -E-xact ConnectionShop -Suite 304 - 134 Abbott Street -Vancouver, BC V6B 2K4 -www.e-xact.com - -TYPE: Purchase - -ACCT: Visa $1.00 USD - -CARD NUMBER : ############1111 -TRANS. REF. : -CARD HOLDER : Active Merchant -EXPIRY DATE : xx/xx -DATE/TIME : 28 Mar 07 12:04:26 -REFERENCE # : 5999 431 M -AUTHOR.# : ET0426 - - Approved - Thank You 00 - -SIGNATURE +A00427-01#######00104242424242424242106625152ET17000909Longbob Longsen123100001Store Purchase0Processed by: +E-xact Transaction Gateway :- Version 8.4.0 B19b +Copyright 2006 +{34:2652}0falsetrue00Transaction Normal00VER UNAVAILABLE 377UM200801181700E-xact ConnectionShopSuite 400 - 1152 Mainland St.VancouverBCCanadaV6B 4X2www.e-xact.com========== TRANSACTION RECORD ========= + +E-xact ConnectionShop +Suite 400 - 1152 Mainland St. +Vancouver, BC V6B 4X2 +www.e-xact.com + +TYPE: Purchase + +ACCT: Visa $1.00 USD + +CARD NUMBER : ############4242 +TRANS. REF. : 1 +CARD HOLDER : Longbob Longsen +EXPIRY DATE : xx/xx +DATE/TIME : 18 Jan 08 14:17:00 +REFERENCE # : 5999 377 M +AUTHOR.# : ET1700 + + Approved - Thank You 00 + +SIGNATURE -_______________________________________ +_______________________________________ RESPONSE end + + def failed_purchase_response + <<-RESPONSE +A00427-01#######005013041111111111111111066246680909Longbob Longsen123100001Store Purchase0Processed by: +E-xact Transaction Gateway :- Version 8.4.0 B19b +Copyright 2006 +{34:2652}0falsefalse00Transaction Normal13AMOUNT ERR376UME-xact ConnectionShopSuite 400 - 1152 Mainland St.VancouverBCCanadaV6B 4X2www.e-xact.com========== TRANSACTION RECORD ========= + +E-xact ConnectionShop +Suite 400 - 1152 Mainland St. +Vancouver, BC V6B 4X2 +www.e-xact.com + +TYPE: Purchase + +ACCT: Visa $5,013.00 USD + +CARD NUMBER : ############1111 +TRANS. REF. : 1 +CARD HOLDER : Longbob Longsen +EXPIRY DATE : xx/xx +DATE/TIME : 18 Jan 08 14:11:09 +REFERENCE # : 5999 376 M +AUTHOR.# : + + Transaction not Approved 13 + + + + RESPONSE + end def soap_fault_response <<-RESPONSE