cancel
Showing results for 
Search instead for 
Did you mean: 

Can't set x_delim_char or x_enca_char in PHP CIM SDK when parsing responses

As is, these two properties can be set when creating a transaction, but they aren't used when parsing the response from AIM. This means that the output from getTransactionResponse() will be quite broken. Also, because it is hardcoded to use a comma as the delimiter, it means it's impossible to allow users to use commas in something like their billing address.

 

It would be great if there was a method to set these two values instead of using extraOptions, so that the class could use them when parsing responses.

4 REPLIES 4

Here's a patch that defaults to using the pipe character for x_encap_char anyone else who is running into this issue.

diff --git lib/AuthorizeNetCIM.php lib/AuthorizeNetCIM.php
index f228feb..dcd0d1d 100644
--- lib/AuthorizeNetCIM.php
+++ lib/AuthorizeNetCIM.php
@@ -113,7 +113,7 @@ class AuthorizeNetCIM extends AuthorizeNetRequest
         $transactionParent = $this->_xml->addChild("transaction");
         $transactionChild = $transactionParent->addChild("profileTrans" . $transactionType);
         $this->_addObject($transactionChild, $transaction);
-        $this->_extraOptions = $extraOptionsString;
+        $this->_extraOptions = $extraOptionsString + "&x_encap_char=|";
         return $this->_sendRequest();
     }
     
@@ -433,7 +433,7 @@ class AuthorizeNetCIM_Response extends AuthorizeNetXMLResponse
      */
     public function getTransactionResponse()
     {
-        return new AuthorizeNetAIM_Response($this->_getElementContents("directResponse"), ",", "", array());
+        return new AuthorizeNetAIM_Response($this->_getElementContents("directResponse"), ",", "|", array());
     }
     
     /**
@@ -444,7 +444,7 @@ class AuthorizeNetCIM_Response extends AuthorizeNetXMLResponse
         $responses = (array)$this->xml->validationDirectResponseList;
         $return = array();
         foreach ((array)$responses["string"] as $response) {
-            $return[] = new AuthorizeNetAIM_Response($response, ",", "", array());
+            $return[] = new AuthorizeNetAIM_Response($response, ",", "|", array());
         }
         return $return;
     }
@@ -454,7 +454,7 @@ class AuthorizeNetCIM_Response extends AuthorizeNetXMLResponse
      */
     public function getValidationResponse()
     {
-        return new AuthorizeNetAIM_Response($this->_getElementContents("validationDirectResponse"), ",", "", array());
+        return new AuthorizeNetAIM_Response($this->_getElementContents("validationDirectResponse"), ",", "|", array());
     }
     
     /**

 

 

Here's an update that fixes an incorrect operator.

diff --git lib/AuthorizeNetCIM.php lib/AuthorizeNetCIM.php
index f228feb..dcd0d1d 100644
--- lib/AuthorizeNetCIM.php
+++ lib/AuthorizeNetCIM.php
@@ -113,7 +113,7 @@ class AuthorizeNetCIM extends AuthorizeNetRequest
         $transactionParent = $this->_xml->addChild("transaction");
         $transactionChild = $transactionParent->addChild("profileTrans" . $transactionType);
         $this->_addObject($transactionChild, $transaction);
-        $this->_extraOptions = $extraOptionsString;
+        $this->_extraOptions = $extraOptionsString . "&x_encap_char=|";
         return $this->_sendRequest();
     }
     
@@ -433,7 +433,7 @@ class AuthorizeNetCIM_Response extends AuthorizeNetXMLResponse
      */
     public function getTransactionResponse()
     {
-        return new AuthorizeNetAIM_Response($this->_getElementContents("directResponse"), ",", "", array());
+        return new AuthorizeNetAIM_Response($this->_getElementContents("directResponse"), ",", "|", array());
     }
     
     /**
@@ -444,7 +444,7 @@ class AuthorizeNetCIM_Response extends AuthorizeNetXMLResponse
         $responses = (array)$this->xml->validationDirectResponseList;
         $return = array();
         foreach ((array)$responses["string"] as $response) {
-            $return[] = new AuthorizeNetAIM_Response($response, ",", "", array());
+            $return[] = new AuthorizeNetAIM_Response($response, ",", "|", array());
         }
         return $return;
     }
@@ -454,7 +454,7 @@ class AuthorizeNetCIM_Response extends AuthorizeNetXMLResponse
      */
     public function getValidationResponse()
     {
-        return new AuthorizeNetAIM_Response($this->_getElementContents("validationDirectResponse"), ",", "", array());
+        return new AuthorizeNetAIM_Response($this->_getElementContents("validationDirectResponse"), ",", "|", array());
     }
     
     /**

 

 

I have also found that the "_setPostString" function also does not correctly replace everything as it should:

 

BAD:

$this->_post_string = str_replace("<extraOptions></extraOptions>",'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML());

 

GOOD:

$this->_post_string = str_replace(array("<extraOptions></extraOptions>","<extraOptions/>"),'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML());

I discovered that the library was creating an element as "<extraOptions/>" but the code wasn't set to do a string replace for the self-closing elements -- so even when I added the extra options in there (according to deviantintegral), the XML that was coming out still didn't have the values in there.

 

Making the code replace BOTH <extraOptions></extraOptions> AND <extraOptions/> fixed it for me!

 

Hope this helps!

Thanks for the heads up on that.  Your example looks like a good solution, I'll try to get it added soon to the official package.  It's unfortunate that simpleXML doesn't have native CDATA functionality so that we could avoid the str_replace altogether.