From 035a24bff9a24f37174746fda6e8e81351d1b48a Mon Sep 17 00:00:00 2001 From: codyfauser Date: Thu, 15 May 2008 20:27:36 +0000 Subject: [PATCH] Detect test mode with Beanstream git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@669 6513ea26-6c20-0410-8a68-89cd7235086d --- CHANGELOG | 1 + .../billing/gateways/beanstream.rb | 3 ++- test/unit/gateways/beanstream_test.rb | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b7991a96546..311101f669f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = ActiveMerchant CHANGELOG +* Add test mode detection to Beanstream [cody] * Add support for Beanstream payment gateway [xiaobozz] * Add support for PayPal NV Pair API. Will be used to replace the usage of the PayPal SOAP API in ActiveMerchant in the future [Greg Furmanek, cody] * Protx does support UK Maestro [cody] diff --git a/lib/active_merchant/billing/gateways/beanstream.rb b/lib/active_merchant/billing/gateways/beanstream.rb index 3ece98dc3fd..3d415133a5a 100644 --- a/lib/active_merchant/billing/gateways/beanstream.rb +++ b/lib/active_merchant/billing/gateways/beanstream.rb @@ -209,7 +209,8 @@ def parse(body) def commit(action, money, parameters) response = parse(ssl_post(URL, post_data(action, parameters))) - Response.new(success?(response), message_from(response), response, + Response.new(success?(response), message_from(response), response, + :test => test? || response[:authCode] == "TEST", :authorization => response[:trnId], :cvv_result => CVD_CODES[response[:cvdId]], :avs_result => { :code => (AVS_CODES.include? response[:avsId]) ? AVS_CODES[response[:avsId]] : response[:avsId] } diff --git a/test/unit/gateways/beanstream_test.rb b/test/unit/gateways/beanstream_test.rb index 28046f6a685..e717613e9b5 100644 --- a/test/unit/gateways/beanstream_test.rb +++ b/test/unit/gateways/beanstream_test.rb @@ -2,6 +2,8 @@ class BeanstreamTest < Test::Unit::TestCase def setup + Base.mode = :test + @gateway = BeanstreamGateway.new( :login => 'merchant id', :user => 'username', @@ -40,6 +42,24 @@ def test_successful_request assert_success response assert_equal '11011067', response.authorization end + + def test_successful_test_request_in_test_environment + @gateway.expects(:ssl_post).returns(successful_purchase_response) + + assert response = @gateway.purchase(@amount, @credit_card, @options) + assert_success response + assert_equal '11011067', response.authorization + assert response.test? + end + + def test_successful_test_request_in_production_environment + Base.mode = :production + @gateway.expects(:ssl_post).returns(successful_test_purchase_response) + + assert response = @gateway.purchase(@amount, @credit_card, @options) + assert_success response + assert response.test? + end def test_unsuccessful_request @gateway.expects(:ssl_post).returns(unsuccessful_purchase_response) @@ -68,6 +88,10 @@ def successful_purchase_response "merchant_id=100200000&trnId=11011067&authCode=456456&trnApproved=1&avsId=M&cvdId=1&messageId=1&messageText=Approved&trnOrderNumber=1234" end + def successful_test_purchase_response + "merchant_id=100200000&trnId=11011067&authCode=TEST&trnApproved=1&avsId=M&cvdId=1&messageId=1&messageText=Approved&trnOrderNumber=1234" + end + def unsuccessful_purchase_response "merchant_id=100200000&trnId=11011069&authCode=&trnApproved=0&avsId=0&cvdId=6&messageId=16&messageText=Duplicate+transaction&trnOrderNumber=1234" end