Adding the Authorize.net PHP SDK to CodeIgniter 2.0
This is a follow up post to my initial Adding the Authorize.net PHP SDK to CodeIgniter 1.7. Now that CI 2.0 is out the plugins are long gone.
So after a couple of minuted fiddling with this, I managed to get the Authorize.net API working as a library in CI
Here is what you need to do :
- Step 1 – You need to download the PHP SDK from Authorize.net, you can get it here
- Step 2 – Copy the AuthorizeNet.php file and the lib folder into your copy of CI’s application/libraries folder
- Step 3 – Rename the file AuthorizeNet.php to Authorizenet.php
- Step 4- Add this to code to Authorizenet.php
class Authorizenet extends AuthorizeNetAIM //AuthorizeNetAIM for using AIM replace with your preferred method
{
}
Now you only need to call your new library like so
$this->load->library('authorizenet');
And to use it
$this->authorizenet->setFields(
array(
'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' => 'some@email.com',
'card_code' => '782',
)
);
$this->authorizenet->authorizeAndCapture();
Of course don't forget to set your global variables that Authorize.net requires
You can see the included example in the SDK or the my previous post
April 13th, 2011 - 04:49
I came here to say that you needed to write a new post and lo and behold you had already done it! Good post, I’ve been playing with CI 2 a little and it makes some good improvements over 1.7. I like that the development cycle is faster, too.
April 13th, 2011 - 12:02
Yeah, this guy wanted to know how to do it on CI 2 so i took the time to do some research. Glad you dropped by.
November 5th, 2011 - 03:21
I will try it on Monday. Best solution for CI so far. Plain and simple.
Thanks Carlos
November 5th, 2011 - 14:39
My pleasure
December 7th, 2011 - 17:50
What if you need to use AuthorizeNetAIM *and* AuthorizeNetARB?
December 8th, 2011 - 14:21
you can create two classes
class Authorizenetaim extends AuthorizeNetAIM
{
}
class Authorizenetarb extends AuthorizeNetARB
{
}
Just remember to capitalize only the first letter of the new class name
and to load them
$this->load->library(‘authorizenetaim’);
$this->load->library(‘authorizenetarb’);
and to use them
$this->authorizenetaim->….
$this->authorizenetarb->….