cancel
Showing results for 
Search instead for 
Did you mean: 

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.
2 REPLIES 2
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();
         }
     }
     

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.