cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Convert from AIM to CIM

I have this cart and it uses the AIM method. I need to use the CIM.  Searching through allthe files there is only one file called Authorize.net.php  Below is the code on this page.

 

<?php

class AuthorizeNet extends GatewayFramework implements GatewayModule {

	var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc");

	var $liveurl = 'https://secure.authorize.net/gateway/transact.dll';
	var $testurl = 'https://secure.authorize.net/gateway/transact.dll';

	function AuthorizeNet () {
		parent::__construct();
		$this->setup('login','password','testmode');
	}

	function actions () {
		add_action('mycart_process_order',array(&$this,'process'));
	}

	function process () {
		$transaction = $this->build();
		$Response = $this->send($transaction);
		if ($Response->code == '1') { // success
			$this->Order->transaction($this->txnid($Response),'CHARGED');
			return;
		} elseif ($Response->code == '4') { // flagged for merchant review or risk management
			$this->Order->transaction($this->txnid($Response),'PENDING');
			return;
		} else $this->error($Response);
	}

	function txnid ($Response) {
		if (empty($Response->transactionid)) return parent::txnid();
		return $Response->transactionid;
	}

	function error ($Response) {
		return new MycartError($Response->reason,'authorize_net_error',MYCART_TRXN_ERR,
			array('code'=>$Response->reasoncode));
	}

	function build () {
		$Order = $this->Order;
		$_ = array();

		// Options
		$_['x_test_request']		= ($this->settings['testmode'] == "on")?"TRUE":"FALSE"; // Set "TRUE" while testing
		$_['x_login'] 				= $this->settings['login'];
		$_['x_password'] 			= $this->settings['password'];
		$_['x_Delim_Data'] 			= "TRUE";
		$_['x_Delim_Char'] 			= ",";
		$_['x_Encap_Char'] 			= "";
		$_['x_version'] 			= "3.1";
		$_['x_relay_response']		= "FALSE";
		$_['x_type'] 				= "AUTH_ONLY";
		//= "AUTH_CAPTURE";
		$_['x_method']				= "CC";
		$_['x_email_customer']		= "FALSE";
		$_['x_merchant_email']		= $this->settings['merchant_email'];

		// Required Fields
		$_['x_amount']				= $Order->Cart->Totals->total;
		$_['x_customer_ip']			= $_SERVER["REMOTE_ADDR"];
		$_['x_fp_sequence']			= mktime();
		$_['x_fp_timestamp']		= time();
		// $_['x_fp_hash']				= hash_hmac("md5","{$_['x_login']}^{$_['x_fp_sequence']}^{$_['x_fp_timestamp']}^{$_['x_amount']}",$_['x_password']);

		// Customer Contact
		$_['x_first_name']			= $Order->Customer->firstname;
		$_['x_last_name']			= $Order->Customer->lastname;
		$_['x_email']				= $Order->Customer->email;
		$_['x_phone']				= $Order->Customer->phone;

		// Billing
		$_['x_card_num']			= $Order->Billing->card;
		$_['x_exp_date']			= date("my",$Order->Billing->cardexpires);
		$_['x_card_code']			= $Order->Billing->cvv;
		$_['x_address']				= $Order->Billing->address;
		$_['x_city']				= $Order->Billing->city;
		$_['x_state']				= $Order->Billing->state;
		$_['x_zip']					= $Order->Billing->postcode;
		$_['x_country']				= $Order->Billing->country;

		// Shipping
		$_['x_ship_to_first_name']  = $Order->Customer->firstname;
		$_['x_ship_to_last_name']	= $Order->Customer->lastname;
		$_['x_ship_to_address']		= $Order->Shipping->address;
		$_['x_ship_to_city']		= $Order->Shipping->city;
		$_['x_ship_to_state']		= $Order->Shipping->state;
		$_['x_ship_to_zip']			= $Order->Shipping->postcode;
		$_['x_ship_to_country']		= $Order->Shipping->country;

		// Transaction
		$_['x_freight']				= $Order->Cart->Totals->shipping;
		$_['x_tax']					= $Order->Cart->Totals->tax;

		// Line Items
		$i = 1;
		foreach($Order->Cart->contents as $Item) {
			$_['x_line_item'][] = ($i++)."<|>".substr($Item->name,0,31)."<|>".((sizeof($Item->options) > 1)?" (".substr($Item->option->label,0,253).")":"")."<|>".(int)$Item->quantity."<|>".number_format($Item->unitprice,$this->precision,'.','')."<|>".(($Item->tax)?"Y":"N");
		}

		return $this->encode($_);
	}

