cancel
Showing results for 
Search instead for 
Did you mean: 

CIM Integration: Getting the initial TOKEN and/or initial Profile

We are attempting to use the CIM system.  The instructions tell us that we first need to aquire a token in order to create a blank profile.

 

I can't find any instructions or methods on aquiring that token that actually work.

 

I'm trying to use the downloaded example files for this process.   The exact system I'm using is the file located at  /php_cim/xml/profile_create.php, which was aquired by downloading the php_cim package from this site.

 

I've made all modifications required (ID's and servers changed to what is actually required),  but I still only get back a response that says:

 

"[E00045] The root node does not reference a valid XML namespace."

 

I've quadruple-checked the small amount of code that is provided in the download package to be sure I haven't missed a modification I needed to do, and I have not missed any of them.

 

The message returned from the authorizenet server when using that file also makes a reference (in the 'raw response') to an address that I'm thinking might be the reason for the error message.

The line says "xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"

 

The part of that line that I'm concerned with is 'AnetAPI'.   In the example code provided to me here,  I'm told that I have to change all references of 'AnetAPI' to the actxual server that I'm supposed to use for the transaction (which I have done).

I no longer have 'AnetApi' in any part of my code.  I even swept through all the code on the server and found no pages that have AnetApi on them at all.

 

The only way that the term 'AnetAPI' could be coming back in the raw response,  if my conclusion is correct,  is if it is being used at the 'other end' of the transaction.. at AuthorizeNet's servers.

 

There may be a perfectly good explanation as to why AN would have 'AnetApi' in their code,  and it may have nothing to do with this system not functioning,  but I can't see anything else that could be causing the error that is coming up.

 

When I sent a support request in,  explaining our situation and that we couldn't even get a TOKEN to be returned to us (due to not being able to find any instructions on how to get it),  the response we got back literally said, "Once you are able to obtain the one-time tokens, you can find examples of how to integrate the hosted payment form into your site in our developer forums".

 

There was no explanation on how to actually get the token, which was what my question was to begin with.

 

I've mentioned this before and have yet to get a reply to it.

 

Our site needs to be able to accept payments.  We want to use CIM for our customers security.  We've been at this for days now, and if we can't even get the first thing done (the token request),  we're just spinning our wheels here.

 

Here is the example code we downloaded that produces the error we are getting (unused code edited out to save room):

 

Page Name:  index.php

<form method=post action=profile_create.php>
<b>Create Customer Profile</b><br>
email <input type=text name=email value='example@example.com'><br>
<input type=submit name=submit value=submit>
</form>

 

Page Name: profile_create.php

<?php

include_once ("vars.php");
include_once ("util.php");

echo "create profile...<br><br>";

//build xml to post
$content =
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
	"<createCustomerProfileRequest xmlns=\"https://api.authorize.net/xml/v1/request.api\">" .
	MerchantAuthenticationBlock().
	"<profile>".
	"<merchantCustomerId>123_Our_Customer_ID</merchantCustomerId>". 
	"<description></description>".
	"<email>" . $_POST["email"] . "</email>".
	"</profile>".
	"</createCustomerProfileRequest>";

echo "Raw request: " . htmlspecialchars($content) . "<br><br>";
$response = send_xml_request($content);
echo "Raw response: " . htmlspecialchars($response) . "<br><br>";
$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
	echo "customerProfileId <b>"
		. htmlspecialchars($parsedresponse->customerProfileId)
		. "</b> was successfully created.<br><br>";
}

echo "<br><a href=index.php?customerProfileId="
	. urlencode($parsedresponse->customerProfileId)
	. ">Continue</a><br>";
?>

 Page Name: vars.php

<?php
$g_loginname = "234_Our_ID";
$g_transactionkey = "345_Our_Key";
$g_apihost = "api.authorize.net";
$g_apipath = "/xml/v1/request.api";

?>

 

 Page Name:  util.php

<?php

include_once ("vars.php");

function send_xml_request($content)
{
	global $g_apihost, $g_apipath;
	return send_request_via_fsockopen($g_apihost,$g_apipath,$content);
}

function send_request_via_fsockopen($host,$path,$content)
{
	$posturl = "ssl://" . $host;
	$header = "Host: $host\r\n";
	$header .= "User-Agent: PHP Script\r\n";
	$header .= "Content-Type: text/xml\r\n";
	$header .= "Content-Length: ".strlen($content)."\r\n";
	$header .= "Connection: close\r\n\r\n";
	$fp = fsockopen($posturl, 443, $errno, $errstr, 30);
	if (!$fp)
	{
		$body = false;
	}
	else
	{
		error_reporting(E_ERROR);
		fputs($fp, "POST $path  HTTP/1.1\r\n");
		fputs($fp, $header.$content);
		fwrite($fp, $out);
		$response = "";
		while (!feof($fp))
		{
			$response = $response . fgets($fp, 128);
		}
		fclose($fp);
		error_reporting(E_ALL ^ E_NOTICE);
		
		$len = strlen($response);
		$bodypos = strpos($response, "\r\n\r\n");
		if ($bodypos <= 0)
		{
			$bodypos = strpos($response, "\n\n");
		}
		while ($bodypos < $len && $response[$bodypos] != '<')
		{
			$bodypos++;
		}
		$body = substr($response, $bodypos);
	}
	return $body;
}

//function to send xml request via curl
function send_request_via_curl($host,$path,$content)
{
	$posturl = "https://" . $host . $path;
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $posturl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
	curl_setopt($ch, CURLOPT_HEADER, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	$response = curl_exec($ch);
	return $response;
}

function parse_api_response($content)
{
	$parsedresponse = simplexml_load_string($content, "SimpleXMLElement", LIBXML_NOWARNING);
	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;
}

function MerchantAuthenticationBlock() {
	global $g_loginname, $g_transactionkey;
	return
        "<merchantAuthentication>".
        "<name>" . $g_loginname . "</name>".
        "<transactionKey>" . $g_transactionkey . "</transactionKey>".
        "</merchantAuthentication>";
}

?>

 

 When we run the profile_create.php page (by clicking the button on index.php),  we get this returned:

 

  Raw request: <?xml version="1.0" encoding="utf-8"?><createCustomerProfileRequest xmlns="https://api.authorize.net/xml/v1/request.api"><merchantAuthentication><name>234_Our_ID</name><transactionKey>345_Our_Key</transactionKey></merchantAuthentication><profile><merchantCustomerId>123_Our_Customer_ID</merchantCustomerId><description></description><email>example@example.com</email></profile></createCustomerProfileRequest>

 Raw response: <?xml version="1.0" encoding="utf-8"?><ErrorResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Error</resultCode><message><code>E00045</code><text>The root node does not reference a valid XML namespace.</text></message></messages></ErrorResponse>

The operation failed with the following errors:
[E00045] The root node does not reference a valid XML namespace.

 

 From what I understand,  this page is supposed to create a new CIM profile for a customer,  not throw this error.

 

 Our account is live and in test mode.

 

 Any idea what I'm doing wrong?

 

Thanks,

JB

 

 

WHeisenberg
Regular Contributor
10 REPLIES 10

Hello, could you make it work with php? Any sample code?

Thanks