Skip to content

Commit

Permalink
Update ExactGateway to support avs and cvv data. Remove test_result_f…
Browse files Browse the repository at this point in the history
…rom_cc_number.

git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@565 6513ea26-6c20-0410-8a68-89cd7235086d
  • Loading branch information
codyfauser committed Jan 18, 2008
1 parent 5cccfca commit 3ce2856
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 87 deletions.
1 change: 1 addition & 0 deletions 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]
Expand Down
32 changes: 13 additions & 19 deletions lib/active_merchant/billing/gateways/exact.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
33 changes: 17 additions & 16 deletions test/remote/gateways/remote_exact_test.rb
@@ -1,58 +1,59 @@
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

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
Expand Down
3 changes: 1 addition & 2 deletions test/unit/gateways/eway_test.rb
Expand Up @@ -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)

Expand Down
143 changes: 93 additions & 50 deletions test/unit/gateways/exact_test.rb
Expand Up @@ -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, {})
Expand All @@ -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
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/" xmlns:types="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><q1:SendAndCommitResponse xmlns:q1="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/Response"><SendAndCommitResult href="#id1" /></q1:SendAndCommitResponse><types:TransactionResult id="id1" xsi:type="types:TransactionResult"><ExactID xsi:type="xsd:string">A00427-01</ExactID><Password xsi:type="xsd:string">#######</Password><Transaction_Type xsi:type="xsd:string">00</Transaction_Type><DollarAmount xsi:type="xsd:string">1</DollarAmount><SurchargeAmount xsi:type="xsd:string">0</SurchargeAmount><Card_Number xsi:type="xsd:string">4111111111111111</Card_Number><Verification_Str2 xsi:type="xsd:string">123</Verification_Str2><Transaction_Tag xsi:type="xsd:string">80928103</Transaction_Tag><Authorization_Num xsi:type="xsd:string">ET0426</Authorization_Num><Expiry_Date xsi:type="xsd:string">0909</Expiry_Date><CardHoldersName xsi:type="xsd:string">Active Merchant</CardHoldersName><CVD_Presence_Ind xsi:type="xsd:string">0</CVD_Presence_Ind><ZipCode xsi:type="xsd:string">55555</ZipCode><Secure_AuthRequired xsi:type="xsd:string">0</Secure_AuthRequired><Secure_AuthResult xsi:type="xsd:string">0</Secure_AuthResult><Ecommerce_Flag xsi:type="xsd:string">0</Ecommerce_Flag><CAVV_Algorithm xsi:type="xsd:string">0</CAVV_Algorithm><Language xsi:type="xsd:string">0</Language><LogonMessage xsi:type="xsd:string">Processed by:
E-xact Transaction Gateway :- Version 8.4.0 B19
Copyright 2006
{34:2652}</LogonMessage><Error_Number xsi:type="xsd:string">0</Error_Number><Error_Description xsi:type="xsd:string" /><Transaction_Error xsi:type="xsd:boolean">false</Transaction_Error><Transaction_Approved xsi:type="xsd:boolean">true</Transaction_Approved><EXact_Resp_Code xsi:type="xsd:string">00</EXact_Resp_Code><EXact_Message xsi:type="xsd:string">Transaction Normal</EXact_Message><Bank_Resp_Code xsi:type="xsd:string">00</Bank_Resp_Code><Bank_Message xsi:type="xsd:string">VER UNAVAILABLE </Bank_Message><SequenceNo xsi:type="xsd:string">431</SequenceNo><AVS xsi:type="xsd:string">U</AVS><Retrieval_Ref_No xsi:type="xsd:string">200703280426</Retrieval_Ref_No><MerchantName xsi:type="xsd:string">E-xact ConnectionShop</MerchantName><MerchantAddress xsi:type="xsd:string">Suite 304 - 134 Abbott Street</MerchantAddress><MerchantCity xsi:type="xsd:string">Vancouver</MerchantCity><MerchantProvince xsi:type="xsd:string">BC</MerchantProvince><MerchantCountry xsi:type="xsd:string">Canada</MerchantCountry><MerchantPostal xsi:type="xsd:string">V6B 2K4</MerchantPostal><MerchantURL xsi:type="xsd:string">www.e-xact.com</MerchantURL><CTR xsi:type="xsd:string">========== 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
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/" xmlns:types="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><q1:SendAndCommitResponse xmlns:q1="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/Response"><SendAndCommitResult href="#id1" /></q1:SendAndCommitResponse><types:TransactionResult id="id1" xsi:type="types:TransactionResult"><ExactID xsi:type="xsd:string">A00427-01</ExactID><Password xsi:type="xsd:string">#######</Password><Transaction_Type xsi:type="xsd:string">00</Transaction_Type><DollarAmount xsi:type="xsd:string">1</DollarAmount><SurchargeAmount xsi:type="xsd:string">0</SurchargeAmount><Card_Number xsi:type="xsd:string">4242424242424242</Card_Number><Transaction_Tag xsi:type="xsd:string">106625152</Transaction_Tag><Authorization_Num xsi:type="xsd:string">ET1700</Authorization_Num><Expiry_Date xsi:type="xsd:string">0909</Expiry_Date><CardHoldersName xsi:type="xsd:string">Longbob Longsen</CardHoldersName><VerificationStr2 xsi:type="xsd:string">123</VerificationStr2><CVD_Presence_Ind xsi:type="xsd:string">1</CVD_Presence_Ind><Secure_AuthRequired xsi:type="xsd:string">0</Secure_AuthRequired><Secure_AuthResult xsi:type="xsd:string">0</Secure_AuthResult><Ecommerce_Flag xsi:type="xsd:string">0</Ecommerce_Flag><CAVV_Algorithm xsi:type="xsd:string">0</CAVV_Algorithm><Reference_No xsi:type="xsd:string">1</Reference_No><Reference_3 xsi:type="xsd:string">Store Purchase</Reference_3><Language xsi:type="xsd:string">0</Language><LogonMessage xsi:type="xsd:string">Processed by:
E-xact Transaction Gateway :- Version 8.4.0 B19b
Copyright 2006
{34:2652}</LogonMessage><Error_Number xsi:type="xsd:string">0</Error_Number><Error_Description xsi:type="xsd:string" /><Transaction_Error xsi:type="xsd:boolean">false</Transaction_Error><Transaction_Approved xsi:type="xsd:boolean">true</Transaction_Approved><EXact_Resp_Code xsi:type="xsd:string">00</EXact_Resp_Code><EXact_Message xsi:type="xsd:string">Transaction Normal</EXact_Message><Bank_Resp_Code xsi:type="xsd:string">00</Bank_Resp_Code><Bank_Message xsi:type="xsd:string">VER UNAVAILABLE </Bank_Message><SequenceNo xsi:type="xsd:string">377</SequenceNo><AVS xsi:type="xsd:string">U</AVS><CVV2 xsi:type="xsd:string">M</CVV2><Retrieval_Ref_No xsi:type="xsd:string">200801181700</Retrieval_Ref_No><MerchantName xsi:type="xsd:string">E-xact ConnectionShop</MerchantName><MerchantAddress xsi:type="xsd:string">Suite 400 - 1152 Mainland St.</MerchantAddress><MerchantCity xsi:type="xsd:string">Vancouver</MerchantCity><MerchantProvince xsi:type="xsd:string">BC</MerchantProvince><MerchantCountry xsi:type="xsd:string">Canada</MerchantCountry><MerchantPostal xsi:type="xsd:string">V6B 4X2</MerchantPostal><MerchantURL xsi:type="xsd:string">www.e-xact.com</MerchantURL><CTR xsi:type="xsd:string">========== 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
_______________________________________
_______________________________________
</CTR></types:TransactionResult></soap:Body></soap:Envelope>
RESPONSE
end