	function send ($data) {
		if ($this->settings['testmode'] == "on") $url = $this->testurl;
		else $url = $this->liveurl;
		$url = apply_filters('mycart_authorize_net_url',$url);
		return $this->response(parent::send($data,$url));
	}

	function response ($buffer) {
		$_ = new stdClass();

		list($_->code,
			 $_->subcode,
			 $_->reasoncode,
			 $_->reason,
			 $_->authcode,
			 $_->avs,
			 $_->transactionid,
			 $_->invoicenum,
			 $_->description,
			 $_->amount,
			 $_->method,
			 $_->type,
			 $_->customerid,
			 $_->firstname,
			 $_->lastname,
			 $_->company,
			 $_->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,
			 $_->duty,
			 $_->freight,
			 $_->taxexempt,
			 $_->ponum,
			 $_->md5hash,
			 $_->cvv2code,
			 $_->cvv2response) = explode(",",$buffer);
		return $_;
	}

	function settings () {
		$this->ui->cardmenu(0,array(
			'name' => 'cards',
			'selected' => $this->settings['cards']
		),$this->cards);

		$this->ui->text(1,array(
			'name' => 'login',
			'value' => $this->settings['login'],
			'size' => '16',
			'label' => __('Enter your AuthorizeNet Login ID.','Mycart')
		));

		$this->ui->password(1,array(
			'name' => 'password',
			'value' => $this->settings['password'],
			'size' => '24',
			'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart')
		));

		$this->ui->checkbox(1,array(
			'name' => 'testmode',
			'checked' => $this->settings['testmode'],
			'label' => __('Enable test mode','Mycart')
		));

	}

} // END class AuthorizeNet

?>


 I was thinking I need to add the XML part to this page. Somehow to have it parse the XML.


//build xml to post
$content =
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
	"<createCustomerProfileTransactionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
	//MerchantAuthenticationBlock().
	"<transaction>".
	"<profileTransAuthOnly>".
	"<amount>" . $_['x_amount'] . "</amount>". // should include tax, shipping, and everything.
	"<shipping>".
	"<amount></amount>".
	"<name>Free Shipping</name>".
	"<description>Free UPS Ground shipping. Ships in 5-10 days.</description>".
	"</shipping>".
	"<lineItems>". $_['x_amount'] ."</lineItems>".
	//"<unitPrice>" . ($_POST["amount"] - 1.00) . "</unitPrice>".
	"<customerProfileId>12711484</customerProfileId>".
	"<customerPaymentProfileId>11714901</customerPaymentProfileId>".
	"<customerShippingAddressId>11804938</customerShippingAddressId>".
	"<order>".
	"<invoiceNumber>INV12345</invoiceNumber>".
	"</order>".
	"</profileTransAuthOnly>".
	"</transaction>".
	"</createCustomerProfileTransactionRequest>";

echo "Raw request: " . htmlspecialchars($content) . "<br><br>";
$response = send_xml_request($content);
echo "Raw response: " . htmlspecialchars($response) . "<br><br>";
$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
	echo "A transaction was successfully created for customerProfileId <b>"
		. htmlspecialchars($_POST["customerProfileId"])
		. "</b>.<br><br>";
}
if (isset($parsedresponse->directResponse)) {
	echo "direct response: <br>"
		. htmlspecialchars($parsedresponse->directResponse)
		. "<br><br>";
		
	$directResponseFields = explode(",", $parsedresponse->directResponse);
	$responseCode = $directResponseFields[0]; // 1 = Approved 2 = Declined 3 = Error
	$responseReasonCode = $directResponseFields[2]; // See http://www.authorize.net/support/AIM_guide.pdf
	$responseReasonText = $directResponseFields[3];
	$approvalCode = $directResponseFields[4]; // Authorization code
	$transId = $directResponseFields[6];
	
	if ("1" == $responseCode) echo "The transaction was successful.<br>";
	else if ("2" == $responseCode) echo "The transaction was declined.<br>";
	else echo "The transaction resulted in an error.<br>";
	
	echo "responseReasonCode = " . htmlspecialchars($responseReasonCode) . "<br>";
	echo "responseReasonText = " . htmlspecialchars($responseReasonText) . "<br>";
	echo "approvalCode = " . htmlspecialchars($approvalCode) . "<br>";
	echo "transId = " . htmlspecialchars($transId) . "<br>";
}

