<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to get back transaction id in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24379#M13072</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;return array($this-&amp;gt;approval_code, $this-&amp;gt;transaction_id);&lt;/PRE&gt;&lt;P&gt;Then you'll have find the code that calls processCard() and look for the line(s) after that that reference the approval code. Add something to print the transaction ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you still need further work on this, I suggest hiring someone for a few dollars. We're here to support you in integrating Authorize.net, but this is getting into general PHP coding at this point.&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.authorize.net/solutions/merchantsolutions/merchantservices/certifieddeveloperdirectory/" target="_blank"&gt;http://www.authorize.net/solutions/merchantsolutions/merchantservices/certifieddeveloperdirectory/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Mar 2012 17:16:45 GMT</pubDate>
    <dc:creator>TJPride</dc:creator>
    <dc:date>2012-03-13T17:16:45Z</dc:date>
    <item>
      <title>how to get back transaction id</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24289#M13029</link>
      <description>&lt;P&gt;I had somebody implement a script for me, so I'm a little lost on how/where to set the code to give me back a transaction id for tracking or for the customer's to print for their records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a payment processing page that includes the below code. I seeat the top,var $trans_key = ''; and down lower, several options under "// response information". But I'm just not sure how to set these to give me that information to echo/use on the confirmation page.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;?php
/**
* CLASS AIM
*
*/
class AIM {
	// login credentials that Authorize.net uses for verification
	var $login_id = '';
	var $trans_key = '';

	// server
	var $server = '';
	
	// testing name stuff


	// credit card information
	var $cc_name = '';
	var $cc_number = '';
	var $cc_month = '';
	var $cc_year = '';
	var $cc_code = '';
	var $cc_type = '';

	// error stack array
	var $errorStack = array();

	// modes
	var $testMode = false;
	var $debugMode = false;
	var $errorRetries = 2;

	// buyer information
	var $buyer = array();

	// response information
	var $status = '';
	var $subcode = '';
	var $response_code = '';
	var $response_text = '';
	var $approval_code = '';
	var $md5hash = '';
	var $code = '';
	var $remaining = array();

	// constructor
	function AIM($login_id, $trans_key) {
		$this-&amp;gt;login_id = $login_id;
		$this-&amp;gt;trans_key = $trans_key;

		$this-&amp;gt;setTesting(0);
	}

	/** loads option array
	* @param	fName	string containing the first name
	* @param	lName	string containing the last name
	* @param	address	string containing the address
	* @param	city	string containing the city
	* @param	state	string containing the state
	* @param	zip		string containing the zipcode
	* @param	phone	string containing the phone number
	* @return	true
	*/
	function setBuyer ($fname, $lname, $address, $city, $state, $zip, $phone = "(000)000-0000") {
		$this-&amp;gt;buyer = array
			(
				"FirstName"	=&amp;gt; $fname,
				"LastName"	=&amp;gt; $lname,
				"Address"	=&amp;gt; $address,
				"City"		=&amp;gt; $city,
				"State"		=&amp;gt; $state,
				"Zip"		=&amp;gt; $zip,
				"Phone"		=&amp;gt; $phone
			);

		return true;
	}

	/** sets the card information variables
	* @param	cc_name		string containing the name on the credit card
	* @param	cc_number	string containing the credit card number
	* @param	cc_month	string containing the expiration month
	* @param	cc_year		string containing the expiration year
	* @param	cc_code		string containing the security code
	* @return	boolean
	*/
	function setCard ($cc_name, $cc_number, $cc_month, $cc_year, $cc_code) {
		$this-&amp;gt;cc_name = $cc_name;
		$this-&amp;gt;cc_number = ereg_replace("[^0-9]", "", $cc_number);
		$this-&amp;gt;cc_month = ereg_replace("[^0-9]", "", $cc_month);
		$this-&amp;gt;cc_year = ereg_replace("[^0-9]", "", $cc_year);
		$this-&amp;gt;cc_code = ereg_replace("[^0-9]", "", $cc_code);

		return $this-&amp;gt;verifyCard();
	}

