How to fix warning in authorized.net transaction details api?

From last couple of days, I was struggling with an Authorized.net Transaction Details API.

 

The code I am working with is written in namespaces/blocks, so the problem I was facing is just like below.

 

SimpleXMLElement::__construct(): Entity: line 1: parser warning : xmlns: URI AnetApi/xml/v1/schema/AnetApiSchema.xsd is not absolute in /classes/anet_php_sdk/lib/AuthorizeNetTD.php on line 188

 

 

To get rid of these warning you have to follow some simple steps as below. I am assuming you are working with Authorized.net SDK Package, have downloaded by below URL. http://developer.authorize.net/downloads/

 

You have to update some small changes in 2 files.

1. anet_php_sdk\lib\AuthorizeNetTD.php

2. anet_php_sdk\lib\shared\AuthorizeNetXMLResponse.php

 

In first step open file “AuthorizeNetTD.php”. Find method “_constructXml”, in this method replace first 2 lines

[php]

<?php

$string = ‘<‘.$request_type.’ xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">’;
$this->_xml = @new SimpleXMLElement($string);

?>

[/php]

By below 3 lines of code

[php]

<?php

$string = ‘<‘.$request_type.’>’;
$this->_xml = @new SimpleXMLElement($string);
$this->_xml->addAttribute(‘xmlns’, ‘AnetApi/xml/v1/schema/AnetApiSchema.xsd’);

?>

[/php]

Now open “AuthorizeNetXMLResponse.php”. Copy/Paste the below method in the class.

[php]

<?php

/* @refer http://community.developer.authorize.net/t5/Integration-and-Testing/ARB-with-SimpleXML-PHP-Issue/m-p/7128#M5139*/
private function removeResponseXMLNS($input)
{
// Remove XML response namespaces one by one
$input = str_replace(‘ xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"’,”,$input);
$input = str_replace(‘ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"’,”,$input);
return str_replace(‘ xmlns:xsd="http://www.w3.org/2001/XMLSchema"’,”,$input);
}

?>
[/php]

Use this method in the constructor “__construct” of the class or replace this

[php]$this->xml = @simplexml_load_string($response);[/php]

By this

[php]$this->xml = @simplexml_load_string($this->removeResponseXMLNS($response));[/php]

One thought on “How to fix warning in authorized.net transaction details api?”

  1. Thanks for telling me about transaction detail, I am from last two days continue facing the problem, Your article is very helpful for me to reduce my headach of warning messages

    Thanks again

Comments are closed.