diff --git a/lib/active_merchant/billing/gateways/borgun.rb b/lib/active_merchant/billing/gateways/borgun.rb index 1850425e697..8c8143e2401 100644 --- a/lib/active_merchant/billing/gateways/borgun.rb +++ b/lib/active_merchant/billing/gateways/borgun.rb @@ -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 @@ -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], diff --git a/test/unit/gateways/borgun_test.rb b/test/unit/gateways/borgun_test.rb index 546d6aaa249..eb9fc57fd74 100644 --- a/test/unit/gateways/borgun_test.rb +++ b/test/unit/gateways/borgun_test.rb @@ -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 @@ -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' })) @@ -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 @@ -369,6 +385,25 @@ def successful_get_3ds_authentication_response RESPONSE end + def failed_get_3ds_authentication_response + %( + + + + + <?xml version="1.0" encoding="iso-8859-1"?> + <get3DSAuthenticationReply> + <Status> + <ResultCode>30</ResultCode> + <ResultText>MPI returns error</ResultText> + <ErrorMessage>Exception in PostEnrollmentRequest.</ErrorMessage> + </Status> + </get3DSAuthenticationReply> + + + ) + 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"