Permalink
Browse files

Allow setting test mode per transaction for litle

  • Loading branch information...
1 parent 1b4d8f8 commit 04c6c9a0e176cb69de3a6c9df342b02485a36069 @jduff jduff committed Aug 22, 2012
Showing with 30 additions and 2 deletions.
  1. +7 −2 lib/active_merchant/billing/gateways/litle.rb
  2. +23 −0 test/unit/gateways/litle_test.rb
@@ -101,6 +101,10 @@ def store(creditcard, options = {})
build_response(:registerToken, @litle.register_token_request(to_pass), %w(801 802))
end
+ def test?
+ super || @options[:test]
+ end
+
private
CARD_TYPE = {
@@ -148,10 +152,11 @@ def build_response(kind, litle_response, valid_responses=%w(000))
{:litleOnlineResponse => response},
:authorization => detail['litleTxnId'],
:avs_result => {:code => fraud['avs']},
- :cvv_result => fraud['cvv']
+ :cvv_result => fraud['cvv'],
+ :test => test?
)
else
- Response.new(false, response['message'], :litleOnlineResponse => response)
+ Response.new(false, response['message'], :litleOnlineResponse => response, :test => test?)
end
end
@@ -527,4 +527,27 @@ def test_store_fail_schema
assert_equal 'Error validating xml data against the schema', responseFrom.message
end
+ def test_in_production_with_test_param_sends_request_to_test_server
+ begin
+ ActiveMerchant::Billing::Base.mode = :production
+ @gateway = LitleGateway.new(
+ :merchant_id => 'login',
+ :login => 'login',
+ :password => 'password',
+ :test => true
+ )
+ purchaseResponseObj = {'response' => '000', 'message' => 'successful', 'litleTxnId'=>'123456789012345678'}
+ retObj = {'response'=>'0','saleResponse'=>purchaseResponseObj}
+ LitleOnline::Communications.expects(:http_post).with(anything,has_entry('url', 'https://www.testlitle.com/sandbox/communicator/online')).returns(retObj.to_xml(:root => 'litleOnlineResponse'))
+
+ creditcard = CreditCard.new(@credit_card_options)
+ assert response = @gateway.purchase(@amount, credit_card)
+ assert_instance_of Response, response
+ assert_success response
+ assert response.test?, response.inspect
+ ensure
+ ActiveMerchant::Billing::Base.mode = :test
+ end
+ end
+
end

0 comments on commit 04c6c9a

Please sign in to comment.