echo "<br><a href=index.php?customerProfileId=" 
	. urlencode($_POST["customerProfileId"])
	. "&customerPaymentProfileId="
	. urlencode($_POST["customerPaymentProfileId"])
	. "&customerShippingAddressId="
	. urlencode($_POST["customerShippingAddressId"])
	. ">Continue</a><br>";

 

mallen
Regular Contributor
58 REPLIES 58

Yes I have seen that and tried it. But can't incorporate it to my situation. This is the code they give but I can't find a way to send that:

include_once ("../anet_php_sdk/AuthorizeNet.php");
include_once ("vars.php");
include_once ("util.php");

echo "create profile...<br><br>";

//build xml to post
$content =
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
	"<createCustomerProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
	MerchantAuthenticationBlock().
	"<profile>".
	"<merchantCustomerId>12346</merchantCustomerId>". // Your own identifier for the customer.
	"<description></description>".
	"<email>" . $_POST["email"] . "</email>".
	"</profile>".
	"</createCustomerProfileRequest>";

echo "Raw request: " . htmlspecialchars($content) . "<br><br>";
$response = send_xml_request($content);
echo "Raw response: " . htmlspecialchars($response) . "<br><br>";
$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
	echo "customerProfileId <b>"
		. htmlspecialchars($parsedresponse->customerProfileId)
		. "</b> was successfully created.<br><br>";
}

echo "<br><a href=index.php?customerProfileId="
	. urlencode($parsedresponse->customerProfileId)
	. ">Continue</a><br>";
?>

 

mallen
Regular Contributor

why did you add, this is the sample code and that is for the SDKs

include_once ("../anet_php_sdk/AuthorizeNet.php");

 

did you read the readme.txt?

 

it is using

$response = send_xml_request($content);

which is in util.php

Yes I have read the readme file and all the documentation many times.  I have no trouble using the sample code by itself. One page send data to a page that processes it. Simple.  But my current store uses this page that had AIM procedure on it. I am trying to replace that. The function Build() fires off thelogic to send the AIM data.

 

I can't find a way to send the XML data.

 

( I included anet_php_sdk/AuthorizeNet.php) becuase I was just including everything until I got it to work.

mallen
Regular Contributor

Just to summarize what I had before using AIM I need to change out the contnet in the function called Build() to use CIM. Again sorry the code does not format well in this window.

<?php


class AuthorizeNet extends GatewayFramework implements GatewayModule {

	var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc");

	var $liveurl = 'https://secure.authorize.net/gateway/transact.dll';
	var $testurl = 'https://secure.authorize.net/gateway/transact.dll';

	function AuthorizeNet () {
		parent::__construct();
		$this->setup('login','password','testmode');
	}

	function actions () {
		add_action('mycart_process_order',array(&$this,'process'));
	}

	function process () {
		$transaction = $this->build();
		$Response = $this->send($transaction);
		if ($Response->code == '1') { // success
			$this->Order->transaction($this->txnid($Response),'CHARGED');
			return;
		} elseif ($Response->code == '4') { // flagged for merchant review or risk management
			$this->Order->transaction($this->txnid($Response),'PENDING');
			return;
		} else $this->error($Response);
	}

	function txnid ($Response) {
		if (empty($Response->transactionid)) return parent::txnid();
		return $Response->transactionid;
	}

	function error ($Response) {
		return new MycartError($Response->reason,'authorize_net_error',MYCART_TRXN_ERR,
			array('code'=>$Response->reasoncode));
	}

