<?php
	
		$amount			= '110';
		$description	= 'echeck product';
		
		$txtAuthorizeLoginId=urlencode('5rWJhq38ShG');
		$txtAuthorizePassword='';
		$txtAuthorizeTransKey=urlencode('5JqprS48438GQKJL');
		$chkAuthorizeMode="YES";;

		$x_customdata="Custom";
		$x_Login= urlencode($txtAuthorizeLoginId); // Replace LOGIN with your login
		$x_Password= urlencode($txtAuthorizePassword); // Replace PASS with your password
		$x_tran_key = urlencode($txtAuthorizeTransKey); // Tran Key
		$x_Delim_Data= urlencode("TRUE");
		$x_Delim_Char= urlencode(",");
		$x_Encap_Char= urlencode("");
		$x_Type= urlencode("AUTH_CAPTURE");

		$x_ADC_Relay_Response = urlencode("FALSE");

		if($chkAuthorizeMode != "NO")
		{
        	$x_Test_Request= urlencode("TRUE");
		}//end if
		
		# Customer Information

		$x_Method= urlencode("ECHECK");
		
		$x_Amount= urlencode($amount);
			
		$x_First_Name= urlencode('test');
		$x_Last_Name= urlencode('test');
		$x_Card_Num= urlencode('test');
		$ExpDate = ('12' . '2009');
		$x_Exp_Date= urlencode($ExpDate);
		$x_card_code =urlencode('123');

		$x_Address= urlencode('test');
		$x_City= urlencode('test');
		$x_State= urlencode('test');
		$x_Zip= urlencode('878778');
		$x_country=urlencode('test');

		$x_saleid = urlencode($saleid);
		$x_userid = urlencode('1');
		$x_dDate = urlencode(date('Y-m-d'));

		$x_Email= urlencode('test@armia.com');
		$x_Email_Customer= urlencode("TRUE");
		$x_Merchant_Email= urlencode('chris@gigamediagroup.com');
		$x_description = urlencode($description);
		
		//for echeck
		
		$x_bank_aba_bode=urlencode('234');

		$x_bank_acct_num=urlencode('3432');
		
		//Describes the type of bank account; if no value is provided,default is set to CHECKING
		if($_POST['txtAccountType']!='')
		{
			$BankAcType=$_POST['txtAccountType'];
		}//end if
		else
		{
			$BankAcType='CHECKING';
		}//end else
		
		$x_bank_acct_type=urlencode($BankAcType);

		$x_bank_name=urlencode('federal');

		$x_bank_acct_name=urlencode('test');

		$x_echeck_type=urlencode('WEB');

		$x_customer_ip='';

		//I=Individual,B=Business
		$x_customer_organization_type==urlencode('I');

		/*Tax ID or SSN of the customer initiating the transaction. 
		 If the Tax ID or SSN is not available, the custoerm's driver's license number,
		 driver's license state and date of birht must be used in it place*/
		 
		$x_customer_tax_id='';

		$x_drivers_license_num='';


		$x_drivers_license_state=$x_State;

		$x_drivers_license_dob=urlencode('12-11-1980');

		//end for echek
		
		//$custip	= $this->get_client_ip();
		$custip	= '192.168.0.12';
		$x_cust_ip=$custip;
		$x_invid="15";
		$x_company="Dollar Date";
		$x_phone=urlencode('23234');
		$x_cust_id=$id;
		$x_invoice_num=$var_inv_no;
		$x_invno=$var_inv_no;

		# Build fields string to post

		$fields = "x_Version=3.1&x_Login=$x_Login&x_tran_key=$x_tran_key&x_Delim_Data=$x_Delim_Data&x_Delim_Char=$x_Delim_Char&x_Encap_Char=$x_Encap_Char";
		$fields .= "&x_Type=$x_Type&x_Test_Request=$x_Test_Request&x_Method=$x_Method&x_Amount=$x_Amount&x_First_Name=$x_First_Name";
		//for echech
		$fields .="&x_bank_aba_bode=$x_bank_aba_bode&x_bank_acct_num=$x_bank_acct_num&x_bank_acct_type=$x_bank_acct_type";
		$fields .="&x_bank_name=$x_bank_name&x_bank_acct_name=$x_bank_acct_name&x_echeck_type=$x_echeck_type&x_customer_ip=$x_customer_ip";
		$fields .="&x_customer_organization_type=$x_customer_organization_type&x_customer_tax_id=$x_customer_tax_id&x_drivers_license_num=$x_drivers_license_num";
		$fields .="&x_drivers_license_state=$x_drivers_license_state&x_drivers_license_dob=$x_drivers_license_dob";
		//for echeck
		$fields .= "&x_Last_Name=$x_Last_Name&x_Card_Num=$x_Card_Num&x_Exp_Date=$x_Exp_Date&x_card_code=$x_card_code&x_Address=$x_Address&x_City=$x_City&x_State=$x_State&x_Zip=$x_Zip&x_country=$x_country&x_Email=$x_Email&x_Email_Customer=$x_Email_Customer&x_Merchant_Email=$x_Merchant_Email&x_ADC_Relay_Response=$x_ADC_Relay_Response&x_invid=$x_invid&x_cust_ip=$x_cust_ip&x_company=$x_company&x_phone=$x_phone&x_cust_id=$x_cust_id&x_invoice_num=$x_invno&x_description=$x_description";
		if ($x_Password != '')
		{
        	$fields .= "&x_Password=$x_Password";
		}//end if	

		# Start CURL session

		$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
		$ch=curl_init("https://secure.authorize.net/gateway/transact.dll");
		curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
		curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " )); // use HTTP POST to send form data
		curl_setopt($ch, CURLOPT_VERBOSE, 1);
		//curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
		//curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
		//curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");

		$buffer = curl_exec($ch);
		curl_close($ch);

		$return = preg_split("/[,]+/", "$buffer");
		$details = $return[0];


		switch ($details)
		{
  				  case "1":
                 	$cc_flag=true;
		           $cc_tran=$return[6];
              break;

       			 case "2":
                        $cc_flag = false;
                        $cc_err="The card has been declined";
                         $cc_err .="<br>" . $return[3];
                break;
       	 case "4":
                        $cc_flag = false;
                        $cc_err="The card has been held for review";
                        $cc_err .="<br>" . $return[3];
                break;
   		 default:
                     $cc_flag = false;
                     $cc_err="Error";
                     $cc_err .="<br>" . $return[3];
       		 break;
		}//end switch
		echo 'Error:<br>'.$cc_err;
?>

