Adding the PHP SDK to CodeIgniter 1.7

I am writing a site that requires credit card processing through I am building the site using the CodeIgniter framework. I was thinking I would have to do some fancy hacking or using a 3rd party library to make this work but it turns out that you can user the SDK provided by directly into CI. here is what you need to do.

  • Step 1 – You need to download the PHP SDK from, you can get it here
  • Step 2 – Copy the AuthorizeNet.php file and the lib folder into your copy of CI’s system/plugins folder
  • Step 3 – Rename the file AuthorizeNet.php to AuthorizeNet_pi.php

Believe it or not you are done! that’s it, no need to do anything else, now you can use the SDK as described in the examples.

Here is an example of a simple authorization and capture using test mode. I used some of the code from the example provided by here. The only difference from the example and this code is that I combined the code from the two config files ofthe example into one and replaced the

 require_once 'anet_php_sdk/AuthorizeNet.php';



Here is my Code:



// To use Direct Post Method, uncomment the line below and update the $site_root variable.
$site_root = "http://YOURDOMAIN/samples/your_store/";
define("AUTHORIZENET_MD5_SETTING",""); // Update this with your MD5 Setting.

$tax = number_format($price * .095,2); // Set tax
$amount = number_format($price + $tax,2); // Set total amount

die('Enter your merchant credentials in config.php before running the sample app.');

$transaction = new AuthorizeNetAIM;
'amount' => '10.00',
'card_num' => '6011000000000012',
'exp_date' => '04/17',
'first_name' => 'John',
'last_name' => 'Doe',
'address' => '123 Main Street',
'city' => 'Boston',
'state' => 'MA',
'country' => 'USA',
'zip' => '02142',
'email' => '',
'card_code' => '782',
$response = $transaction->authorizeAndCapture();
if ($response->approved) {
return "APPROVED";
} else {
return "DENIED";


  1. Hey, I guess you didn’t know it existed but if you look into Eppros, you’ll see an CodeIgniter class I wrote. It is basically a port of the code provided by, but it uses CodeIgniter conventions that mimic the standard libraries.

    Last time I talked to you, you were using Joomla. Why not for this project?

    I miss doing CodeIgniter apps…


    1. Hey, because it was too much of a custom site to try to figure it out in joomla.


    2. Also, The advantage of this is that you can use the API samples pretty much line by line. i will have to get your API, do you need a copy?


  2. Nah, I think I have a copy floating around somewhere. Thanks though.


  3. Carlos,

    How might you accomplish this in CI 2.x where plugins no longer exist? I have tried building the PHP SDK as a package in third_party, but, thus far, I’ve only been met with (rather unspecific) errors.


    1. I haven’t tried it yet but i will look it up you


    2. I might have a lead on this setting this up in a wrapper function and using it as a helper. I will get back to you when i test this


      1. Carlos,

        Much appreciated, I’ll await your next post.


        1. Not a problem Tom, glad I could help


  4. i am geting problem to impliment it. i m place lib folder into libraries folder and place file into libraies folder but i m geting error Fatal error: Class ‘AuthorizeNetAIM’ not found in /var/www/CodeIgniter/application/libraries/Authorizenet.php on line 4 plz help


    1. make sure AuthorizeNetAIM is included in Authorizenet.php


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.