	/** verifies correct format of card
	* @return	boolean
	*/
	function verifyCard () {
		// these can be combined. however, if card type is needed, split up works better
		if (ereg('^4[0-9]{12}([0-9]{3})?$', $this-&amp;gt;cc_number))
			$this-&amp;gt;cc_type = 'Visa';
		elseif (ereg('^5[1-5][0-9]{14}$', $this-&amp;gt;cc_number))
			$this-&amp;gt;cc_type = 'Master Card';
		elseif (ereg('^3[47][0-9]{13}$', $this-&amp;gt;cc_number))
			$this-&amp;gt;cc_type = 'American Express';
		elseif (ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $this-&amp;gt;cc_number))
			$this-&amp;gt;cc_type = 'Diners Club';
		elseif (ereg('^6011[0-9]{12}$', $this-&amp;gt;cc_number))
			$this-&amp;gt;cc_type = 'Discover';
		elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this-&amp;gt;cc_number))
			$this-&amp;gt;cc_type = 'JCB';
		else{
			$this-&amp;gt;errorStack[] = "Invalid card number.";
			return false;
		}

		// if the year is before the current
		if ($this-&amp;gt;cc_year &amp;lt; date ("Y")) {
			$this-&amp;gt;errorStack[] = "Invalid card expiration date (card has expired).";
			return false;
		}

		// if the year is the current, and the month is less than the current
		if ($this-&amp;gt;cc_year == date ("Y") &amp;amp;&amp;amp; $this-&amp;gt;cc_month &amp;lt; date ("m")) {
			$this-&amp;gt;errorStack[] = "Invalid card expiration date (card has expired).";
			return false;
		}	

		// who has a name less than 5 characters?
		if (strlen($this-&amp;gt;cc_name) &amp;lt; 5) {
			$this-&amp;gt;errorStack[] = "The name on the credit card appears invalid.";
			return false;
		}

		// make sure the security is atleast 3 characters long and larger than 000
		if (strlen($this-&amp;gt;cc_code) &amp;lt; 3 || $this-&amp;gt;cc_code &amp;lt; 1) {
			$this-&amp;gt;errorStack[] = "Invalid security code.";
			return false;
		}

		return true;
	}

	/** set testing mode
	* @param	test	int/boolean containing testing setting
	* @return	true
	*/
	function setTesting ($test) {
		if ($test == 1 || $test == true) {
			$this-&amp;gt;testMode = true;
			$this-&amp;gt;server = "&lt;A href="https://certification.authorize.net/gateway/transact.dll" target="_blank"&gt;https://certification.authorize.net/gateway/transact.dll&lt;/A&gt;";
		}else{
			$this-&amp;gt;testMode = false;
			$this-&amp;gt;server = "&lt;A href="https://secure.authorize.net/gateway/transact.dll" target="_blank"&gt;https://secure.authorize.net/gateway/transact.dll&lt;/A&gt;";
		}

		return true;
	}

	/** process the card
	* @param	item	string containing a description of the item being sold
	* @param	amount	float containing the amount to be charge
	* @return	boolean
	*/
	function processCard ($item, $amount) {
		// run the regular expression to verify card format
		if (!$this-&amp;gt;verifyCard()) {
			$this-&amp;gt;errorStack[] = "Invalid card.";
			return false;
		}

		// populate the array of items to send to authorize.net
		$values					= array
		(
			"x_login"			=&amp;gt; $this-&amp;gt;login_id,
			"x_tran_key"		=&amp;gt; $this-&amp;gt;trans_key,
			"x_version"			=&amp;gt; "3.1",
			"x_delim_char"		=&amp;gt; "|",
			"x_delim_data"		=&amp;gt; "TRUE",
			"x_url"				=&amp;gt; "FALSE",
			"x_type"			=&amp;gt; "AUTH_CAPTURE",
			"x_method"			=&amp;gt; "CC",
			"x_relay_response"	=&amp;gt; "TRUE",
			"x_card_num"		=&amp;gt; $this-&amp;gt;cc_number,
			"x_exp_date"		=&amp;gt; $this-&amp;gt;cc_month . $this-&amp;gt;cc_year,
			"x_card_code"		=&amp;gt; $this-&amp;gt;cc_code,
			"x_description"		=&amp;gt; $item,
			"x_amount"			=&amp;gt; $amount,
			"x_first_name"		=&amp;gt; htmlspecialchars($this-&amp;gt;buyer["FirstName"]),
			"x_last_name"		=&amp;gt; htmlspecialchars($this-&amp;gt;buyer["LastName"]),
			"x_address"			=&amp;gt; htmlspecialchars($this-&amp;gt;buyer["Address"]),
			"x_city"			=&amp;gt; htmlspecialchars($this-&amp;gt;buyer["City"]),
			"x_state"			=&amp;gt; htmlspecialchars($this-&amp;gt;buyer["State"]),
			"x_zip"				=&amp;gt; htmlspecialchars($this-&amp;gt;buyer["Zip"]),
			"x_country"			=&amp;gt; 'US',
			"x_phone"			=&amp;gt; htmlspecialchars($this-&amp;gt;buyer["Phone"])
		);

		// makes for a safe transfer
		$fields = "";
		foreach( $values as $key =&amp;gt; $value ) $fields .= "$key=" . urlencode($value) . "&amp;amp;";

		// begin setting up cURL
		$ch = curl_init($this-&amp;gt;server); 
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "&amp;amp; "));

		// lets talk
		$resp = curl_exec($ch);
		curl_close ($ch);

		// parse the response
		$this-&amp;gt;parseReturn ($resp);

		// if we had any errors parsing, return right now
		if (sizeof ($this-&amp;gt;errorStack) &amp;gt; 0)
			return false;

		return $this-&amp;gt;approval_code;
	}

	/** parse the returned delimited string
	* @param	response	string containing the authorize.net response
	* @return	boolean
	*/
	function parseReturn ($response) {
		// figure out how many responses we got back
		$text = $response;
		$h = substr_count($text, "|");
		$h++;

		// loop through the result string, one delimited (|) chunk at time
		for($j=1; $j &amp;lt;= $h; $j++) {
			// get the location of the end of the item to process
			$p = strpos($text, "|");

			if ((!$p === false)) {
				$p++;

				$pstr = substr($text, 0, $p);

				$pstr_trimmed = substr($pstr, 0, -1); // removes "|" at the end

				// nothing found?
				if ($pstr_trimmed == "") {
					$this-&amp;gt;errorStack[] = "Error communicating with payment processing server.";
					return false;
				}

				// what did we just get?
				switch($j) {
					// case 1 is the general approved/declined/error result
					case 1:
						if ($pstr_trimmed=="1")
							$this-&amp;gt;status = "Approved";
						elseif ($pstr_trimmed=="2") {
							$this-&amp;gt;status = "Declined";
							//$this-&amp;gt;errorStack[] = "The card was declined.";
						}elseif ($pstr_trimmed=="3") {
							$this-&amp;gt;status = "Error";
							//$this-&amp;gt;errorStack[] = "An error occurred.";
						}
						break;

					// case 2 is the sub code
					case 2:
						$this-&amp;gt;subcode = $pstr_trimmed;
						break;

					// case 3 is the response code
					case 3:
						$this-&amp;gt;response_code = $pstr_trimmed;
						break;

					// case 4 is the detailed response text (readable)
					case 4:
						$this-&amp;gt;response_text = $pstr_trimmed;
						if ($this-&amp;gt;status == "Declined" || $this-&amp;gt;status == "Error")
							$this-&amp;gt;errorStack[] = $this-&amp;gt;response_text;
						break;

					// case 5 is the authorize.net approval code
					case 5:
						$this-&amp;gt;approval_code = $pstr_trimmed;
						break;

					// case 38 is the MD5 to prove it came from authorize.net
					case 38:
						$this-&amp;gt;md5hash = $pstr_trimmed;
						break;

					// case 39 is the code result
					case 39:
						if ($pstr_trimmed == "M")
							$this-&amp;gt;code = "M = Match";
						elseif ($pstr_trimmed == "N") {
							$this-&amp;gt;code = "N = No Match";
							$this-&amp;gt;errorStack[] = "The security code supplied did not match.";
						}elseif ($pstr_trimmed == "P") {
							$this-&amp;gt;code = "P = Not Processed";
							$this-&amp;gt;errorStack[] = "We were unable to process your card's security code. Please contact Reliance.";
						}elseif ($pstr_trimmed == "S")
							$this-&amp;gt;code = "S = Should have been present";
						elseif ($pstr_trimmed == "U")
							$this-&amp;gt;code = "U = Issuer unable to process request";
						else
							$this-&amp;gt;code = "NO VALUE RETURNED";
						break;

					// the rest of the messages are just stored for debugging purposes (or random use)
					default:
						$this-&amp;gt;remaining[$j] = $pstr_trimmed;
						break;
				}

				// drop the processed item
				$text = substr($text, $p);
			}
		}

		return true;
	}
}