	function build () {
		$Order = $this->Order;
		$_ = array();

		// Options
		$_['x_test_request']		= ($this->settings['testmode'] == "on")?"TRUE":"FALSE"; // Set "TRUE" while testing
		$_['x_login'] 				= $this->settings['login'];
		$_['x_password'] 			= $this->settings['password'];
		$_['x_Delim_Data'] 			= "TRUE";
		$_['x_Delim_Char'] 			= ",";
		$_['x_Encap_Char'] 			= "";
		$_['x_version'] 			        = "3.1";
		$_['x_relay_response']		        = "FALSE";
		$_['x_type'] 				= "AUTH_ONLY";
		//= "AUTH_CAPTURE";
		$_['x_method']				= "CC";
		$_['x_email_customer']		= "FALSE";
		$_['x_merchant_email']		= $this->settings['merchant_email'];

		// Required Fields
		$_['x_amount']				= $Order->Cart->Totals->total;
		$_['x_customer_ip']			= $_SERVER["REMOTE_ADDR"];
		$_['x_fp_sequence']			= mktime();
		$_['x_fp_timestamp']		        = time();
		// $_['x_fp_hash']				= hash_hmac("md5","{$_['x_login']}^{$_['x_fp_sequence']}^{$_['x_fp_timestamp']}^{$_['x_amount']}",$_['x_password']);

		// Customer Contact
		$_['x_first_name']			= $Order->Customer->firstname;
		$_['x_last_name']			= $Order->Customer->lastname;
		$_['x_email']				= $Order->Customer->email;
		$_['x_phone']				= $Order->Customer->phone;

		// Billing
		$_['x_card_num']			= $Order->Billing->card;
		$_['x_exp_date']			        = date("my",$Order->Billing->cardexpires);
		$_['x_card_code']			= $Order->Billing->cvv;
		$_['x_address']				= $Order->Billing->address;
		$_['x_city']				        = $Order->Billing->city;
		$_['x_state']				= $Order->Billing->state;
		$_['x_zip']					= $Order->Billing->postcode;
		$_['x_country']				= $Order->Billing->country;

		// Shipping
		$_['x_ship_to_first_name']  = $Order->Customer->firstname;
		$_['x_ship_to_last_name']	= $Order->Customer->lastname;
		$_['x_ship_to_address']	= $Order->Shipping->address;
		$_['x_ship_to_city']		= $Order->Shipping->city;
		$_['x_ship_to_state']		= $Order->Shipping->state;
		$_['x_ship_to_zip']		= $Order->Shipping->postcode;
		$_['x_ship_to_country']	= $Order->Shipping->country;

		// Transaction
		$_['x_freight']				= $Order->Cart->Totals->shipping;
		$_['x_tax']					= $Order->Cart->Totals->tax;

		// Line Items
		$i = 1;
		foreach($Order->Cart->contents as $Item) {
			$_['x_line_item'][] = ($i++)."<|>".substr($Item->name,0,31)."<|>".((sizeof($Item->options) > 1)?" (".substr($Item->option->label,0,253).")":"")."<|>".(int)$Item->quantity."<|>".number_format($Item->unitprice,$this->precision,'.','')."<|>".(($Item->tax)?"Y":"N");
		}

		return $this->encode($_);
	}

	function send ($data) {
		if ($this->settings['testmode'] == "on") $url = $this->testurl;
		else $url = $this->liveurl;
		$url = apply_filters('mycart_authorize_net_url',$url);
		return $this->response(parent::send($data,$url));
	}

	function response ($buffer) {
		$_ = new stdClass();

		list($_->code,
			 $_->subcode,
			 $_->reasoncode,
			 $_->reason,
			 $_->authcode,
			 $_->avs,
			 $_->transactionid,
			 $_->invoicenum,
			 $_->description,
			 $_->amount,
			 $_->method,
			 $_->type,
			 $_->customerid,
			 $_->firstname,
			 $_->lastname,
			 $_->company,
			 $_->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,
			 $_->duty,
			 $_->freight,
			 $_->taxexempt,
			 $_->ponum,
			 $_->md5hash,
			 $_->cvv2code,
			 $_->cvv2response) = explode(",",$buffer);
		return $_;
	}

	function settings () {
		$this->ui->cardmenu(0,array(
			'name' => 'cards',
			'selected' => $this->settings['cards']
		),$this->cards);

		$this->ui->text(1,array(
			'name' => 'login',
			'value' => $this->settings['login'],
			'size' => '16',
			'label' => __('Enter your AuthorizeNet Login ID.','Mycart')
		));

		$this->ui->password(1,array(
			'name' => 'password',
			'value' => $this->settings['password'],
			'size' => '24',
			'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart')
		));

		$this->ui->checkbox(1,array(
			'name' => 'testmode',
			'checked' => $this->settings['testmode'],
			'label' => __('Enable test mode','Mycart')
		));

	}

} // END class AuthorizeNet

?>

 

mallen
Regular Contributor

so don't use the build() and add the CIM code.

Right but the process ()  function triggers the build () fuction.  I don't see how it will send the XML. The CIM code never runs.

mallen
Regular Contributor

It doesn't now, not until you add the code to call the CIM function.

