Reply
Member
Posts: 9
Registered: ‎02-21-2011

PHP SDK bug with setting extraOptions string for CIM

There's a bug in AuthorizeNetCIM::_setPostString() method. On my PHP installation, the empty extraOptions tag is being rendered as

<extraOptions/>

That doesn't match the str_replace call. Since both versions are valid XML, here's a patch that uses the DOM API to add the CDATA section:

diff --git lib/AuthorizeNetCIM.php lib/AuthorizeNetCIM.php
index 653e731..379ec02 100644
--- lib/AuthorizeNetCIM.php
+++ lib/AuthorizeNetCIM.php
@@ -339,8 +339,10 @@ class AuthorizeNetCIM extends AuthorizeNetRequest
         
         // Add extraOptions CDATA
         if ($this->_extraOptions) {
-            $this->_xml->addChild("extraOptions");
-            $this->_post_string = str_replace("",'' . $this->_extraOptions . '', $this->_xml->asXML());
+            $dom = dom_import_simplexml($this->_xml);
+            $extraOptions = $dom->appendChild($dom->ownerDocument->createElement("extraOptions"));
+            $extraOptions->appendChild($dom->ownerDocument->createCDATASection($this->_extraOptions));
+            $this->_post_string = $this->_xml->asXML();
         }
     }
     
I don't see a public bug tracker anywhere, but if there is please point me to it and I'll file an issue.
Member
Posts: 9
Registered: ‎02-21-2011

Re: PHP SDK bug with setting extraOptions string for CIM

Looks like the editor munged my patch. Let's try this again.
diff --git lib/AuthorizeNetCIM.php lib/AuthorizeNetCIM.php
index 653e731..379ec02 100644
--- lib/AuthorizeNetCIM.php
+++ lib/AuthorizeNetCIM.php
@@ -339,8 +339,10 @@ class AuthorizeNetCIM extends AuthorizeNetRequest
         
         // Add extraOptions CDATA
         if ($this->_extraOptions) {
-            $this->_xml->addChild("extraOptions");
-            $this->_post_string = str_replace("<extraOptions></extraOptions>",'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML());
+            $dom = dom_import_simplexml($this->_xml);
+            $extraOptions = $dom->appendChild($dom->ownerDocument->createElement("extraOptions"));
+            $extraOptions->appendChild($dom->ownerDocument->createCDATASection($this->_extraOptions));
+            $this->_post_string = $this->_xml->asXML();
         }
     }
     
Member
Posts: 1
Registered: ‎05-19-2012

Re: PHP SDK bug with setting extraOptions string for CIM

I can confirm this.

There is a bug.

 

The simplier way to fix it is to change:

$this->_xml->addChild("extraOptions"); 

to

$this->_xml->addChild("extraOptions", '');

 

Weird thing that Authorize.net still didn't do anything about it.