echophp.class   [plain text]


<?php

    /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-*/
    //                                                            //
    //  Name: ECHOPHP v1.6.3  07-02-2003                          //
    //  Description: PHP Class used to interface with             //
    //               ECHO (http://www.echo-inc.com).              //
    //  Requirements: cURL - http://curl.haxx.se/                 //
    //                OpenSSL - http://www.openssl.org            //
    //  Refer to ECHO's documentation for more info:              //
    //  http://www.openecho.com/echo_gateway_guide.html           //
    //                                                            //
    //  05-16-2003 - see WHATSNEW.txt in ECHOPHP class download   //
    //  03-28-2003 - updated to reflect additional status and     //
    //               avs_result codes                             //
    //  03-25-2003 - added error messages for missing curl/ssl    //
    //  03-21-2003 - fixed issue with cURL 7.10.2 + Win2k         //
    //  02-18-2003 - the what happened to my auth code release	  //
    //  01-16-2003 - removed duplicate functions		  //
    //  12-03-2002 - added product_description,                   //
    //                 purchase_order_number  		          //
    //  11-18-2002 - added sales_tax				  //
    //  03-12-2002 - added ec_transaction_dt                      //
    //  01-16-2002 - fixed ec_account_type (typo)                 //
    //  01-10-2002 - Added ec_account_type and ec_payment_type    //
    //  for Alex ;-)                                              //
    //                                                            //
    /*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-*/

/* Note: this is part of OpenEcho, included for code sample
   purposes.  OpenEcho is licensed under the GNU General Public
   License (GPL).  For a copy of this license and/or a complete copy
   of OpenEcho, visit www.openecho.com.
 */

