Skip to content

Commit

Permalink
Fix response parsing and clean up fraud checks
Browse files Browse the repository at this point in the history
  • Loading branch information
John Duff committed Jul 6, 2012
1 parent 0d7975a commit de787a2
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 107 deletions.
36 changes: 17 additions & 19 deletions lib/active_merchant/billing/gateways/litle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,21 @@ def url
end

def build_response(kind, litle_response, valid_responses=%w(000))
if litle_response.response == "0"
detail = litle_response.send("#{kind}Response")
response = Hash.from_xml(litle_response.raw_xml.to_s)['litleOnlineResponse']

if response['response'] == "0"
detail = response["#{kind}Response"]
fraud = fraud_result(detail)
Response.new(
(valid_responses.include?(detail.response)),
detail.message,
{:litleOnlineResponse => litle_response},
:authorization => detail.litleTxnId,
:avs_result => {:code => fraud_result(detail)['avs']},
:cvv_result => fraud_result(detail)['cvv']
valid_responses.include?(detail['response']),
detail['message'],
{:litleOnlineResponse => response},
:authorization => detail['litleTxnId'],
:avs_result => {:code => fraud['avs']},
:cvv_result => fraud['cvv']
)
else
Response.new(false, litle_response.message, :litleOnlineResponse => litle_response)
Response.new(false, response['message'], :litleOnlineResponse => response)
end
end

Expand Down Expand Up @@ -269,17 +272,12 @@ def create_hash(money, options)
end

def fraud_result(authorization_response)
if authorization_response.respond_to?(:fraudResult)
fraud_result = authorization_response.fraudResult
if fraud_result.respond_to?(:cardValidationResult)
cvv_to_pass = fraud_result.cardValidationResult
if(cvv_to_pass == "")
cvv_to_pass = "P"
end
end
if fraud_result.respond_to?(:avsResult)
avs_to_pass = AVS_RESPONSE_CODE[fraud_result.avsResult]
if result = authorization_response['fraudResult']
if result.key?('cardValidationResult')
cvv_to_pass = result['cardValidationResult'].blank? ? "P" : result['cardValidationResult']
end

avs_to_pass = AVS_RESPONSE_CODE[result['avsResult']] unless result['avsResult'].blank?
end
{'cvv'=>cvv_to_pass, 'avs'=>avs_to_pass}
end
Expand Down
15 changes: 7 additions & 8 deletions test/remote/gateways/remote_litle_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'test_helper'


class RemoteLitleTest < Test::Unit::TestCase
def setup
Base.gateway_mode = :test
Expand Down Expand Up @@ -102,13 +101,13 @@ def test_authorization_capture_credit_void
assert_equal 'Approved', capture_response.message

#Credit against the Capture
capture_litle_txn_id = capture_response.params['litleOnlineResponse'].captureResponse.litleTxnId
capture_litle_txn_id = capture_response.params['litleOnlineResponse']['captureResponse']['litleTxnId']
assert credit_response = @gateway.credit(10010, capture_litle_txn_id)
assert_success credit_response
assert_equal 'Approved', credit_response.message

#Void that credit
credit_litle_txn_id = credit_response.params['litleOnlineResponse'].creditResponse.litleTxnId
credit_litle_txn_id = credit_response.params['litleOnlineResponse']['creditResponse']['litleTxnId']
assert void_response = @gateway.void(credit_litle_txn_id)
assert_success void_response
assert_equal 'Approved', void_response.message
Expand Down Expand Up @@ -138,10 +137,10 @@ def test_store_successful

assert_success store_response
assert_equal 'Account number was successfully registered', store_response.message
assert_equal '445711', store_response.params['litleOnlineResponse'].registerTokenResponse.bin
assert_equal 'VI', store_response.params['litleOnlineResponse'].registerTokenResponse['type'] #type is on Object in 1.8.7 - later versions can use .registerTokenResponse.type
assert_equal '801', store_response.params['litleOnlineResponse'].registerTokenResponse.response
assert_equal '1111222233330123', store_response.params['litleOnlineResponse'].registerTokenResponse.litleToken
assert_equal '445711', store_response.params['litleOnlineResponse']['registerTokenResponse']['bin']
assert_equal 'VI', store_response.params['litleOnlineResponse']['registerTokenResponse']['type'] #type is on Object in 1.8.7 - later versions can use .registerTokenResponse.type
assert_equal '801', store_response.params['litleOnlineResponse']['registerTokenResponse']['response']
assert_equal '1111222233330123', store_response.params['litleOnlineResponse']['registerTokenResponse']['litleToken']
end

def test_store_unsuccessful
Expand All @@ -150,7 +149,7 @@ def test_store_unsuccessful

assert_failure store_response
assert_equal 'Credit card number was invalid', store_response.message
assert_equal '820', store_response.params['litleOnlineResponse'].registerTokenResponse.response
assert_equal '820', store_response.params['litleOnlineResponse']['registerTokenResponse']['response']
end

end
Loading

0 comments on commit de787a2

Please sign in to comment.