Skip to content

Commit

Permalink
Litle update the successful_from method
Browse files Browse the repository at this point in the history
Add 001 and 010 to be considered successful responses for Litle.

Remote
57 tests, 251 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
Unit
58 tests, 255 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
Alma Malambo committed May 2, 2023
1 parent a753cbc commit a51d854
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
* IPG: Improve error handling [heavyblade] #4753
* Shift4: Handle access token failed calls [heavyblade] #4745
* Bogus: Add verify functionality [willemk] #4749
* Litle: Update successful_from method [almalee24] #4765

== Version 1.127.0 (September 20th, 2022)
* BraintreeBlue: Add venmo profile_id [molbrown] #4512
Expand Down
15 changes: 13 additions & 2 deletions lib/active_merchant/billing/gateways/litle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,26 @@ def commit(kind, request, money = nil)
cvv_result: parsed[:fraudResult_cardValidationResult]
}

Response.new(success_from(kind, parsed), parsed[:message], parsed, options)
Response.new(success_from(kind, parsed), message_from(parsed), parsed, options)
end

def success_from(kind, parsed)
return (parsed[:response] == '000') unless kind == :registerToken
return %w(000 001 010).any?(parsed[:response]) unless kind == :registerToken

%w(000 801 802).include?(parsed[:response])
end

def message_from(parsed)
case parsed[:response]
when '010'
return "#{parsed[:message]}: The authorized amount is less than the requested amount."
when '001'
return "#{parsed[:message]}: This is sent to acknowledge that the submitted transaction has been received."
else
parsed[:message]
end
end

def authorization_from(kind, parsed, money)
kind == :registerToken ? parsed[:litleToken] : "#{parsed[:litleTxnId]};#{kind};#{money}"
end
Expand Down
54 changes: 32 additions & 22 deletions test/remote/gateways/remote_litle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def setup
routing_number: '011100012',
account_number: '1099999998'
)

@declined_card = credit_card('4488282659650110', first_name: nil, last_name: 'REFUSED')
end

def test_successful_authorization
Expand Down Expand Up @@ -143,14 +145,22 @@ def test_successful_authorization_with_echeck
assert_equal 'Approved', response.message
end

def test_avs_and_cvv_result
def test_avs_result
@credit_card1.number = '4200410886320101'
assert response = @gateway.authorize(10010, @credit_card1, @options)
assert_equal 'X', response.avs_result['code']
assert_equal 'M', response.cvv_result['code']

assert_equal 'Z', response.avs_result['code']
end

def test__cvv_result
@credit_card1.number = '4100521234567000'
assert response = @gateway.authorize(10010, @credit_card1, @options)

assert_equal 'P', response.cvv_result['code']
end