def failed_purchase_response
<<-RESPONSE
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/" xmlns:types="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><q1:SendAndCommitResponse xmlns:q1="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/Response"><SendAndCommitResult href="#id1" /></q1:SendAndCommitResponse><types:TransactionResult id="id1" xsi:type="types:TransactionResult"><ExactID xsi:type="xsd:string">A00427-01</ExactID><Password xsi:type="xsd:string">#######</Password><Transaction_Type xsi:type="xsd:string">00</Transaction_Type><DollarAmount xsi:type="xsd:string">5013</DollarAmount><SurchargeAmount xsi:type="xsd:string">0</SurchargeAmount><Card_Number xsi:type="xsd:string">4111111111111111</Card_Number><Transaction_Tag xsi:type="xsd:string">106624668</Transaction_Tag><Expiry_Date xsi:type="xsd:string">0909</Expiry_Date><CardHoldersName xsi:type="xsd:string">Longbob Longsen</CardHoldersName><VerificationStr2 xsi:type="xsd:string">123</VerificationStr2><CVD_Presence_Ind xsi:type="xsd:string">1</CVD_Presence_Ind><Secure_AuthRequired xsi:type="xsd:string">0</Secure_AuthRequired><Secure_AuthResult xsi:type="xsd:string">0</Secure_AuthResult><Ecommerce_Flag xsi:type="xsd:string">0</Ecommerce_Flag><CAVV_Algorithm xsi:type="xsd:string">0</CAVV_Algorithm><Reference_No xsi:type="xsd:string">1</Reference_No><Reference_3 xsi:type="xsd:string">Store Purchase</Reference_3><Language xsi:type="xsd:string">0</Language><LogonMessage xsi:type="xsd:string">Processed by:
E-xact Transaction Gateway :- Version 8.4.0 B19b
Copyright 2006
{34:2652}</LogonMessage><Error_Number xsi:type="xsd:string">0</Error_Number><Error_Description xsi:type="xsd:string" /><Transaction_Error xsi:type="xsd:boolean">false</Transaction_Error><Transaction_Approved xsi:type="xsd:boolean">false</Transaction_Approved><EXact_Resp_Code xsi:type="xsd:string">00</EXact_Resp_Code><EXact_Message xsi:type="xsd:string">Transaction Normal</EXact_Message><Bank_Resp_Code xsi:type="xsd:string">13</Bank_Resp_Code><Bank_Message xsi:type="xsd:string">AMOUNT ERR</Bank_Message><SequenceNo xsi:type="xsd:string">376</SequenceNo><AVS xsi:type="xsd:string">U</AVS><CVV2 xsi:type="xsd:string">M</CVV2><MerchantName xsi:type="xsd:string">E-xact ConnectionShop</MerchantName><MerchantAddress xsi:type="xsd:string">Suite 400 - 1152 Mainland St.</MerchantAddress><MerchantCity xsi:type="xsd:string">Vancouver</MerchantCity><MerchantProvince xsi:type="xsd:string">BC</MerchantProvince><MerchantCountry xsi:type="xsd:string">Canada</MerchantCountry><MerchantPostal xsi:type="xsd:string">V6B 4X2</MerchantPostal><MerchantURL xsi:type="xsd:string">www.e-xact.com</MerchantURL><CTR xsi:type="xsd:string">========== 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
</CTR></types:TransactionResult></soap:Body></soap:Envelope>
RESPONSE
end

def soap_fault_response
<<-RESPONSE
Expand Down

0 comments on commit 3ce2856

Please sign in to comment.