Skip to content

Commit

Permalink
Detect test mode with Beanstream
Browse files Browse the repository at this point in the history
git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@669 6513ea26-6c20-0410-8a68-89cd7235086d
  • Loading branch information
codyfauser committed May 15, 2008
1 parent d6afe12 commit 035a24b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions 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]
Expand Down
3 changes: 2 additions & 1 deletion lib/active_merchant/billing/gateways/beanstream.rb
Expand Up @@ -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] }
Expand Down
24 changes: 24 additions & 0 deletions test/unit/gateways/beanstream_test.rb
Expand Up @@ -2,6 +2,8 @@

class BeanstreamTest < Test::Unit::TestCase
def setup
Base.mode = :test

@gateway = BeanstreamGateway.new(
:login => 'merchant id',
:user => 'username',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 035a24b

Please sign in to comment.