?&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2012 16:54:58 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24289#M13029</guid>
      <dc:creator>turpentyne</dc:creator>
      <dc:date>2012-03-12T16:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to get back transaction id</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24313#M13040</link>
      <description>&lt;P&gt;After this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// case 5 is the authorize.net approval code
case 5:
        $this-&amp;gt;approval_code = $pstr_trimmed;
        break;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Add this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// case 7 is the authorize.net transaction ID
case 7:
        $this-&amp;gt;transaction_id = $pstr_trimmed;
        break;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Now, before this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;return $this-&amp;gt;approval_code;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;You will be able to access it via:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$this-&amp;gt;transaction_id&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Assuming, of course, this wall of code works the way it appears to.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2012 19:48:29 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24313#M13040</guid>
      <dc:creator>TJPride</dc:creator>
      <dc:date>2012-03-12T19:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to get back transaction id</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24357#M13062</link>
      <description>&lt;P&gt;hmmm... I think I'm missing the last bit on this? On the page itself (that includes the AIM.class.php) where I wanted to echo it and set it as a variable, I simply put "echo $response-&amp;gt;transaction_id;" thinking that would be all I need. It looked like it was done that way in some of the sample files from authorize.net&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did this part as you suggested:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// parse the response
		$this-&amp;gt;parseReturn ($resp);
		
		$this-&amp;gt;transaction_id;
	        // also tried... return $this-&amp;gt;transaction_id;
		// if we had any errors parsing, return right now
		if (sizeof ($this-&amp;gt;errorStack) &amp;gt; 0)
			return false;
		// also tried putting return $this-&amp;gt;transaction_id; here
		return $this-&amp;gt;approval_code;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2012 06:17:45 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24357#M13062</guid>
      <dc:creator>turpentyne</dc:creator>
      <dc:date>2012-03-13T06:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to get back transaction id</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24379#M13072</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;return array($this-&amp;gt;approval_code, $this-&amp;gt;transaction_id);&lt;/PRE&gt;&lt;P&gt;Then you'll have find the code that calls processCard() and look for the line(s) after that that reference the approval code. Add something to print the transaction ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you still need further work on this, I suggest hiring someone for a few dollars. We're here to support you in integrating Authorize.net, but this is getting into general PHP coding at this point.&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.authorize.net/solutions/merchantsolutions/merchantservices/certifieddeveloperdirectory/" target="_blank"&gt;http://www.authorize.net/solutions/merchantsolutions/merchantservices/certifieddeveloperdirectory/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2012 17:16:45 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/how-to-get-back-transaction-id/m-p/24379#M13072</guid>
      <dc:creator>TJPride</dc:creator>
      <dc:date>2012-03-13T17:16:45Z</dc:date>
    </item>
  </channel>
</rss>

