How can We Integrate the Authorize.Net Payment Gateway in Codeigniter?
Authorize.Net is my favorite payment mode for using in web development. It is simple, easy and secure payment connection. I use authorize.Net in my codeigniter based projects and here is the code and downloads.
This is helper for payment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | function do_payment ($post_values) { $post_url = "https://test.authorize.net/gateway/transact.dll"; // This section takes the input fields and converts them to the proper format $post_string = ""; foreach( $post_values as $key => $value ) { $post_string .= "$key=" . urlencode( $value ) . "&"; } $post_string = rtrim( $post_string, "& " ); // This sample code uses the CURL library for php to establish a connection, // submit the post, and record the response. // If you receive an error, you may want to ensure that you have the curl // library enabled in your php configuration $request = curl_init($post_url); // initiate curl object curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. $post_response = curl_exec($request); // execute curl post and store results in $post_response // additional options may be required depending upon your server configuration // you can find documentation on curl options at http://www.php.net/curl_setopt curl_close ($request); // close curl object // This line takes the response and breaks it into an array using the specified delimiting character $response_array = explode($post_values["x_delim_char"],$post_response); // The results are output to the screen in the form of an html numbered list. if($response_array) { return $response_array; } else { return ''; } } |
And here is your controller function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | function do_user_payment() { $this->load->library('auth_payment'); $card_expiration = $_POST['crMonth'].$_POST['crYear']; $x_login = "login_key"; $x_tran_key = "trans_key"; $card_number = $_POST['ccn']; $invoice_num = ''; $x_card_code = $_POST['CSV']; $post_values['x_invoice_num'] = $invoice_num; $post_values['x_login'] = $x_login; $post_values['x_tran_key'] = $x_tran_key; $post_values['x_card_code'] = $x_card_code; $post_values['x_version'] = "3.1"; $post_values['x_delim_data'] = "TRUE"; $post_values['x_delim_char'] = "|"; $post_values['x_relay_response'] = "FALSE"; $post_values['x_type'] = "AUTH_CAPTURE"; //Optional $post_values['x_method'] = "CC"; $post_values['x_card_num'] = $card_number; $post_values['x_exp_date'] = $card_expiration; $post_values['x_amount'] = 'Your Charges'; $post_values['x_first_name'] = $user_first_name; //Optional (From Client) $post_values['x_last_name'] = $user_last_name; //Optional (From Client) $post_values['x_address'] = $user_address1; //Optional (From Client) $post_values['x_state'] = $user_state; //Optional (From Client) $post_values['x_zip'] = $user_zip; //Optional (From Client) //Calling Payment function $paymentResponse = $this->auth_payment->do_payment($post_values); if($paymentResponse[0]==1 && $paymentResponse[1]==1 && $paymentResponse[2]==1) { // payment is successful. Do your action here } else { // payment failed. return $paymentResponse[3]; // return error } } |
Who I Am

Zeeshan Rasool
Software Engineer - PHP
Lahore - Pakistan
zeeshan(@)99points.info
Skype: zeeshan-rasool
gTalk: zishan.rasool85
Categories
- AJAX (37)
- Codeigniter (16)
- CSS (16)
- Facebook (11)
- Joomla (1)
- JQuery (53)
- Miscellaneous (4)
- Mootools (1)
- MySQL (6)
- PHP (60)
- SEO (2)
- Technology (6)
- Tutorials (15)
- Twitter (2)
- Web Design (23)
- Web Development (57)
- WordPress (2)
Tags
99points
adobe
AJAX
ajax pagination
ajax rating
ajax tutorial
ajax voting system
captcha
Codeigniter
codeigniter 2.0
codeigniter recaptcha
CSS
css tutorials
dreamweaver cs5
Facebook
facebox
farmville
ffmpeg
flv
google api
hacking
Joomla
JQuery
JQuery Gallery
JQuery menus
Jquery tutorial
mafia war
Mootools
MySQL
pagination
Payment
PHP
php curl
recaptcha
RSS Feed
SEO
simplepie
socail networking
ssl
Tutorials
Twitter
wall script
Web
XSS
youtube
Comments
- ZeeShaN on Facebook Wall Script Clone with JQuery and PHP: Personal Project BETA Version 2.0
- 20 + Fresh jQuery Image Gallery/Slider Plugins and Tutorials Worth a Look | free on JQuery Based Flipped Image Gallery with Bounce Effects
- 20 + Fresh jQuery Image Gallery/Slider Plugins and Tutorials Worth a Look | free on Fresh JQuery Image Gallery with Captions and Auto Play/Pause Rotation
- 25 Cool and Helpful jQuery Plugins/Tutorials For Your Next Project | free on jQuery Tutorial: Create jQuery and CSS based Awesome navigation.
- 25 Cool and Helpful jQuery Plugins/Tutorials For Your Next Project | free on Ajax Tutorial: How to Create Ajax Search Using PHP jQuery and MYSQL
ZeeShaN







Thanks. Very useful
[...] FLV using FFmpeg. Simple class to encrypt url data How to Create Ajax Pagination using CodeIgniter? How can We Integrate the Authorize.Net Payment Gateway in CodeIgniter? 30 Top CodeIgniter best Tutorials You must want to know. How To: Use Re-Captcha in CodeIgniter [...]
not suitable for implementation. looks incomplete.
Hi,
very nice tutorial. But please provide library code for “AUTH_PAYMENT”
$this->load->library(‘auth_payment’);
waiting for reply