def test_unsuccessful_authorization
assert response = @gateway.authorize(60060, @credit_card2,
assert response = @gateway.authorize(60060, @declined_card,
{
order_id: '6',
billing_address: {
Expand Down Expand Up @@ -231,7 +241,7 @@ def test_successful_purchase_with_3ds_fields
def test_successful_purchase_with_apple_pay
assert response = @gateway.purchase(10010, @decrypted_apple_pay)
assert_success response
assert_equal 'Approved', response.message
assert_equal 'Partially Approved: The authorized amount is less than the requested amount.', response.message
end

def test_successful_purchase_with_android_pay
Expand Down Expand Up @@ -370,7 +380,7 @@ def test_successful_purchase_with_echeck
end

def test_unsuccessful_purchase
assert response = @gateway.purchase(60060, @credit_card2, {
assert response = @gateway.purchase(60060, @declined_card, {
order_id: '6',
billing_address: {
name: 'Joe Green',
Expand Down Expand Up @@ -398,6 +408,8 @@ def test_authorize_capture_refund_void
assert_success refund
assert_equal 'Approved', refund.message

sleep 40.seconds

assert void = @gateway.void(refund.authorization)
assert_success void
assert_equal 'Approved', void.message
Expand All @@ -422,7 +434,7 @@ def test_authorize_and_capture_with_stored_credential_recurring
)
assert auth = @gateway.authorize(4999, credit_card, initial_options)
assert_success auth
assert_equal 'Approved', auth.message
assert_equal 'Transaction Received: This is sent to acknowledge that the submitted transaction has been received.', auth.message
assert network_transaction_id = auth.params['networkTransactionId']

assert capture = @gateway.capture(4999, auth.authorization)
Expand All @@ -440,7 +452,7 @@ def test_authorize_and_capture_with_stored_credential_recurring
)
assert auth = @gateway.authorize(4999, credit_card, used_options)
assert_success auth
assert_equal 'Approved', auth.message
assert_equal 'Transaction Received: This is sent to acknowledge that the submitted transaction has been received.', auth.message

assert capture = @gateway.capture(4999, auth.authorization)
assert_success capture
Expand Down Expand Up @@ -642,9 +654,9 @@ def test_void_authorization
end

def test_unsuccessful_void
assert void = @gateway.void('123456789012345360;authorization;100')
assert void = @gateway.void('1234567890r2345360;authorization;100')
assert_failure void
assert_equal 'No transaction found with specified Transaction Id', void.message
assert_match(/^Error validating xml data against the schema/, void.message)
end

def test_successful_credit
Expand Down Expand Up @@ -710,15 +722,15 @@ def test_nil_amount_capture
end

def test_capture_unsuccessful
assert capture_response = @gateway.capture(10010, '123456789012345360')
assert capture_response = @gateway.capture(10010, '123456789w123')
assert_failure capture_response
assert_equal 'No transaction found with specified Transaction Id', capture_response.message
assert_match(/^Error validating xml data against the schema/, capture_response.message)
end

def test_refund_unsuccessful
assert credit_response = @gateway.refund(10010, '123456789012345360')
assert credit_response = @gateway.refund(10010, '123456789w123')
assert_failure credit_response
assert_equal 'No transaction found with specified Transaction Id', credit_response.message
assert_match(/^Error validating xml data against the schema/, credit_response.message)
end

def test_void_unsuccessful
Expand All @@ -733,10 +745,8 @@ def test_store_successful

assert_success store_response
assert_equal 'Account number was successfully registered', store_response.message
assert_equal '445711', store_response.params['bin']
assert_equal 'VI', store_response.params['type']
assert_equal '801', store_response.params['response']
assert_equal '1111222233330123', store_response.params['litleToken']
assert_equal '1111222233334444', store_response.params['litleToken']
end

def test_store_with_paypage_registration_id_successful
Expand All @@ -750,11 +760,11 @@ def test_store_with_paypage_registration_id_successful
end

def test_store_unsuccessful
credit_card = CreditCard.new(@credit_card_hash.merge(number: '4457119999999999'))
credit_card = CreditCard.new(@credit_card_hash.merge(number: '4100282090123000'))
assert store_response = @gateway.store(credit_card, order_id: '51')

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

Expand All @@ -768,7 +778,7 @@ def test_store_and_purchase_with_token_successful

assert response = @gateway.purchase(10010, token)
assert_success response
assert_equal 'Approved', response.message
assert_equal 'Partially Approved: The authorized amount is less than the requested amount.', response.message
end

def test_purchase_with_token_and_date_successful
Expand All @@ -780,7 +790,7 @@ def test_purchase_with_token_and_date_successful

assert response = @gateway.purchase(10010, token, { basis_expiration_month: '01', basis_expiration_year: '2024' })
assert_success response
assert_equal 'Approved', response.message
assert_equal 'Partially Approved: The authorized amount is less than the requested amount.', response.message
end

def test_echeck_store_and_purchase
Expand All @@ -793,7 +803,7 @@ def test_echeck_store_and_purchase

assert response = @gateway.purchase(10010, token)
assert_success response
assert_equal 'Approved', response.message
assert_equal 'Partially Approved: The authorized amount is less than the requested amount.', response.message
end

def test_successful_verify
Expand Down
34 changes: 31 additions & 3 deletions test/unit/gateways/litle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,35 @@ def test_successful_purchase
end.respond_with(successful_purchase_response)

assert_success response
assert_equal 'Approved', response.message
assert_equal '100000000000000006;sale;100', response.authorization
assert response.test?
end

def test_successful_purchase_with_010_response
response = stub_comms do
@gateway.purchase(@amount, @credit_card)
end.check_request do |endpoint, _data, _headers|
# Counterpoint to test_successful_postlive_url:
assert_match(/www\.testvantivcnp\.com/, endpoint)
end.respond_with(successful_purchase_response('010', 'Partially Approved'))

assert_success response
assert_equal 'Partially Approved: The authorized amount is less than the requested amount.', response.message
assert_equal '100000000000000006;sale;100', response.authorization
assert response.test?
end

def test_successful_purchase_with_001_response
response = stub_comms do
@gateway.purchase(@amount, @credit_card)
end.check_request do |endpoint, _data, _headers|
# Counterpoint to test_successful_postlive_url:
assert_match(/www\.testvantivcnp\.com/, endpoint)
end.respond_with(successful_purchase_response('001', 'Transaction Received'))

assert_success response
assert_equal 'Transaction Received: This is sent to acknowledge that the submitted transaction has been received.', response.message
assert_equal '100000000000000006;sale;100', response.authorization
assert response.test?
end
Expand Down Expand Up @@ -732,15 +760,15 @@ def network_transaction_id
'63225578415568556365452427825'
end

def successful_purchase_response
def successful_purchase_response(code = '000', message = 'Approved')
%(
<litleOnlineResponse version='8.22' response='0' message='Valid Format' xmlns='http://www.litle.com/schema'>
<saleResponse id='1' reportGroup='Default Report Group' customerId=''>
<litleTxnId>100000000000000006</litleTxnId>
<orderId>1</orderId>
<response>000</response>
<response>#{code}</response>
<responseTime>2014-03-31T11:34:39</responseTime>
<message>Approved</message>
<message>#{message}</message>
<authCode>11111 </authCode>
<fraudResult>
<avsResult>01</avsResult>
Expand Down

0 comments on commit a51d854

Please sign in to comment.