cancel
Showing results for 
Search instead for 
Did you mean: 

Having trouble with PHP sample code for CIM

I've done programming for Authorize.net in the past without any problems, but I wanted to take a look at CIM in the sandbox today. I'm having trouble with the PHP sample code. I entered the login id and transaction key into vars.php, but when I try to run profile_create.php, the only response I get back is "The operation failed with the following errors:" (with nothing listed afterwards).

 

I'm running this on a test server that has a copy of our production code on it that works fine, so it shouldn't be a problem with the server setup.

unitedu
Contributor
5 REPLIES 5

OK, I've changed it to use curl instead of fsockopen, and I'm actually getting some stuff back now.

unitedu
Contributor

However the XML parsing isn't working because the response contains more than just XML. So much for useful sample code...

This works:

 

function parse_api_response($content)
{
   $content = substr($content, strpos($content, "<")); // strip out header lines
   $parsedresponse = simplexml_load_string($content, "SimpleXMLElement");
   if ("Ok" != $parsedresponse->messages->resultCode) {
      echo "The operation failed with the following errors:<br>";
      foreach ($parsedresponse->messages->message as $msg) {
         echo "[" . htmlspecialchars($msg->code) . "] " . htmlspecialchars($msg->text) . "<br>";
      }
      echo "<br>";
   }
   return $parsedresponse;
}

Hi there,

 

Check out the new PHP samle code on github, it's still work-in-progress but here are the CIM samples:  https://github.com/AuthorizeNet/sample-code-php/tree/master/CustomerProfiles

 

You can see they are also matched with our API explorer http://developer.authorize.net/api/reference/index.html#manage-customer-profiles

 

Hope this helps,

 

Brian

Thanks. I tried that and found it to also have problems.

 

I then found this, which seems to work pretty well:

 

http://www.johnconde.net/blog/tutorial-integrate-authorize-net-xml-api-universal-php-class/