<?php

function plugin_stormpay_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"=>"StormPay"
                                   ),
               "In Signup" => array (
                                    "type"=>"yesno",
                                    "description"=>"Select YES if you want to include this payment processor in the signup script.",
                                    "value"=>"0"
                                   ),
               "User ID" => array (
                                    "type"=>"text",
                                    "description"=>"ID used to identify you to StormPay.<br>NOTE: This ID is required if you have selected StormPay as a payment gateway for any of your clients.",
                                    "value"=>""
                                   ),
               "Visa" => array (
                                    "type"=>"yesno",
                                    "description"=>"Select YES to allow Visa card acceptance with this plugin.  No will prevent this card type.",
                                    "value"=>"0"
                                   ),
               "MasterCard" => array (
                                    "type"=>"yesno",
                                    "description"=>"Select YES to allow MasterCard acceptance with this plugin. No will prevent this card type.",
                                    "value"=>"0"
                                   ),
               "AmericanExpress" => array (
                                    "type"=>"yesno",
                                    "description"=>"Select YES to allow American Express card acceptance with this plugin. No will prevent this card type.",
                                    "value"=>"0"
                                   ),
               "Discover" => array (
                                    "type"=>"yesno",
                                    "description"=>"Select YES to allow Discover card acceptance with this plugin. No will prevent this card type.",
                                    "value"=>"0"
                                   ),
               "Invoice After Signup" => array (
                                    "type"=>"yesno",
                                    "description"=>"Select YES if you want an invoice sent to customer after signup is complete.  Only used for offline plugins",
                                    "value"=>"1"
                                   ),
               "Signup Name" => array (
                                    "type"=>"text",
                                    "description"=>"Select the name to display in the signup process for this payment type. Example: eCheck or Credit Card.",
                                    "value"=>"Stormpay"
                                   ),
               "Accept CC Number" => array (
                                       "type"=>"hidden",
                                    "description"=>"Selecting YES allows the entering of CC numbers when using this plugin type. No will prevent entering of cc information",
                                    "value"=>"0"
                                   ),
               "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"
                                   ),
               "Auto Payment" => array (
                                    "type"=>"hidden",
                                    "description"=>"No description",
                                    "value"=>"0"
                                   ),
               "30 Day Billing" => array (
                                    "type"=>"hidden",
                                    "description"=>"Select YES if you want ClientExec to treat monthly billing by 30 day intervals.  If you select NO then the same day will be used to determine intervals.",
                                    "value"=>"0"
                                   ),
                            "buttonurl" => array (
                                    "type"=>"text",
                                    "description"=>"Button URL of the StormPay Buy Now Button.",
                                    "value"=>"https://www.stormpay.com/stormpay/images/BuyNowSP1.gif"
                                   ),
                            "secretcode" => array (
                                    "type"=>"text",
                                    "description"=>"Secret Code as configured in your StormPay Accounts IPN configurations.",
                                    "value"=>""
                                   ),
                            "test" => array (
                                    "type"=>"yesno",
                                    "description"=>"Test mode Switch for the StormPay Module.",
                                    "value"=>"0"
                                   )
    );

    return $variables;

}

function plugin_stormpay_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_stormpay_UserID"])
    $stat_url = substr($params['clientExecURL'],-1,1) == "//" ? $params['clientExecURL']."plugins/gateways/stormpay/callback.php" : $params['clientExecURL']."/plugins/gateways/stormpay/callback.php";

    $strRet = "<html>\n";
    $strRet .= "<head></head>\n";
    $strRet .= "<body>\n";
    $strRet .= "<form name=frmStormpay action=\"https://www.stormpay.com/stormpay/handle_gen.php\" method=\"post\">";
    $strRet .= "<INPUT type=hidden name=\"generic\" value=\"1\">";
        $strRet .= "<INPUT type=hidden name=\"vendor_email\" value=\"".$params["plugin_stormpay_User ID"]."\">";
        $strRet .= "<INPUT type=hidden name=\"payee_email\" value=\"".$params["plugin_stormpay_User ID"]."\">";
    $strRet .= "<INPUT type=hidden name=\"product_name\" value=\"".$params["companyName"]." Invoice\">";
    $strRet .= "<INPUT type=hidden name=\"description\" value=\"Invoice Number:".$params['invoiceNumber']."\">";
        $strRet .= "<INPUT type=hidden name=\"amount\" value=\"".sprintf("%.2f", $params["invoiceTotal"])."\">";
        $strRet .= "<INPUT type=hidden name=\"user1\" value=\"".$params["invoiceNumber"]."\">";// USER VARIABLE FOR IPN

    //Need to check to see if user is coming from signup
    if ($params['isSignup']==1) {
          $returnURL=$params["clientExecURL"]."/signup.php?step=6&pass=1";
          $returnURL_Cancel=$params["clientExecURL"]."/signup.php?step=6&pass=0";
    }else {
          $returnURL=$params["clientExecURL"];
          $returnURL_Cancel=$params["clientExecURL"];
    }

    $strRet .= "<INPUT type=hidden name=\"return_URL\" value=\"".$returnURL."\">";
    $strRet .= "<input type=hidden name=\"cancel_URL\" value=\"".$returnURL_Cancel."\">";
    $strRet .= "<input type=hidden name=\"notify_URL\" value=\"".$stat_url."\">";
        $strRet .= "<input type=hidden name=\"require_IPN\" value=\"1\">";
        $strRet .= "<input type=hidden name=\"test_mode\" value=\"".$params["plugin_stormpay_test"]."\">";
    $strRet .= "<input type=hidden name=\"secret_code\" value=\"".$params["plugin_stormpay_secretcode"]."\">";
    $strRet .= "<INPUT type=hidden name=\"first_name\" value=\"".$params["userFirstName"]."\">";
    $strRet .= "<INPUT type=hidden name=\"last_name\" value=\"".$params["userLastName"]."\">";
    $strRet .= "<INPUT type=hidden name=\"address1\" value=\"".$params["userAddress"]."\">";
    $strRet .= "<INPUT type=hidden name=\"city\" value=\"".$params["userCity"]."\">";
    $strRet .= "<INPUT type=hidden name=\"state\" value=\"".$params["userState"]."\">";
    $strRet .= "<INPUT type=hidden name=\"zip\" value=\"".$params["userZipcode"]."\">";
    $strRet .= "<INPUT type=hidden name=\"require_shipping\" value=\"0\">";
//    $strRet .= "<INPUT type=hidden name=\"no_note\" value=\"1\">";
//    $strRet .= "<INPUT type=hidden name=\"currency_code\" value=\"".$params["currencytype"]."\">";
        //<input type="image" src="https://www.stormpay.com/stormpay/images/BuyNowSP1.gif">
    $strRet .= "<script language=\"JavaScript\">\n";
    $strRet .= "document.forms['frmStormpay'].submit();\n";
    $strRet .= "</script>\n";
        $strRet .= "<INPUT type=image src=\"".$params["plugin_stormpay_buttonurl"]."\">";
    $strRet .= "</form>\n";
    $strRet .= "</body></html>";
    echo $strRet;
    exit;
}

?>
