\!/ KyuuKazami \!/

Path : /home/kohli/public_html/application/libraries/
Upload :
Current File : /home/kohli/public_html/application/libraries/authorize_net.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
|--------------------------------------------------------------------------
| Authorize.net Payment Module
|--------------------------------------------------------------------------
|
| Just add the following config to your application/config/config.php file
|
| $config['at_login']	= "xxxxxxxxxx"; //your login
| $config['at_password']	= "xxxxxxxxxxxx"; //your transaction key
| $config['at_test']	= 1; //Set to 0 for live transactions
| $config['at_debug']	= 1; //Set to 0 for live transactions
| $config['at_site'] = 'https://test.authorize.net/gateway/transact.dll'; //comment for live trans
| //$config['at_site'] = 'https://secure.authorize.net/gateway/transact.dll'; //uncomment for live trans
|
|	public function validate()
|	{
|			$this->load->library('Authorize_net');
|			
|			$param['card_num']		= '4222222222222';
|			$param['exp_date']		= '02/2020';
|			$param['desc']			= 'Some Product Here';
|			$param['amount']		= '0.01';
|			$param['first_name']	= 'Harpreet1';
|			$param['last_name']		= 'Singh';
|			$param['address']		= 'Vill. Laroi, Bhogpur.';
|			$param['city']			= 'Jalandhar';
|			$param['state']			= 'Punjab';
|			$param['zipcode']		= '144201';
|			$param['birth_month']	= '10';
|			$param['birth_day']		= '21';
|			$param['birth_year']	= '86';
|			$param['code']			= '000';
|			
|			$result = $this->Authorize_net->authorize($param);
|			
|			print_r(explode("|", $result));
|			
|			$result_arr = explode("|", $result);
|			
|			if(sizeof($result_arr) > 1)
|			{
|				$detail['response_code']	= $result_arr[0];// 1 = Approved, 2 = Declined, 3 = Error, 4 = Held for Review
|				$detail['description']		= $result_arr[3];// Description
|				$detail['trans_id']			= $result_arr[6];// Transaction ID
|				$detail['auth_code']		= $result_arr[4];// Authorization Code
|			}
|			else
|				echo 'Error: While recieving information from Authorized.net. Please check SSL enable option in library.';
|	} 
*/

class Authorize_net {

	public function Authorize($param)
	{
		$CI =& get_instance();

		$x_Login = $CI->config->item('at_login');     
		$x_Password = $CI->config->item('at_password');

		$DEBUGGING					= $CI->config->item('at_debug');
		$TESTING					= $CI->config->item('at_test');	
		$ERROR_RETRIES				= 2;

		$auth_net_url				= $CI->config->item('at_site');

		$authnet_values				= array
		(
			"x_login"				=> $x_Login,
			"x_version"				=> "3.1",
			"x_delim_char"			=> "|",
			"x_delim_data"			=> "TRUE",
			"x_type"				=> "AUTH_CAPTURE",
			"x_method"				=> "CC",
		 	"x_tran_key"			=> $x_Password,
		 	"x_relay_response"		=> "FALSE",
			"x_card_num"			=> $param['card_num'],
			"x_exp_date"			=> $param['exp_date'],
			"x_description"			=> $param['desc'],
			"x_amount"				=> $param['amount'],
			"x_first_name"			=> $param['first_name'],
			"x_last_name"			=> $param['last_name'],
			"x_address"				=> $param['address'],
			"x_city"				=> $param['city'],
			"x_state"				=> $param['state'],
			"x_country"				=> $param['country'],
			"x_zip"					=> $param['zipcode'],
			"x_invoice_num"			=> $param['order_id'],
			"x_cust_id"				=> $param['user_id'],
			"x_customer_ip"			=> $param['ip'],
			"CustomerBirthMonth"	=> $param['birth_month'],
			"CustomerBirthDay"		=> $param['birth_day'],
			"CustomerBirthYear"		=> $param['birth_year'],
			"SpecialCode"			=> $param['code'],
		);

		$fields = "";
		foreach( $authnet_values as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";

		$ch = curl_init($auth_net_url);
		
		curl_setopt($ch, CURLOPT_HEADER, 0); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " ));
		
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Comment this line for live transaction.
		
		$result = curl_exec($ch);
		
		curl_close ($ch);

		return $result;

	}
}
/* End of file Authorize_net.php */
/* Location: ./system/application/libraries/Authorize_net.php */
?>

@KyuuKazami