Thanks RaynorC1emen7.  Hopefully with your expertise I can get this working. You seem to know your stuff. This is what I have now. I entered all my CIM code in the build() function.  I get this error:
(TESTMODE) The merchant login ID or password is invalid or the account is inactive.

 

include_once ("XML/util.php"); 
include_once ("XML/vars.php"); 

class AuthorizeNet extends GatewayFramework implements GatewayModule {

	var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc");

	//var $liveurl = 'https://secure.authorize.net/gateway/transact.dll';
	//var $testurl = 'https://secure.authorize.net/gateway/transact.dll';
	//worksvar $testurl = 'https://test.authorize.net/gateway/transact.dll';
	
	//var $testurl = 'https://apitest.authorize.net/xml/v1/request.api';
	//var $liveurl = 'https://test.authorize.net/xml/v1/request.api';
	var $testurl = 'https://apitest.authorize.net/xml/v1/request.api';
	function AuthorizeNet () {
		parent::__construct();
		$this->setup('login','password','testmode');
	}

	function actions () {
		add_action('mycart_process_order',array(&$this,'process'));
		add_action('mycart_process_order','runxml');
	}

function process () {
	
		$transaction = $this->build();
		
	$Response = $this->send($transaction);
		if ($Response->code == '1') { // success
		$this->Order->transaction($this->txnid($Response),'CHARGED');
			//return;
		} elseif ($Response->code == '4') { // flagged for merchant review or risk management
		$this->Order->transaction($this->txnid($Response),'PENDING');
			//return;
		} else $this->error($Response); 

	}


	function txnid ($Response) {
		if (empty($Response->transactionid)) return parent::txnid();
		return $Response->transactionid;
	}

	function error ($Response) {
		return new MycartError($Response->reason,'authorize_net_error',MYCART_TRXN_ERR,
			array('code'=>$Response->reasoncode));
	}

