<?php
if (!$txtFirstName || !$txtLastName || !$txtAddress || !$txtCity || !$txtState || !$txtZIP || !$txtCCNumber || !
    $txtEmail || !$txtCVV2 || !$ddlCountry || !$txtMM || !$txtYY|| !$txtPhone) {
    $paymentsuccessful = false;
    $paymenterror = "Some necessary information were found missing.  Please enter the missing information." ;
	// exit;
}else{
	include_once "lphp.php";
	$mylphp=new lphp;
	$myorder["host"]       = "secure.linkpt.net";
	$myorder["port"]       = "1129";
	$myorder["keyfile"]    = "./pem/".$pemfolder; # Change this to the name and location of your certificate file
	$myorder["configfile"] = urlencode($txtYourpayStoreId);        # Change this to your store number
	$myorder["ordertype"]    = "SALE";
    if($txtUrPayDemo=="YES"){
	  $myorder["result"]       = "GOOD";# For a test, set result to GOOD, DECLINE, or DUPLICATE
	}else{
	  $myorder["result"]       = "LIVE";
	}

    $myorder["cardnumber"]   = urlencode($txtCCNumber);
	$myorder["cardexpmonth"] = $txtMM ;
	$myorder["cardexpyear"]  = $txtYY;
	$myorder["chargetotal"]  = urlencode($totaltopay);
	
	if($reccuringpayment==true and $reccuringmode=="SUBMIT"){
            //echo " <br>Yourpay submited::$recurringinstallment::$recurringstartdate:$recurringperiodicity";
            $myorder["action"]="SUBMIT";
            $myorder["installments"] = $recurringinstallment;
			$myorder["threshold"] = "3";
			$myorder["startdate"] = $recurringstartdate;
			$myorder["periodicity"] = $recurringperiodicity;
	}
	    if($reccuringpayment==true and $reccuringmode=="CANCEL"){
	        //echo " <br>Yourpay cancel ::$recurringinstallment::$recurringstartdate:$recurringperiodicity::$recurringorderid";
            $myorder["action"]="CANCEL";
            $myorder["installments"] = $recurringinstallment;
			$myorder["threshold"] = "3";
			$myorder["startdate"] = $recurringstartdate;
			$myorder["periodicity"] = $recurringperiodicity;
			$myorder["oid"] = $recurringorderid;
	   }
# BILLING INFO 4111111111111111
	$myorder["name"]     =urlencode($txtFirstName)." ".urlencode($txtLastName);
	$myorder["company"]  = "-NA-";
	$myorder["address1"] = urlencode($txtAddress);
	$myorder["city"]     = urlencode($txtCity);
	$myorder["state"]    = urlencode($txtState);
	$myorder["country"]  = urlencode($ddlCountry);
	$myorder["phone"]    = urlencode($txtPhone);
	$myorder["email"]    = urlencode($txtEmail);
	//$myorder["debugging"] = "true";  # for development only - not intended for production use
	$result = $mylphp->curl_process($myorder);  # use curl methods
  /*echo "<br>result::$result<br>";
  echo "<br>approved==".$result["r_approved"];
  echo "<br>ordernum===".$result[r_ordernum];
  echo "<br>ordernum1===".$result["r_ordernum"];
  echo "<br>resultarray<br>";
  foreach($result as $key=>$value){
  echo "<br>$key::$value";
 }
  echo "<br>";*/
   if(!is_array($result)){
        $paymentsuccessful = false;
       $paymenterror = "Error";
       //$paymenterror .= "<br>Transcation declined. Please contact the administrator." . $result;
       $paymenterror =$result;
   }else{

	if ($result["r_approved"] != "APPROVED")	// transaction failed, print the reason
	{
	   $paymentsuccessful = false;
       $paymenterror = "Error";
       $err=explode(":",$result[r_error]);
       if(is_array($err))
       $len=strlen($err[0])+1;
       else
         $len=0;
       $paymenterror .= "<br>" . substr($result[r_error],$len);
		//print "Status: $result[r_approved]\n";
		//print "Error: $result[r_error]\n";
	}
	else
	{	// success
	   $paymentsuccessful = true;
       $transactionid = $result[r_ordernum];
	//	print "Status: $result[r_approved]\n";
		//print "Code: $result[r_code]\n";
		//print "OID: $result[r_ordernum]\n\n";
	}
}


}
?>
