Skip to content

Commit

Permalink
Repair Mecury and TransFirst (#5206)
Browse files Browse the repository at this point in the history
* Repair Mecury and TransFirst

A previous commit broke these gateways after updating REXML. This
commit updates the two gateways so that they can process the XML
like it used to.

Test Summary
Remote:
No credentials available for Mercury
Could not reach the test server for TransFirst

* changelog
  • Loading branch information
aenand committed Aug 8, 2024
1 parent f52d344 commit 3e7aa32
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
= ActiveMerchant CHANGELOG

== HEAD
* Mercury, TransFirst: Repair gateways following updates to `rexml` [aenand] #5206.

= Version 1.137.0 (August 2, 2024)

Expand Down
4 changes: 3 additions & 1 deletion lib/active_merchant/billing/gateways/mercury.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ def escape_xml(xml)
end

def unescape_xml(escaped_xml)
escaped_xml.gsub(/\&gt;/, '>').gsub(/\&lt;/, '<')
xml = escaped_xml.gsub(/\&gt;/, '>')
xml.slice! "<?xml version=\"1.0\"?>" # rubocop:disable Style/StringLiterals
xml
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/active_merchant/billing/gateways/trans_first.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ def parse(data)
end
end

response
rescue StandardError
response[:message] = data&.to_s&.strip
response
end

Expand Down
6 changes: 3 additions & 3 deletions test/unit/gateways/mercury_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_transcript_scrubbing

def successful_purchase_response
<<~RESPONSE
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CreditTransactionResponse xmlns="http://www.mercurypay.com"><CreditTransactionResult>
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CreditTransactionResponse xmlns="http://www.mercurypay.com"><CreditTransactionResult><?xml version="1.0"?>
<RStream>
<CmdResponse>
<ResponseOrigin>Processor</ResponseOrigin>
Expand Down Expand Up @@ -163,7 +163,7 @@ def successful_purchase_response

def failed_purchase_response
<<~RESPONSE
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CreditTransactionResponse xmlns="http://www.mercurypay.com"><CreditTransactionResult>
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CreditTransactionResponse xmlns="http://www.mercurypay.com"><CreditTransactionResult><?xml version="1.0"?>
<RStream>
<CmdResponse>
<ResponseOrigin>Server</ResponseOrigin>
Expand All @@ -179,7 +179,7 @@ def failed_purchase_response

def successful_refund_response
<<~RESPONSE
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CreditTransactionResponse xmlns="http://www.mercurypay.com"><CreditTransactionResult>
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CreditTransactionResponse xmlns="http://www.mercurypay.com"><CreditTransactionResult><?xml version="1.0"?>
<RStream>
<CmdResponse>
<ResponseOrigin>Processor</ResponseOrigin>
Expand Down
10 changes: 10 additions & 0 deletions test/unit/gateways/trans_first_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ def setup
@amount = 100
end

def test_missing_field_response
@gateway.stubs(:ssl_post).returns(missing_field_response)

response = @gateway.purchase(@amount, @credit_card, @options)

assert_failure response
assert response.test?
assert_equal 'Missing parameter: UserId.', response.message
end

def test_successful_purchase
@gateway.stubs(:ssl_post).returns(successful_purchase_response)

Expand Down

0 comments on commit 3e7aa32

Please sign in to comment.