	function build () {
		
		//create Auth & Capture Transaction
		$request = new AuthorizeNetCIM;
		$customerProfile = new AuthorizeNetCustomer;
		$customerProfile->description = "Description of customer here";
		$customerProfile->merchantCustomerId = 987;
        //create and add payment profiles and addresses

		// add payment profile.
		$paymentProfile = new AuthorizeNetPaymentProfile;
		$paymentProfile->customerType = "individual";
		$paymentProfile->payment->creditCard->cardNumber = $Mycart->Order->Billing->card;
		$paymentProfile->payment->creditCard->expirationDate = date("my",$Mycart->Order->Billing->cardexpires);
		$paymentProfile->payment->creditCard->cardCode  = $Mycart->Order->Billing->cvv;
		$customerProfile->paymentProfiles[] = $paymentProfile;
		$customerProfile->email = $Order->Customer->email;
		
		//add a shipping address
		$address = new AuthorizeNetAddress;
		$address->firstName = $Mycart->Order->Customer->firstname;
		$address->lastName = $Mycart->Order->Customer->lasttname;
		$address->company = "John Doe Company";
		$address->address = $Mycart->Order->Shipping->address;
		$address->city = $Mycart->Order->Shipping->city;
		$address->state = $Mycart->Order->Shipping->state;
		$address->zip = $Mycart->Order->Shipping->postcode;
		$address->country = $Mycart->Order->Shipping->country;
		$address->phoneNumber = $Mycart->Order->Customer->phone;
		$response = $request->createCustomerShippingAddress($customerProfileId, $address);
		$customerAddressId = $response->getCustomerAddressId();

		//create the transaction
		$transaction = new AuthorizeNetTransaction;
		$transaction->customerProfileId = $customerProfileId;
		$transaction->customerPaymentProfileId = $paymentProfileId;
		$transaction->customerShippingAddressId = $customerAddressId;   
		$transaction->amount = $Order->Cart->Totals->total;
		//$lineItem = new AuthorizeNetLineItem;
		$transaction->lineItems[] = $lineItem;  
    
		$response = $request->createCustomerProfileTransaction("AuthCapture", $transaction);
		$transactionResponse = $response->getTransactionResponse();
		$transactionId = $transactionResponse->transaction_id;
		
		// Line Items
		$i = 1;
		foreach($Order->Cart->contents as $Item) {
		$transaction->lineItems[] = ($i++)."<|>".substr($Item->name,0,31)."<|>".((sizeof($Item->options) > 1)?" (".substr($Item->option->label,0,253).")":"")."<|>".(int)$Item->quantity."<|>".number_format($Item->unitprice,$this->precision,'.','')."<|>".(($Item->tax)?"Y":"N");
		
		}

//build xml to post
function runxml() {
	 //header('Location: https://apitest.authorize.net/xml/v1/request.api');
//$request = new AuthorizeNetCIM;
		//$customerProfile = new AuthorizeNetCustomer;
		//$customerProfile->description = "Description of customer here";
		//$customerProfile->merchantCustomerId = 987;
        //create and add payment profiles and addresses	
$content =
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
	"<createCustomerPaymentProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
	MerchantAuthenticationBlock().
		"<profile>".
	"<merchantCustomerId>9999</merchantCustomerId>". // Your own identifier for the customer.
	"<description>none</description>".
	"<email></email>".
	"</profile>".
	"</createCustomerProfileRequest>";

echo "Raw request: " . htmlspecialchars($content) . "<br><br>";
$response = send_xml_request($content);
echo "Raw response: " . htmlspecialchars($response) . "<br><br>";
$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
	echo "A transaction was successfully created for customerProfileId <b>"
		. htmlspecialchars($_POST["customerProfileId"])
		. "</b>.<br><br>";
}
if (isset($parsedresponse->directResponse)) {
	echo "direct response: <br>"
		. htmlspecialchars($parsedresponse->directResponse)
		. "<br><br>";
		
	$directResponseFields = explode(",", $parsedresponse->directResponse);
	$responseCode = $directResponseFields[0]; // 1 = Approved 2 = Declined 3 = Error
	$responseReasonCode = $directResponseFields[2]; // See http://www.authorize.net/support/AIM_guide.pdf
	$responseReasonText = $directResponseFields[3];
	$approvalCode = $directResponseFields[4]; // Authorization code
	$transId = $directResponseFields[6];
	
	if ("1" == $responseCode) echo "The transaction was successful.<br>";
	else if ("2" == $responseCode) echo "The transaction was declined.<br>";
	else echo "The transaction resulted in an error.<br>";
	
	echo "responseReasonCode = " . htmlspecialchars($responseReasonCode) . "<br>";
	echo "responseReasonText = " . htmlspecialchars($responseReasonText) . "<br>";
	echo "approvalCode = " . htmlspecialchars($approvalCode) . "<br>";
	echo "transId = " . htmlspecialchars($transId) . "<br>";
}

echo "<br><a href=index.php?customerProfileId=" 
	. urlencode($_POST["customerProfileId"])
	. "&customerPaymentProfileId="
	. urlencode($_POST["customerPaymentProfileId"])
	. "&customerShippingAddressId="
	. urlencode($_POST["customerShippingAddressId"])
	. ">Continue</a><br>";

}

	}

	function send ($data) {
		if ($this->settings['testmode'] == "off") $url = $this->testurl;
		else $url = $this->liveurl;
		$url = apply_filters('mycart_authorize_net_url',$url);
		return $this->response(parent::send($data,$url));
		
}

function response ($buffer) {
		$_ = new stdClass();

		list($_->code,
			 $_->subcode,
			 $_->reasoncode,
			 $_->reason,
			 $_->authcode,
			 $_->avs,
			 $_->transactionid,
			 $_->invoicenum,
			 $_->description,
			 $_->amount,
			 $_->method,
			 $_->type,
			 $_->customerid,
			 $_->firstname,
			 $_->lastname,
			 $_->company,
			 $_->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,
			 $_->duty,
			 $_->freight,
			 $_->taxexempt,
			 $_->ponum,
			 $_->md5hash,
			 $_->cvv2code,
			 $_->cvv2response) = explode(",",$buffer);
		return $_;
	}


	function settings () {
		$this->ui->cardmenu(0,array(
			'name' => 'cards',
			'selected' => $this->settings['cards']
		),$this->cards);

		$this->ui->text(1,array(
			'name' => 'login',
			'value' => $this->settings['login'],
			'size' => '16',
			'label' => __('Enter your AuthorizeNet Login ID.','Mycart')
		));

		$this->ui->password(1,array(
			'name' => 'password',
			'value' => $this->settings['password'],
			'size' => '24',
			'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart')
		));

		$this->ui->checkbox(1,array(
			'name' => 'testmode',
			'checked' => $this->settings['testmode'],
			'label' => __('Enable test mode','Mycart')
		));

	}



} // END class AuthorizeNet

 

mallen
Regular Contributor

did you put your loginID, transactionKey in vars.php?

 