/*! @class EchoPHP
    @abstract this is EchoPHP.
    @discussion this is EchoPHP.
 */

	class EchoPHP {

/*! @var order_type
  @abstract the order type
  @discussion This is undocumented for now.
*/
		var $order_type;
/*! @var transaction_type
   @abstract the transaction type.
  @discussion This is undocumented for now.
*/
		var $transaction_type;
		var $merchant_echo_id;
		var $merchant_pin;
		var $isp_echo_id;
		var $isp_pin;
		var $authorization;
		var $billing_ip_address;
		var $billing_prefix;
		var $billing_name;
		var $billing_first_name;
		var $billing_last_name;
		var $billing_company_name;
		var $billing_address1;
		var $billing_address2;
		var $billing_city;
		var $billing_state;
		var $billing_zip;
		var $billing_country;
		var $billing_phone;
		var $billing_fax;
		var $billing_email;
		var $cc_number;
		var $ccexp_month;
		var $ccexp_year;
		var $counter;
		var $debug;
		var $ec_account;
		var $ec_account_type;
		var $ec_payment_type;
		var $ec_address1;
		var $ec_address2;
		var $ec_bank_name;
		var $ec_city;
		var $ec_email;
		var $ec_first_name;
		var $ec_id_country;
		var $ec_id_exp_mm;
		var $ec_id_exp_dd;
		var $ec_id_exp_yy;
		var $ec_id_number;
		var $ec_id_state;
		var $ec_id_type;
		var $ec_last_name;
		var $ec_other_name;
		var $ec_payee;
		var $ec_rt;
		var $ec_serial_number;
		var $ec_state;
		var $ec_transaction_dt;
		var $ec_zip;
		var $grand_total;
		var $merchant_email;
		var $merchant_trace_nbr;
		var $original_amount;
		var $original_trandate_mm;
		var $original_trandate_dd;
		var $original_trandate_yyyy;
		var $original_reference;
		var $order_number;
		var $shipping_flag;
  	        var $status;
		var $shipping_prefix;
		var $shipping_name;
		var $shipping_address1;
		var $shipping_address2;
		var $shipping_city;
		var $shipping_state;
		var $shipping_zip;
		var $shipping_comments;
		var $shipping_country;
		var $shipping_phone;
		var $shipping_fax;
		var $shipper;
		var $shipper_tracking_nbr;
		var $product_description;
		var $purchase_order_number;
		var $sales_tax;
		var $track1;
		var $track2;
		var $EchoResponse;
		var $echotype1;
		var $echotype2;
		var $echotype3;
		var $openecho;
		var $avs_result;
		var $reference;
		var $EchoSuccess;
		var $cnp_recurring;
		var $cnp_security;
		var $security_result;
		var $mac;
		var $decline_code;
		var $tran_date;
		var $merchant_name;
/*! @var version 
	@abstract the version number. 
  @discussion This is undocumented for now.
 */
		var $version;
		
/*! @function Submit
    @abstract called upon submission?
 */
		function Submit() 
		{				
			if ($this->EchoServer) {
				$URL = $this->EchoServer;
			} else {
				$URL = "https://wwws.echo-inc.com/scripts/INR200.EXE";
			}

			$this->EchoResponse = "";

			$data = $this->getURLData();

			// get the php version number
			if (!(phpversion())) 
			{
				die("Please email <a href=\"mailto:developer-support@echo-inc.com\">ECHO Developer Support</a> and notify them know that the echophp.class file cannot find the <a href=\"http://www.php.net\">PHP</a> version number.  Please also include your server configuration.\n<br>\n<br>\nServer Software: ".$_SERVER["SERVER_SOFTWARE"]."\n<br>\nPHP Version: ".phpversion());
			}
	
			// checks to see if their php is under version 4.3.  if it is, then they have to execute
			// the curl statements.
			
/*! @function version_check
    @abstract called upon submission?
 */
			function version_check($vercheck)
			{
				$minver = str_replace(".","", $vercheck);
				$curver = str_replace(".","", phpversion());

				if ($curver >= $minver)
					return true;
		 		else 
					return false;
			}
			
			if (!version_check("4.3.0"))
			{
				// if the curl functions do not exist, they must install curl into php
				if (!(function_exists(curl_init))) 
				{
					print("Your <a href=\"http://www.php.net\">PHP</a> currently does not have <a href=\"http://curl.haxx.se\">cURL</a> with <a href=\"http://www.openssl.org\">OpenSSL</a> support.  Please contact your hosting company to resolve this issue.  <a href=\"http://curl.haxx.se\">cURL</a> must be configured with the --with-ssl option, and <a href=\"http://www.php.net\">PHP</a> must be configured with the --with-curl option.\n<br>\n<br>\nServer Software: ".$_SERVER["SERVER_SOFTWARE"]."\n<br>\nPHP Version: ".phpversion());
					die("");
				}
				
				// they have curl, but it must be configured with ssl to execute curl_exec($ch)
				else
				{
					$ch = @curl_init();
					curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
					curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
					curl_setopt ($ch, CURLOPT_URL, $URL);
					curl_setopt ($ch, CURLOPT_POST, $data);
					curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
					if (!($this->EchoResponse = curl_exec ($ch))) 
					{
						print("You are receiving this error for one of the following reasons:<br><br>1) Your <a href=\"http://www.php.net\">PHP</a> currently does not support <a href=\"http://curl.haxx.se\">cURL</a> with <a href=\"http://www.openssl.org\">OpenSSL</a> support.  <a href=\"http://curl.haxx.se\">cURL</a> must be configured with the --with-ssl option.<br>2) The server cannot establish an internet connection to the <i>ECHO</i>nline server at " . $URL . "<br><br>Please contact your hosting company to resolve this issue.\n<br>\n<br>\nServer Software: ".$_SERVER["SERVER_SOFTWARE"]."\n<br>\nPHP Version: ".phpversion());
						die("");
					}
					curl_close ($ch);
				}
			}
			
			// else their php can execute using openssl OR curl.  if openssl doesn't work, try curl.  if
			// that doesn't work, give an error message.
			
			else
			{
				// open the https:// file handle, will error out if OpenSSL support is not compiled into PHP
		
				ini_set('allow_url_fopen', '1');
				if (!($handle = @fopen($URL."?".$data, "r"))) 
				{ 
					if ( function_exists(curl_init) )
					{
						$ch = @curl_init();
						curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
						curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
						curl_setopt ($ch, CURLOPT_URL, $URL);
						curl_setopt ($ch, CURLOPT_POST, $data);
						curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
						if (!($this->EchoResponse = curl_exec ($ch))) 
						{
							print("You are receiving this error for one of the following reasons:<br><br>1) Your <a href=\"http://www.php.net\">PHP</a> currently does not support <a href=\"http://curl.haxx.se\">cURL</a> with <a href=\"http://www.openssl.org\">OpenSSL</a> support.  <a href=\"http://curl.haxx.se\">cURL</a> must be configured with the --with-ssl option.<br>2) The server cannot establish an internet connection to the <i>ECHO</i>nline server at " . $URL . "<br><br>Please contact your hosting company to resolve this issue.\n<br>\n<br>\nServer Software: ".$_SERVER["SERVER_SOFTWARE"]."\n<br>\nPHP Version: ".phpversion());
							die("");
						}
						curl_close ($ch);
					}
					else
					{
						print("You are receiving this error for one of the following reasons:<br><br>1) Your <a href=\"http://www.php.net\">PHP</a> does not have built-in <a href=\"http://www.openssl.org\">OpenSSL</a> support.  Please contact your hosting company to resolve this issue.  ");
						if ( strcmp($_ENV["OS"],"Windows_NT") == 0 )
						{
							print("<br><br>Since this server is running under a Windows box, it may need some modifications.  In order to take advantage of the new features in PHP 4.3.0 such as SSL url wrappers you need to install PHP with built-in SSL support. In order to do so you need to install the standard <a href=\"http://www.php.net\">PHP</a> distribution and replace php4ts.dll file with one supplied in <a href=\"http://ftp.proventum.net/pub/php/win32/misc/openssl/\">this</a> archive.  ");
							print("Since OpenSSL support is built-in into this file, please remember to comment out 'extension=php_openssl.dll' from your php.ini file since the external extension is no longer needed.");
			
						}
						else
						{
							print("<a href=\"http://www.php.net\">PHP</a> needs to be configured with the --with-openssl option.");
						}
						print("<br><br>2) The server cannot establish an internet connection to the <i>ECHO</i>nline server at " . $URL);
						print("\n<br>\n<br>\nServer Software: ".$_SERVER["SERVER_SOFTWARE"]."\n<br>\nPHP Version: ".phpversion());
						die("");
					}
				}
				else
				{
					// get the ECHO Response
					$this->EchoResponse = "";
					while (!feof ($handle)) 
					{
						$buffer = @fgets($handle, 4096);
						$this->EchoResponse .= $buffer;
					}
           	     		}
           		}
                

			$startpos = strpos($this->EchoResponse, "<ECHOTYPE1>") + 11;
			$endpos = strpos($this->EchoResponse, "</ECHOTYPE1>");
			$this->echotype1 = substr($this->EchoResponse, $startpos, $endpos - $startpos);

			$startpos = strpos($this->EchoResponse, "<ECHOTYPE2>") + 11;
			$endpos = strpos($this->EchoResponse, "</ECHOTYPE2>");
			$this->echotype2 = substr($this->EchoResponse, $startpos, $endpos - $startpos);

			$startpos = strpos($this->EchoResponse, "<ECHOTYPE3>") + 11;
			$endpos = strpos($this->EchoResponse, "</ECHOTYPE3>");
			$this->echotype3 = substr($this->EchoResponse, $startpos, $endpos - $startpos);

			if (strpos($this->EchoResponse, "<OPENECHO>")) {
				$startpos = strpos($this->EchoResponse, "<OPENECHO>") + 10;
				$endpos = strpos($this->EchoResponse, "</OPENECHO>");
				$this->openecho = substr($this->EchoResponse, $startpos, $endpos - $startpos);
			}

			// Get all the metadata.
			$this->authorization = $this->GetEchoProp($this->echotype3, "auth_code");
			$this->order_number = $this->GetEchoProp($this->echotype3, "order_number");
			$this->reference = $this->GetEchoProp($this->echotype3, "echo_reference");
            		$this->status = $this->GetEchoProp($this->echotype3, "status");
			$this->avs_result = $this->GetEchoProp($this->echotype3, "avs_result");
			$this->security_result = $this->GetEchoProp($this->echotype3, "security_result");
			$this->mac = $this->GetEchoProp($this->echotype3, "mac");
			$this->decline_code = $this->GetEchoProp($this->echotype3, "decline_code");
			$this->tran_date = $this->GetEchoProp($this->echotype3, "tran_date");
			$this->merchant_name = $this->GetEchoProp($this->echotype3, "merchant_name");
			$this->version = $this->GetEchoProp($this->echotype3, "version");

			if ($this->status == "G" or $this->status == "R")
			{
				if ($this->transaction_type == "AD") 
				{
					if ($this->avs_result == "X" or $this->avs_result == "Y" or
					    $this->avs_result == "D" or $this->avs_result == "M") 
					{
						$this->EchoSuccess = true;
					} 
					else 
					{
						$this->EchoSuccess = false;
					}
				}
				else $this->EchoSuccess = true;
			} 
			else 
			{
				$this->EchoSuccess = false;
			}


			if ($this->EchoResponse == "") {
				$this->EchoSuccess = False;
			}

			// make sure we assign an integer to EchoSuccess
			($this->EchoSuccess == true) ? ($this->EchoSuccess = true) : ($this->EchoSuccess = false);

			return $this->EchoSuccess;



		} // function submit


/*! @function getURLData
    @abstract called upon submission?
 */
		function getURLData() {
			$s .=
			"order_type=" 			. $this->order_type .
			"&transaction_type=" 		. $this->transaction_type .
			"&merchant_echo_id=" 		. $this->merchant_echo_id .
			"&merchant_pin=" 		. $this->merchant_pin .
			"&isp_echo_id=" 		. $this->isp_echo_id .
			"&isp_pin=" 			. $this->isp_pin .
			"&authorization=" 		. $this->authorization .
			"&billing_ip_address=" 		. $this->billing_ip_address .
			"&billing_prefix="		. $this->billing_prefix .
			"&billing_name="		. $this->billing_name .
			"&billing_first_name="		. $this->billing_first_name .
			"&billing_last_name="		. $this->billing_last_name .
			"&billing_company_name="	. $this->billing_company_name .
			"&billing_address1="		. $this->billing_address1 .
			"&billing_address2="		. $this->billing_address2 .
			"&billing_city="		. $this->billing_city .
			"&billing_state="		. $this->billing_state .
			"&billing_zip="			. $this->billing_zip .
			"&billing_country="		. $this->billing_country .
			"&billing_phone="		. $this->billing_phone .
			"&billing_fax="			. $this->billing_fax .
			"&billing_email="		. $this->billing_email .
			"&cc_number="			. $this->cc_number .
			"&ccexp_month="			. $this->ccexp_month .
			"&ccexp_year="			. $this->ccexp_year .
			"&counter="			. $this->counter .
			"&debug="			. $this->debug;
			if (($this->transaction_type == "DD") ||
				($this->transaction_type == "DC") ||
				($this->transaction_type == "DV")) {
				$s .=
				"&ec_account="			. $this->ec_account .
				"&ec_account_type="		. $this->ec_account_type .
				"&ec_payment_type="		. $this->ec_payment_type .
				"&ec_address1="			. $this->ec_address1 .
				"&ec_address2="			. $this->ec_address2 .
				"&ec_bank_name="		. $this->ec_bank_name .
				"&ec_city="			. $this->ec_city .
				"&ec_email="			. $this->ec_email .
				"&ec_first_name="		. $this->ec_first_name .
				"&ec_id_country="		. $this->ec_id_country .
				"&ec_id_exp_mm="		. $this->ec_id_exp_mm .
				"&ec_id_exp_dd="		. $this->ec_id_exp_dd .
				"&ec_id_exp_yy="		. $this->ec_id_exp_yy .
				"&ec_id_number="		. $this->ec_id_number .
				"&ec_id_state="			. $this->ec_id_state .
				"&ec_id_type="			. $this->ec_id_type .
				"&ec_last_name="		. $this->ec_last_name .
				"&ec_other_name="		. $this->ec_other_name .
				"&ec_payee="			. $this->ec_payee .
				"&ec_rt="			. $this->ec_rt .
				"&ec_serial_number="		. $this->ec_serial_number .
				"&ec_state="			. $this->ec_state .
				"&ec_transaction_dt="		. $this->ec_transaction_dt .
				"&ec_zip="			. $this->ec_zip;
			}

			$s .=
			"&grand_total="			. $this->grand_total .
			"&merchant_email="		. $this->merchant_email .
			"&merchant_trace_nbr="		. $this->merchant_trace_nbr .
			"&original_amount="		. $this->original_amount .
			"&original_trandate_mm="	. $this->original_trandate_mm .
			"&original_trandate_dd="	. $this->original_trandate_dd .
			"&original_trandate_yyyy="	. $this->original_trandate_yyyy .
			"&original_reference="		. $this->original_reference .
			"&order_number="		. $this->order_number .
			"&shipping_flag="		. $this->shipping_flag .
			"&shipping_prefix="		. $this->shipping_prefix .
			"&shipping_name="		. $this->shipping_name .
			"&shipping_address1="		. $this->shipping_address1 .
			"&shipping_address2="		. $this->shipping_address2 .
			"&shipping_city="		. $this->shipping_city .
			"&shipping_state="		. $this->shipping_state .
			"&shipping_zip="		. $this->shipping_zip .
			"&shipping_comments="		. $this->shipping_comments .
			"&shipping_country="		. $this->shipping_country .
			"&shipping_phone="		. $this->shipping_phone .
			"&shipping_fax="		. $this->shipping_fax .
			"&shipper="			. $this->shipper .
			"&shipper_tracking_nbr="	. $this->shipper_tracking_nbr .
			"&product_description="		. $this->product_description .
			"&purchase_order_number="	. $this->purchase_order_number .
			"&sales_tax="			. $this->sales_tax .
			"&track1="			. $this->track1 .
			"&track2="			. $this->track2 .
			"&cnp_security="		. $this->cnp_security .
			"&cnp_recurring="		. $this->cnp_recurring;

			return $s;

		} // end getURLData



		/**********************************************
		All the get/set methods for the echo properties
		***********************************************/
/*! @function set_order_type
    @abstract called upon submission?
 */
		function set_order_type($value) {
			$this->order_type = $value;
		}

/*! @function get_order_type
    @abstract called upon submission?
 */
		function get_order_type() {
			return $this->order_type;
		}

/*! @function set_transaction_type
    @abstract called upon submission?
 */
		function set_transaction_type($value) {
			$this->transaction_type = $value;
		}

/*! @function get_transaction_type
    @abstract called upon submission?
 */
		function get_transaction_type() {
			return $this->transaction_type;
		}

		function set_merchant_echo_id($value) {
			$this->merchant_echo_id = urlencode($value);
		}

		function get_merchant_echo_id() {
			return $this->merchant_echo_id;
		}

		function set_merchant_pin($value) {
			$this->merchant_pin = urlencode($value);
		}

		function get_merchant_pin() {
			return $this->merchant_pin;
		}

		function set_isp_echo_id($value) {
			$this->isp_echo_id = urlencode($value);
		}

		function get_isp_echo_id() {
			return $this->isp_echo_id;
		}

		function set_isp_pin($value) {
			$this->isp_pin = urlencode($value);
		}

		function get_isp_pin() {
			return $this->isp_pin;
		}

		function set_authorization($value) {
			$this->authorization = $value;
		}

		function get_authorization() {
			return $this->authorization;
		}

		function set_billing_ip_address($value) {
			$this->billing_ip_address = $value;
		}

		function get_billing_ip_address() {
			return $this->billing_ip_address;
		}

		function set_billing_prefix($value) {
			$this->billing_prefix = urlencode($value);
		}

		function get_billing_prefix() {
			return $this->billing_prefix;
		}
		
		function set_billing_name($value) {
			$this->billing_name = urlencode($value);
		}

		function get_billing_name() {
			return $this->billing_name;
		}	

		function set_billing_first_name($value) {
			$this->billing_first_name = urlencode($value);
		}

		function get_billing_first_name() {
			return $this->billing_first_name;
		}
		function set_billing_last_name($value) {
			$this->billing_last_name = urlencode($value);
		}

		function get_billing_last_name() {
			return $this->billing_last_name;
		}
		function set_billing_company_name($value) {
			$this->billing_company_name = urlencode($value);
		}

		function get_billing_company_name() {
			return $this->billing_company_name;
		}

		function set_billing_address1($value) {
			$this->billing_address1 = urlencode($value);
		}

		function get_billing_address1() {
			return $this->billing_address1;
		}

		function set_billing_address2($value) {
			$this->billing_address2 = urlencode($value);
		}

		function get_billing_address2() {
			return $this->billing_address2;
		}

		function set_billing_city($value) {
			$this->billing_city = urlencode($value);
		}

		function get_billing_city() {
			return $this->billing_city;
		}

		function set_billing_state($value) {
			$this->billing_state = urlencode($value);
		}

		function get_billing_state() {
			return $this->billing_state;
		}

		function set_billing_zip($value) {
			$this->billing_zip = urlencode($value);
		}

		function get_billing_zip() {
			return $this->billing_zip;
		}

		function set_billing_country($value) {
			$this->billing_country = urlencode($value);
		}

		function get_billing_country() {
			return $this->billing_country;
		}

		function set_billing_phone($value) {
			$this->billing_phone = urlencode($value);
		}

		function get_billing_phone() {
			return $this->billing_phone;
		}

		function set_billing_fax($value) {
			$this->billing_fax = urlencode($value);
		}

		function get_billing_fax() {
			return $this->billing_fax;
		}

		function set_billing_email($value) {
			$this->billing_email = urlencode($value);
		}

		function get_billing_email() {
			return $this->billing_email;
		}

		function set_cc_number($value) {
			$this->cc_number = urlencode($value);
		}

		function get_cc_number() {
			return $this->cc_number;
		}

		function set_ccexp_month($value) {
			$this->ccexp_month = $value;
		}

		function get_ccexp_month() {
			return $this->ccexp_month;
		}

		function set_ccexp_year($value) {
			$this->ccexp_year = $value;
		}

		function get_ccexp_year() {
			return $this->ccexp_year;
		}

		function set_counter($value) {
			$this->counter = $value;
		}

		function get_counter() {
			return $this->counter;
		}

		function set_debug($value) {
			$this->debug = $value;
		}

		function get_debug() {
			return $this->debug;
		}

		function set_ec_account($value) {
			$this->ec_account = urlencode($value);
		}

		function get_ec_account() {
			return $this->ec_account;
		}

		function set_ec_account_type($value) {
			$this->ec_account_type = urlencode($value);
		}

		function get_ec_account_type() {
			return $this->ec_account_type;
		}

		function set_ec_payment_type($value) {
			$this->ec_payment_type = urlencode($value);
		}

		function get_ec_payment_type() {
			return $this->ec_payment_type;
		}

		function set_ec_address1($value) {
			$this->ec_address1 = urlencode($value);
		}

		function get_ec_address1() {
			return $this->ec_address1;
		}

		function set_ec_address2($value) {
			$this->ec_address2 = urlencode($value);
		}

		function get_ec_address2() {
			return $this->ec_address2;
		}

		function set_ec_bank_name($value) {
			$this->ec_bank_name = urlencode($value);
		}

		function get_ec_bank_name() {
			return $this->ec_bank_name;
		}

		function set_ec_city($value) {
			$this->ec_city = $value;
		}

		function get_ec_city() {
			return $this->ec_city;
		}

		function set_ec_email($value) {
			$this->ec_email = urlencode($value);
		}

		function get_ec_email() {
			return $this->ec_email;
		}

		function set_ec_first_name($value) {
			$this->ec_first_name = urlencode($value);
		}

		function get_ec_first_name() {
			return $this->ec_first_name;
		}

		function set_ec_id_country($value) {
			$this->ec_id_country = urlencode($value);
		}

		function get_ec_id_country() {
			return $this->ec_id_country;
		}

		function set_ec_id_exp_mm($value) {
			$this->ec_id_exp_mm = $value;
		}

		function get_ec_id_exp_mm() {
			return $this->ec_id_exp_mm;
		}

		function set_ec_id_exp_dd($value) {
			$this->ec_id_exp_dd = $value;
		}

		function get_ec_id_exp_dd() {
			return $this->ec_id_exp_dd;
		}

		function set_ec_id_exp_yy($value) {
			$this->ec_id_exp_yy = $value;
		}

		function get_ec_id_exp_yy() {
			return $this->ec_id_exp_yy;
		}

		function set_ec_id_number($value) {
			$this->ec_id_number = urlencode($value);
		}

		function get_ec_id_number() {
			return $this->ec_id_number;
		}

		function set_ec_id_state($value) {
			$this->ec_id_state = urlencode($value);
		}

		function get_ec_id_state() {
			return $this->ec_id_state;
		}

		function set_ec_id_type($value) {
			$this->ec_id_type = $value;
		}

		function get_ec_id_type() {
			return $this->ec_id_type;
		}

		function set_ec_last_name($value) {
			$this->ec_last_name = urlencode($value);
		}

		function get_ec_last_name() {
			return $this->ec_last_name;
		}

		function set_ec_other_name($value) {
			$this->ec_other_name = urlencode($value);
		}

		function get_ec_other_name() {
			return $this->ec_other_name;
		}

		function set_ec_payee($value) {
			$this->ec_payee = urlencode($value);
		}

		function get_ec_payee() {
			return $this->ec_payee;
		}

		function set_ec_rt($value) {
			$this->ec_rt = urlencode($value);
		}

		function get_ec_rt() {
			return $this->ec_rt;
		}

		function set_ec_serial_number($value) {
			$this->ec_serial_number = urlencode($value);
		}

		function get_ec_serial_number() {
			return $this->ec_serial_number;
		}

		function set_ec_state($value) {
			$this->ec_state = urlencode($value);
		}

		function get_ec_state() {
			return $this->ec_state;
		}

		function set_ec_transaction_dt($value) {
			$this->ec_transaction_dt = urlencode($value);
		}

		function get_ec_transaction_dt() {
			return $this->ec_transaction_dt;
		}


		function set_ec_zip($value) {
			$this->ec_zip = urlencode($value);
		}

		function get_ec_zip() {
			return $this->ec_zip;
		}

		function set_grand_total($value) {
			$this->grand_total = sprintf("%01.2f", $value);
		}

		function get_grand_total() {
			return $this->grand_total;
		}

		function set_merchant_email($value) {
			$this->merchant_email = urlencode($value);
		}

		function get_merchant_email() {
			return $this->merchant_email;
		}

		function set_merchant_trace_nbr($value) {
			$this->merchant_trace_nbr = $value;
		}

		function get_merchant_trace_nbr() {
			return $this->merchant_trace_nbr;
		}

		function set_original_amount($value) {
			$this->original_amount = sprintf("%01.2f", $value);
		}

		function get_original_amount() {
			return $this->original_amount;
		}

		function set_original_trandate_mm($value) {
			$this->original_trandate_mm = $value;
		}

		function get_original_trandate_mm() {
			return $this->original_trandate_mm;
		}

		function set_original_trandate_dd($value) {
			$this->original_trandate_dd = $value;
		}

		function get_original_trandate_dd() {
			return $this->original_trandate_dd;
		}

		function set_original_trandate_yyyy($value) {
			$this->original_trandate_yyyy = $value;
		}

		function get_original_trandate_yyyy() {
			return $this->original_trandate_yyyy;
		}

		function set_original_reference($value) {
			$this->original_reference = $value;
		}

		function get_original_reference() {
			return $this->original_reference;
		}

		function set_order_number($value) {
			$this->order_number = $value;
		}

		function get_order_number() {
			return $this->order_number;
		}

		function set_shipping_flag($value) {
			$this->shipping_flag = $value;
		}

		function get_shipping_flag() {
			return $this->shipping_flag;
		}

		function set_shipping_prefix($value) {
			$this->shipping_prefix = urlencode($value);
		}

		function get_shipping_prefix() {
			return $this->shipping_prefix;
		}

		function set_shipping_name($value) {
			$this->shipping_name = urlencode($value);
		}

		function get_shipping_name() {
			return $this->shipping_name;
		}

		function set_shipping_address1($value) {
			$this->shipping_address1 = urlencode($value);
		}

		function get_shipping_address1() {
			return $this->shipping_address1;
		}

		function set_shipping_address2($value) {
			$this->shipping_address2 = urlencode($value);
		}

		function get_shipping_address2() {
			return $this->shipping_address2;
		}

		function set_shipping_city($value) {
			$this->shipping_city = urlencode($value);
		}

		function get_shipping_city() {
			return $this->shipping_city;
		}

		function set_shipping_state($value) {
			$this->shipping_state = urlencode($value);
		}

		function get_shipping_state() {
			return $this->shipping_state;
		}

		function set_shipping_zip($value) {
			$this->shipping_zip = urlencode($value);
		}

		function get_shipping_zip() {
			return $this->shipping_zip;
		}

		function set_shipping_comments($value) {
			$this->shipping_comments = urlencode($value);
		}

		function get_shipping_comments() {
			return $this->shipping_comments;
		}

		function set_shipping_country($value) {
			$this->shipping_country = urlencode($value);
		}

		function get_shipping_country() {
			return $this->shipping_country;
		}

		function set_shipping_phone($value) {
			$this->shipping_phone = urlencode($value);
		}

		function get_shipping_phone() {
			return $this->shipping_phone;
		}

		function set_shipping_fax($value) {
			$this->shipping_fax = urlencode($value);
		}

		function get_shipping_fax() {
			return $this->shipping_fax;
		}

		function set_shipper($value) {
			$this->shipper = urlencode($value);
		}

		function get_shipper() {
			return $this->shipper;
		}

		function set_shipper_tracking_nbr($value) {
			$this->shipper_tracking_nbr = $value;
		}

		function get_shipper_tracking_nbr() {
			return $this->shipper_tracking_nbr;
		}
		
		function set_product_description($value) {
			$this->product_description = urlencode($value);
		}
	
		function get_product_description() {
			return $this->product_description;
		}

		function set_purchase_order_number($value) {
			$this->purchase_order_number = urlencode($value);
		}

		function get_purchase_order_number() {
			return $this->purchase_order_number;
		}

		function set_sales_tax($value) {
			$this->sales_tax = urlencode($value);
		}

		function get_sales_tax() {
			return $this->sales_tax;
		}

		function set_track1($value) {
			$this->track1 = urlencode($value);
		}

		function get_track1() {
			return $this->track1;
		}

		function set_track2($value) {
			$this->track2 = urlencode($value);
		}

		function get_track2() {
			return $this->track2;
		}

		function set_cnp_recurring($value) {
			$this->cnp_recurring = $value;
		}

		function set_cnp_security($value) {
			$this->cnp_security = $value;
		}


		/************************************************
						Helper functions
		************************************************/

		function get_version() 
		{
			return "ECHOPHP 1.6.3 07/02/2003";
		}

		function getRandomCounter() {
			mt_srand ((double) microtime() * 1000000);
			return mt_rand();
		}

		function get_EchoResponse() {
			return $this->EchoResponse;
		}

		function get_echotype1() {
			return $this->echotype1;
		}

		function get_echotype2() {
			return $this->echotype2;
		}

		function get_echotype3() {
			return $this->echotype3;
		}

		function get_openecho() {
			return $this->openecho;
		}

		function set_EchoServer($value) {
			$this->EchoServer = $value;
		}


		function get_avs_result() {
			return $this->avs_result;
		}

		function get_reference() {
			return $this->reference;
		}

		function get_EchoSuccess() {
			return $this->EchoSuccess;
		}

		function get_status() {
			return $this->status;
		}

		function get_security_result() {
			return $this->GetEchoProp($this->echotype3, "security_result");
		}

		function get_mac() {
			return $this->GetEchoProp($this->echotype3, "mac");
		}
		
		function get_decline_code() {
			return $this->GetEchoProp($this->echotype3, "decline_code");
		}

/*! @function GetEchoProp
  @discussion Get Echo Property?
 */
		function GetEchoProp($haystack, $prop) {
			// prepend garbage in case the property
			// starts at position 0 .. I know, there's a better way
			// to do this, right?
			$haystack = "garbage" . $haystack;

			if  ($start_pos = strpos(strtolower($haystack), "<$prop>")) {
				$start_pos = strpos(strtolower($haystack), "<$prop>") + strlen("<$prop>");
				$end_pos = strpos(strtolower($haystack), "</$prop");
				return substr($haystack, $start_pos, $end_pos - $start_pos);
			} else {
				return "";
			}
		}

	} // end of class
?>