I’m adding Authorize.NET to one of my client’s CakePHP apps and used the Authorize.NET CakePHP Component which saved me a world of time.
But, after setting everything up, I ran my first transaction and got this error: The merchant login ID or password is invalid or the account is inactive. I double checked my API Login ID and Transaction Key and they were correct. Finally, I stumbled on a helpful thread that set me in the right direction.
I was using the test.authorize.net URL but that is only for developer accounts. Even if you are in Test mode, but have a ‘Normal’ Authorize.NET account, you need to use the secure.authorize.net URL.
In order to call CakePHP from non-CakePHP code, we will copy index.php from /app/webroot and put it into our non-CakePHP codebase as cakephp.php.
Then, we’ll create a function requestCakePHP that requires the cakephp.php file:
function requestCakePHP($url)
{
// Set the url parameter for cakephp
$_GET['url'] = $url;
require_once 'cakephp.php';
// Fire up CakePHP and buffer results
ob_start();
$Dispatcher= new Dispatcher ();
$Dispatcher->dispatch($url);
return ob_get_clean();
}
?>
Then, whenever we need to call for some Cake, we just call requestCake with the URL minus the hostname:
echo requestCakePHP("/webpages/view/2");
In the example above, I have a webpages controller, a view action and am viewing webpage #2.