Sorry this is the corrected version. Still same error. Yes I have my login ID and transaction key in vars.

 

include_once ("XML/util.php"); 
include_once ("XML/vars.php"); 

class AuthorizeNet extends GatewayFramework implements GatewayModule {

	var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc");

	//var $liveurl = 'https://secure.authorize.net/gateway/transact.dll';
	//var $testurl = 'https://secure.authorize.net/gateway/transact.dll';
	//worksvar $testurl = 'https://test.authorize.net/gateway/transact.dll';
	
	//var $testurl = 'https://apitest.authorize.net/xml/v1/request.api';
	var $liveurl = 'https://test.authorize.net/xml/v1/request.api';
	var $testurl = 'https://apitest.authorize.net/xml/v1/request.api';
	function AuthorizeNet () {
		parent::__construct();
		$this->setup('login','password','testmode');
	}

	function actions () {
		add_action('mycart_process_order',array(&$this,'process'));
		add_action('mycart_process_order','runxml');
	}

function process () {
	
		$transaction = $this->build();
		
	$Response = $this->send($transaction);
		if ($Response->code == '1') { // success
		$this->Order->transaction($this->txnid($Response),'CHARGED');
			//return;
		} elseif ($Response->code == '4') { // flagged for merchant review or risk management
		$this->Order->transaction($this->txnid($Response),'PENDING');
			//return;
		} else $this->error($Response); 

	}


	function txnid ($Response) {
		if (empty($Response->transactionid)) return parent::txnid();
		return $Response->transactionid;
	}

	function error ($Response) {
		return new MycartError($Response->reason,'authorize_net_error',MYCART_TRXN_ERR,
			array('code'=>$Response->reasoncode));
	}

