Welcome Guest, Not a member yet? Register   Sign In
Problem Integrating AUTHORIZE.NET INTEGRATION WITH CODEIGNITER 2.1
#1

[eluser]Unknown[/eluser]
Hello every body I am stucked with this Authorize.net Payment Integration In Codeigniter 2.1, and your help to get me out of this will be great.

Basically I am integrating Authorize.net in CODEIGNITER 2.1, I have created a credit card present account of test.authorize.net Tested many libraries available on net but all in vain

Whatever I do always returns me an error like "Invalid Login API or Transaction key is invalid" OR "Error Processing Your Payment (TEST MODE) Trasactions of this market type cannot be processed on this system"

Here is the code I am using

My AUTHORIZE.NET LIBRARY FOR CODEIGNITER

Authorize_net.php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Authorize_net {

var $field_string;
var $fields = array();
var $response_string;
var $response = array();
var $debuginfo;
var $gateway_url = "https://secure.authorize.net/gateway/transact.dll";
function Authorize_net() {
$this->CI =& get_instance();
if($this->CI->config->item('authorize_net_test_mode') == 'TRUE') {
$this->gateway_url = $this->CI->config->item('authorize_net_test_api_host');
$this->add_x_field('x_test_request', $this->CI->config->item('authorize_net_test_mode'));
$this->add_x_field('x_login', $this->CI->config->item('authorize_net_test_x_login'));
$this->add_x_field('x_tran_key', $this->CI->config->item('authorize_net_test_x_tran_key'));
}else{
$this->gateway_url = $this->CI->config->item('authorize_net_live_api_host');
$this->add_x_field('x_test_request', $this->CI->config->item('authorize_net_test_mode'));
$this->add_x_field('x_login', $this->CI->config->item('authorize_net_live_x_login'));
$this->add_x_field('x_tran_key', $this->CI->config->item('authorize_net_live_x_tran_key'));
}
$this->add_x_field('x_version', $this->CI->config->item('authorize_net_x_version'));
$this->add_x_field('x_delim_data', $this->CI->config->item('authorize_net_x_delim_data'));
$this->add_x_field('x_delim_char', $this->CI->config->item('authorize_net_x_delim_char'));
$this->add_x_field('x_encap_char', $this->CI->config->item('authorize_net_x_encap_char'));
$this->add_x_field('x_url', $this->CI->config->item('authorize_net_x_url'));
$this->add_x_field('x_type', $this->CI->config->item('authorize_net_x_type'));
$this->add_x_field('x_method', $this->CI->config->item('authorize_net_x_method'));
$this->add_x_field('x_relay_response', $this->CI->config->item('authorize_net_x_relay_response'));
}
function add_x_field($field, $value) {
$this->fields[$field] = $value;
}

function process_payment() {
foreach( $this->fields as $key => $value ) {
$this->field_string .= "$key=" . urlencode( $value ) . "&";
}
$ch = curl_init($this->gateway_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $this->field_string, "& " ));
$this->response_string = urldecode(curl_exec($ch)Wink;

if (curl_errno($ch)) {
$this->response['Response_Reason_Text'] = curl_error($ch);
return 3;
}else{
curl_close ($ch);
}
$temp_values = explode($this->CI->config->item('authorize_net_x_delim_char'), $this->response_string);
$temp_keys= array (
"Response_Code", "Response_Subcode", "Response_Reason_Code", "Response_Reason_Text",
"Approval_Code", "AVS_Result_Code", "Transaction_ID", "Invoice_Number", "Description",
"Amount", "Method", "Transaction_Type", "Customer_ID", "Cardholder_First_Name",
"Cardholder Last_Name", "Company", "Billing_Address", "City", "State",
"Zip", "Country", "Phone", "Fax", "Email", "Ship_to_First_Name", "Ship_to_Last_Name",
"Ship_to_Company", "Ship_to_Address", "Ship_to_City", "Ship_to_State",
"Ship_to_Zip", "Ship_to_Country", "Tax_Amount", "Duty_Amount", "Freight_Amount",
"Tax_Exempt_Flag", "PO_Number", "MD5_Hash", "Card_Code_CVV_Response Code",
"Cardholder_Authentication_Verification_Value_CAVV_Response_Code"
);
for ($i=0; $i<=27; $i++) {
array_push($temp_keys, 'Reserved_Field '.$i);
}
$i=0;
while (sizeof($temp_keys) < sizeof($temp_values)) {
array_push($temp_keys, 'Merchant_Defined_Field '.$i);
$i++;
}
for ($i=0; $i<sizeof($temp_values);$i++) {
$this->response["$temp_keys[$i]"] = $temp_values[$i];
}
return $this->response['Response_Code'];
}

function get_response_reason_text() {
return $this->response['Response_Reason_Text'];
}
function get_all_response_codes() {
return $this->response;
}

function dump_fields() {
echo "<h3>authorizenet_class->dump_fields() Output:</h3>";
echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
<tr>
<td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
<td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
</tr>";

foreach ($this->fields as $key => $value) {
echo "<tr><td>$key</td><td>".urldecode($value)."&nbsp;</td></tr>";
}

echo "</table><br>";
}
function dump_response() {
$i = 0;
foreach ($this->response as $key => $value) {
$this->debuginfo .= "$key: $value\n";
$i++;
}
return $this->debuginfo;
}
}
CONFIG FILE CODE:


/*| Authorize.net Credentials and Info*/
$config['authorize_net_test_mode'] = 'TRUE'; // Set this to FALSE for live processing
$config['authorize_net_live_x_login'] = 'Live API';
$config['authorize_net_live_x_tran_key'] = 'Live Trans Key';
$config['authorize_net_live_api_host'] = 'https://secure.authorize.net/gateway/transact.dll';

$config['authorize_net_test_x_login'] = 'I Given Here My API KEY';
$config['authorize_net_test_x_tran_key'] = 'I Given Here Trans KEY';
$config['authorize_net_test_api_host'] = 'https://test.authorize.net/gateway/transact.dll';
// Lets setup some other values so we dont have to do it everytime
// we process a transaction
$config['authorize_net_x_version'] = '3.1';
$config['authorize_net_x_type'] = 'AUTH_CAPTURE';
$config['authorize_net_x_relay_response'] = 'FALSE';
$config['authorize_net_x_delim_data'] = 'TRUE';
$config['authorize_net_x_delim_ch
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

You did not mention what method you're calling when you get those errors, and you did not post the code you are using to interact with the library. This would save us from having to figure out what you're doing, and from having to study your undocumented library to figure out how to use it.

It also helps if you put your code in [code]code tags[/code] and indent it.

However, I do have an optimisation for you that I just spotted. I suggest changing this:
Code:
if($this->CI->config->item(‘authorize_net_test_mode’) == ‘TRUE’) {
    $this->gateway_url = $this->CI->config->item(‘authorize_net_test_api_host’);
    $this->add_x_field(‘x_test_request’, $this->CI->config->item(‘authorize_net_test_mode’));
    $this->add_x_field(‘x_login’, $this->CI->config->item(‘authorize_net_test_x_login’));
    $this->add_x_field(‘x_tran_key’, $this->CI->config->item(‘authorize_net_test_x_tran_key’));
}else{
    $this->gateway_url = $this->CI->config->item(‘authorize_net_live_api_host’);
    $this->add_x_field(‘x_test_request’, $this->CI->config->item(‘authorize_net_test_mode’));
    $this->add_x_field(‘x_login’, $this->CI->config->item(‘authorize_net_live_x_login’));
    $this->add_x_field(‘x_tran_key’, $this->CI->config->item(‘authorize_net_live_x_tran_key’));
}

to this:
Code:
$this->gateway_url = ($this->CI->config->item(‘authorize_net_test_mode’) == ‘TRUE’)
    ? $this->CI->config->item(‘authorize_net_test_api_host’)
    : $this->CI->config->item(‘authorize_net_live_api_host’);

$this->add_x_field(‘x_test_request’, $this->CI->config->item(‘authorize_net_test_mode’));
$this->add_x_field(‘x_login’, $this->CI->config->item(‘authorize_net_live_x_login’));
$this->add_x_field(‘x_tran_key’, $this->CI->config->item(‘authorize_net_live_x_tran_key’));




Theme © iAndrew 2016 - Forum software by © MyBB