I did not expect it to be this easy to integrate. All I did was download the sdk for AIM method in authorize.net official site under developer section. You need to create a test account with the site and get the api login id and transaction id using which you can test the account.
--> Unzip the zip file copy the entire folder into your_project/app/controller/component/ folder.
--> Copy the lib folder, Authorize.Net.php file into the component folder, instead of having the entire thing into this folder "anet_php_sdk"
--> Now rename the AuthorizeNet.php to authorize_net.php and modify the class name to
class AuthorizeNetComponent extends Object
instead of Exception class.
Now write a function for ex. validate_card() which accepts two parameters that is your login id and transaction id.
Here is how your class in authorize_net.php should look like
In your controller, include another Component to your var $component list which is AuthorizeNet.
And now write another function which should look like this.
Thats it in your browser now call this action: http://localhost/your_controller/testauth
And you should see success message if you use the same card details, change a bit and see if it says success or failure.
You can either add parameters to the function validate_card to send in the card details etc., Or send as an array or have public variables in the AuthorizeNet class and use them to set the values from your form. You can use any method to integrate this payment method.
--> Unzip the zip file copy the entire folder into your_project/app/controller/component/ folder.
--> Copy the lib folder, Authorize.Net.php file into the component folder, instead of having the entire thing into this folder "anet_php_sdk"
--> Now rename the AuthorizeNet.php to authorize_net.php and modify the class name to
class AuthorizeNetComponent extends Object
instead of Exception class.
Now write a function for ex. validate_card() which accepts two parameters that is your login id and transaction id.
Here is how your class in authorize_net.php should look like
class AuthorizeNetComponent extends Object
{
function validate_card($loginid=null,$trankey=null)
{
$transaction = new AuthorizeNetAIM($loginid, $trankey);
$transaction->amount = '9.99';
$transaction->card_num = '4007000000027';
$transaction->exp_date = '10/16';
//$transaction->cardholder_authentication_value = '778';
return $transaction->authorizeAndCapture();
}
}
{
function validate_card($loginid=null,$trankey=null)
{
$transaction = new AuthorizeNetAIM($loginid, $trankey);
$transaction->amount = '9.99';
$transaction->card_num = '4007000000027';
$transaction->exp_date = '10/16';
//$transaction->cardholder_authentication_value = '778';
return $transaction->authorizeAndCapture();
}
}
In your controller, include another Component to your var $component list which is AuthorizeNet.
And now write another function which should look like this.
function testauth()
{
$response = $this->AuthorizeNet->validate_card('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY'
{
$response = $this->AuthorizeNet->validate_card('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY'
);
if ($response->approved) {
echo "<h1>Success! The test credit card has been charged!</h1>";
echo "Transaction ID: " . $response->transaction_id;
} else {
echo $response->error_message;
}
}
if ($response->approved) {
echo "<h1>Success! The test credit card has been charged!</h1>";
echo "Transaction ID: " . $response->transaction_id;
} else {
echo $response->error_message;
}
}
Thats it in your browser now call this action: http://localhost/your_controller/testauth
And you should see success message if you use the same card details, change a bit and see if it says success or failure.
You can either add parameters to the function validate_card to send in the card details etc., Or send as an array or have public variables in the AuthorizeNet class and use them to set the values from your form. You can use any method to integrate this payment method.