	function build () {
		($this->settings['testmode'] == "off")?"TRUE":"FALSE"; // Set "TRUE" while testing
		
		//create Auth & Capture Transaction
		$request = new AuthorizeNetCIM;
		$customerProfile = new AuthorizeNetCustomer;
		$customerProfile->description = "Description of customer here";
		$customerProfile->merchantCustomerId = 987;
        //create and add payment profiles and addresses

		// add payment profile.
		$paymentProfile = new AuthorizeNetPaymentProfile;
		$paymentProfile->customerType = "individual";
		$paymentProfile->payment->creditCard->cardNumber = $Mycart->Order->Billing->card;
		$paymentProfile->payment->creditCard->expirationDate = date("my",$Mycart->Order->Billing->cardexpires);
		$paymentProfile->payment->creditCard->cardCode  = $Mycart->Order->Billing->cvv;
		$customerProfile->paymentProfiles[] = $paymentProfile;
		$customerProfile->email = $Order->Customer->email;
		
		//add a shipping address
		$address = new AuthorizeNetAddress;
		$address->firstName = $Mycart->Order->Customer->firstname;
		$address->lastName = $Mycart->Order->Customer->lasttname;
		$address->company = "John Doe Company";
		$address->address = $Mycart->Order->Shipping->address;
		$address->city = $Mycart->Order->Shipping->city;
		$address->state = $Mycart->Order->Shipping->state;
		$address->zip = $Mycart->Order->Shipping->postcode;
		$address->country = $Mycart->Order->Shipping->country;
		$address->phoneNumber = $Mycart->Order->Customer->phone;
		$response = $request->createCustomerShippingAddress($customerProfileId, $address);
		$customerAddressId = $response->getCustomerAddressId();

		//create the transaction
		$transaction = new AuthorizeNetTransaction;
		$transaction->customerProfileId = $customerProfileId;
		$transaction->customerPaymentProfileId = $paymentProfileId;
		$transaction->customerShippingAddressId = $customerAddressId;   
		$transaction->amount = $Order->Cart->Totals->total;
		//$lineItem = new AuthorizeNetLineItem;
		$transaction->lineItems[] = $lineItem;  
    
		$response = $request->createCustomerProfileTransaction("AuthCapture", $transaction);
		$transactionResponse = $response->getTransactionResponse();
		$transactionId = $transactionResponse->transaction_id;
		
		// Line Items
		$i = 1;
		foreach($Order->Cart->contents as $Item) {
		$transaction->lineItems[] = ($i++)."<|>".substr($Item->name,0,31)."<|>".((sizeof($Item->options) > 1)?" (".substr($Item->option->label,0,253).")":"")."<|>".(int)$Item->quantity."<|>".number_format($Item->unitprice,$this->precision,'.','')."<|>".(($Item->tax)?"Y":"N");
		
		
	//build xml to post

	 //header('Location: https://apitest.authorize.net/xml/v1/request.api');
//$request = new AuthorizeNetCIM;
		//$customerProfile = new AuthorizeNetCustomer;
		//$customerProfile->description = "Description of customer here";
		//$customerProfile->merchantCustomerId = 987;
        //create and add payment profiles and addresses	
$content =
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
	"<createCustomerPaymentProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
	MerchantAuthenticationBlock().
		"<profile>".
	"<merchantCustomerId>9999</merchantCustomerId>". // Your own identifier for the customer.
	"<description>none</description>".
	"<email></email>".
	"</profile>".
	"</createCustomerProfileRequest>";

echo "Raw request: " . htmlspecialchars($content) . "<br><br>";
$response = send_xml_request($content);
echo "Raw response: " . htmlspecialchars($response) . "<br><br>";
$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
	echo "A transaction was successfully created for customerProfileId <b>"
		. htmlspecialchars($_POST["customerProfileId"])
		. "</b>.<br><br>";
}
if (isset($parsedresponse->directResponse)) {
	echo "direct response: <br>"
		. htmlspecialchars($parsedresponse->directResponse)
		. "<br><br>";
		
	$directResponseFields = explode(",", $parsedresponse->directResponse);
	$responseCode = $directResponseFields[0]; // 1 = Approved 2 = Declined 3 = Error
	$responseReasonCode = $directResponseFields[2]; // See http://www.authorize.net/support/AIM_guide.pdf
	$responseReasonText = $directResponseFields[3];
	$approvalCode = $directResponseFields[4]; // Authorization code
	$transId = $directResponseFields[6];
	
	if ("1" == $responseCode) echo "The transaction was successful.<br>";
	else if ("2" == $responseCode) echo "The transaction was declined.<br>";
	else echo "The transaction resulted in an error.<br>";
	
	echo "responseReasonCode = " . htmlspecialchars($responseReasonCode) . "<br>";
	echo "responseReasonText = " . htmlspecialchars($responseReasonText) . "<br>";
	echo "approvalCode = " . htmlspecialchars($approvalCode) . "<br>";
	echo "transId = " . htmlspecialchars($transId) . "<br>";
}

echo "<br><a href=index.php?customerProfileId=" 
	. urlencode($_POST["customerProfileId"])
	. "&customerPaymentProfileId="
	. urlencode($_POST["customerPaymentProfileId"])
	. "&customerShippingAddressId="
	. urlencode($_POST["customerShippingAddressId"])
	. ">Continue</a><br>";


	}	
		
		
		
		
		
		}



	function send ($data) {
		if ($this->settings['testmode'] == "off") $url = $this->testurl;
		else $url = $this->liveurl;
		$url = apply_filters('mycart_authorize_net_url',$url);
		return $this->response(parent::send($data,$url));
		
}

function response ($buffer) {
		$_ = new stdClass();

		list($_->code,
			 $_->subcode,
			 $_->reasoncode,
			 $_->reason,
			 $_->authcode,
			 $_->avs,
			 $_->transactionid,
			 $_->invoicenum,
			 $_->description,
			 $_->amount,
			 $_->method,
			 $_->type,
			 $_->customerid,
			 $_->firstname,
			 $_->lastname,
			 $_->company,
			 $_->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,
			 $_->duty,
			 $_->freight,
			 $_->taxexempt,
			 $_->ponum,
			 $_->md5hash,
			 $_->cvv2code,
			 $_->cvv2response) = explode(",",$buffer);
		return $_;
	}


	function settings () {
		$this->ui->cardmenu(0,array(
			'name' => 'cards',
			'selected' => $this->settings['cards']
		),$this->cards);

		$this->ui->text(1,array(
			'name' => 'login',
			'value' => $this->settings['login'],
			'size' => '16',
			'label' => __('Enter your AuthorizeNet Login ID.','Mycart')
		));

		$this->ui->password(1,array(
			'name' => 'password',
			'value' => $this->settings['password'],
			'size' => '24',
			'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart')
		));

		$this->ui->checkbox(1,array(
			'name' => 'testmode',
			'checked' => $this->settings['testmode'],
			'label' => __('Enable test mode','Mycart')
		));

	}



} // END class AuthorizeNet

 

mallen
Regular Contributor