<?php
function plugin_chronopay_variables() {
	/* Specification
		  itemkey     - used to identify variable in your other functions
		  type 		  - text,textarea,yesno,password
		  description - description of the variable, displayed in ClientExec
	*/

    $variables = array (
               "Plugin Name" => array (
			   						"type"=>"hidden",
									"description"=>"How CE sees this plugin (not to be confused with the Signup Name)",
									"value"=>"ChronoPay"
								   ),
               "In Signup" => array (
			   						"type"=>"yesno",
									"description"=>"Select YES if you want to include this payment processor in the signup script.",
									"value"=>"0"
								   ),
               "Product ID" => array (
			   						"type"=>"text",
									"description"=>"Product ID configured in your ChronoPay Account.<br>NOTE: This ID is required if you have selected ChronoPay as a payment gateway for any of your clients.",
									"value"=>""
								   ),
               "Product Name" => array (
			   						"type"=>"text",
									"description"=>"Product Name to be displayed on the ChronoPay hosted payment page.",
									"value"=>""
								   ),
               "ChronoPay Language" => array (
			   						"type"=>"text",
									"description"=>"Language in which the ChronoPay page will be displayed in. <br/>NL = Dutch, ES = Spanish, <br/>RU = Russian, EN = English (Default)",
									"value"=>"EN"
								   ),
               "Invoice After Signup" => array (
                                    "type"=>"yesno",
                                    "description"=>"Select YES if you want an invoice sent to the customer after signup is complete.",
                                    "value"=>"1"
                                   ),
               "Signup Name" => array (
			   						"type"=>"text",
									"description"=>"Select the name to display in the signup process for this payment type. Example: ChronoPay or Credit Card.",
									"value"=>"Credit Card"
								   ),
               "Dummy Plugin" => array (
			   						"type"=>"hidden",
									"description"=>"1 = Only used to specify a billing type for a customer. 0 = full fledged plugin requiring complete functions",
									"value"=>"0"
								   ),
    );
	return $variables;
}

function plugin_chronopay_singlepayment($params) {
	//Function needs to build the url to the payment processor, then redirect
	//Plugin variables can be accesses via $params["plugin_[pluginname]_[variable]"] (ex. $params["plugin_2checkout_SellerID"])

	$return_url = substr($params['clientExecURL'],-1,1) == "//" ? $params['clientExecURL']."plugins/gateways/chronopay/callback_ipn.php" : $params['clientExecURL']."/plugins/gateways/chronopay/callback_ipn.php";
	
	$postURL = "https://secure.chronopay.com/index_shop.cgi";

	
	if ($params["userCountry"]=="US") $params["userCountry"]="USA";
	
	//if ($params["invoiceDomainCharge"] == "1")
	//	$tPrice = $params["invoiceTotal"] - $params["invoiceSetup"] - $params["invoiceDomainSetup"];
	//else
	//	$tPrice = $params["invoiceTotal"] - $params["invoiceSetup"];

//	print_r( $params );

    //generate post to submit to chronopay
    $strRet = "<html>\n";
    $strRet .= "<head></head>\n";
    $strRet .= "<body>\n";
    $strRet .= "<form name=\"frmChronoPay\" action=\"$postURL\" method=\"post\">\n";
    $strRet .= "<input type=\"hidden\" name=\"product_id\" value=\"".$params['plugin_chronopay_Product ID']."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"product_name\" value=\"".$params['plugin_chronopay_Product Name']."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"product_price\" value=\"".sprintf("%.2f", $params["invoiceTotal"])."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"product_price_currency\" value=\"".$params['currencytype']."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"language\" value=\"".$params['plugin_chronopay_ChronoPay Language']."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"cs1\" value=\"".$params["invoiceNumber"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"cs2\" value=\"".$params['isSignup']."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"cs3\" value=\"".''."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"cb_url\" value=\"".$return_url."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"cb_type\" value=\"P\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"decline_url\" value=\"".$return_url."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"f_name\" value=\"".$params["userFirstName"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"s_name\" value=\"".$params["userLastName"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"street\" value=\"".$params["userAddress"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"city\" value=\"".$params["userCity"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"state\" value=\"".$params["userState"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"zip\" value=\"".$params["userZipcode"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"country\" value=\"".$params["userCountry"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"email\" value=\"".$params["userEmail"]."\" />\n";
    $strRet .= "<input type=\"hidden\" name=\"phone\" value=\"".$params["userPhone"]."\" />\n";
    $strRet .= "<script language=\"JavaScript\">\n";
    $strRet .= "document.forms[0].submit();\n";
    $strRet .= "</script>\n";
//	$strRet .= "<input type=\"submit\" name=\"go\" value=\"Go to ChronoPay\" />\n";
    $strRet .= "</form>\n";
    $strRet .= "</body></html>";
    echo $strRet;
 	exit;
 }
?>