Skip to content

Commit

Permalink
Borgun: Update authorization_from & message_from
Browse files Browse the repository at this point in the history
Update authorization_from to return nil if the transaction failed or
it is a 3DS transaction. Update message_from to return ErrorMessage
if present.

Unit:
12 tests, 66 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
Remote:
22 tests, 43 assertions, 6 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
72.7273% passed
  • Loading branch information
Alma Malambo committed Jul 7, 2023
1 parent 2566c8b commit 38a6a9d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/active_merchant/billing/gateways/borgun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def commit(action, post, options = {})
success,
message_from(success, pairs),
pairs,
authorization: authorization_from(pairs),
authorization: authorization_from(pairs, success, options),
test: test?
)
end
Expand All @@ -185,11 +185,15 @@ def message_from(succeeded, response)
if succeeded
'Succeeded'
else
response[:message] || "Error with ActionCode=#{response[:actioncode]}"
response[:message] || response[:status_errormessage] || "Error with ActionCode=#{response[:actioncode]}"
end
end

def authorization_from(response)
def authorization_from(response, succeeded, options)
return nil unless succeeded
# 3DS reponses don't have the below params
return nil if options[:apply_3d_secure] == '1'

[
response[:dateandtime],
response[:batch],
Expand Down
35 changes: 35 additions & 0 deletions test/unit/gateways/borgun_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_failed_purchase

response = @gateway.purchase(@amount, @credit_card, @options)
assert_failure response
assert response.authorization.blank?
end

def test_authorize_and_capture
Expand All @@ -56,6 +57,20 @@ def test_authorize_and_capture
assert_success capture
end

def test_failed_preauth_3ds
response = stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge({ redirect_url: 'http://localhost/index.html', apply_3d_secure: '1', sale_description: 'product description' }))
end.check_request do |_endpoint, data, _headers|
assert_match(/MerchantReturnURL>#{@options[:redirect_url]}/, data)
assert_match(/SaleDescription>#{@options[:sale_description]}/, data)
assert_match(/TrCurrencyExponent>2/, data)
end.respond_with(failed_get_3ds_authentication_response)

assert_failure response
assert_equal response.message, 'Exception in PostEnrollmentRequest.'
assert response.authorization.blank?
end

def test_successful_preauth_3ds
response = stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge({ redirect_url: 'http://localhost/index.html', apply_3d_secure: '1', sale_description: 'product description' }))
Expand All @@ -70,6 +85,7 @@ def test_successful_preauth_3ds
assert !response.params['acsformfields_actionurl'].blank?
assert !response.params['acsformfields_pareq'].blank?
assert !response.params['threedsmessageid'].blank?
assert response.authorization.blank?
end

def test_successful_purchase_after_3ds
Expand Down Expand Up @@ -369,6 +385,25 @@ def successful_get_3ds_authentication_response
RESPONSE
end

def failed_get_3ds_authentication_response
%(
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"></SOAP-ENV:Header><SOAP-ENV:Body>
<ser-root:get3DSAuthenticationResponse xmlns:ser-root="http://Borgun/Heimir/pub/ws/Authorization" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<getAuth3DSResXml>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
&lt;get3DSAuthenticationReply&gt;
&lt;Status&gt;
&lt;ResultCode&gt;30&lt;/ResultCode&gt;
&lt;ResultText&gt;MPI returns error&lt;/ResultText&gt;
&lt;ErrorMessage&gt;Exception in PostEnrollmentRequest.&lt;/ErrorMessage&gt;
&lt;/Status&gt;
&lt;/get3DSAuthenticationReply&gt;</getAuth3DSResXml>
</ser-root:get3DSAuthenticationResponse></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
)
end

def transcript
<<-PRE_SCRUBBED
<- "POST /ws/Heimir.pub.ws:Authorization HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: Basic yyyyyyyyyyyyyyyyyyyyyyyyyy==\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: gateway01.borgun.is\r\nContent-Length: 1220\r\n\r\n"
Expand Down

0 comments on commit 38a6a9d

Please sign in to comment.