<?php
require_once 'modules/admin/models/GatewayPlugin.php';
require_once 'modules/billing/models/Currency.php';

class PluginAlertpay extends GatewayPlugin{

    function getVariables()
    {
        /* 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 (
            /*T*/"Plugin Name"/*/T*/ => array (
                                "type"          =>"hidden",
                                "description"   =>/*T*/"How CE sees this plugin (not to be confused with the Signup Name)"/*/T*/,
                                "value"         =>/*T*/"Alertpay"/*/T*/
            ),
            /*T*/"In Signup"/*/T*/ => array (
                                "type"          =>"yesno",
                                "description"   =>/*T*/"Select YES if you want to include this payment processor in the signup script."/*/T*/,
                                "value"         =>"0"
            ),
           /*T*/"One-Time Payments"/*/T*/ => array (
                                "type"          =>"yesno",
                                "description"   =>/*T*/"Select YES if you want to allow customers to make one-time payments through this payment processor."/*/T*/,
                                "value"         =>"0"
            ),
            /*T*/"User ID"/*/T*/ => array (
                                "type"          =>"text",
                                "description"   =>/*T*/"ID used to identify you to Alertpay.<br>NOTE: This ID is required if you have selected Alertpay as a payment gateway for any of your clients."/*/T*/,
                                "value"         =>""
            ),
            /*T*/"Security Code"/*/T*/ => array (
                                "type"          =>"text",
                                "description"   =>/*T*/"Security Code in your Alertpay IPN setup."/*/T*/,
                                "value"         =>""
            ),
            /*T*/"Signup Name"/*/T*/ => array (
                                "type"          =>"text",
                                "description"   =>/*T*/"Select the name to display in the signup process for this payment type. Example: eCheck or Credit Card."/*/T*/,
                                "value"         =>"Alertpay"
            ),
           /*T*/"Payment Description"/*/T*/ => array (
                        "type"          =>"text",
                        "description"   =>/*T*/"(Optional) Enter the description for this payment processor to be shown to customers. <br /><b>Example:</b> Save time.  Checkout securely.&lt;br /&gt;&amp;nbsp; Pay without sharing your financial information."/*/T*/,
                        "value"         =>""
            ),
            /*T*/"Invoice After Signup"/*/T*/ => array (
                                "type"          =>"yesno",
                                "description"   =>/*T*/"Select YES if you want an invoice sent to the customer after signup is complete."/*/T*/,
                                "value"         =>"1"
            ),
             /*T*/"Use Test Mode"/*/T*/ => array(
                                "type"          =>"yesno",
                                "description"   =>/*T*/"Select YES if you want to use Alertpay in test mode. You need to make sure in your IPN settings of Alertpay you have enabled Test mode"/*/T*/,
                                "value"         =>"0"
            ),
           /*T*/"Check CVV2"/*/T*/ => array (
                                "type"          =>"hidden",
                                "description"   =>/*T*/"Select YES if you want to accept CVV2 for this plugin."/*/T*/,
                                "value"         =>"0"
            )
        );
        return $variables;
    }

    function singlepayment($params, $test = false){
        $this->logger->log(4,print_r("single payment alertpay",true) );
        $this->logger->log(4,print_r($params,true) );
        $currency = new Currency($this->user);
        $userid=$params['plugin_alertpay_User ID'];
        $itemName=$params["companyName"]." - Subscription";
        $currencyType=$params["currencytype"];
        if ($params['isSignup']==1) {
            $returnURL=$params["clientExecURL"]."/signup.php?step=6&pass=1";
            //$returnURL=mb_substr($params['clientExecURL'],-1,1) == "//" ? $params['clientExecURL']."plugins/gateways/alertpay/callback.php" : $params['clientExecURL']."/plugins/gateways/alertpay/callback.php";
            $returnURL_Cancel=$params["clientExecURL"]."/signup.php?step=6&pass=0";
        }else {
            $returnURL=$params["clientExecURL"];
           // $returnURL=mb_substr($params['clientExecURL'],-1,1) == "//" ? $params['clientExecURL']."plugins/gateways/alertpay/callback.php" : $params['clientExecURL']."/plugins/gateways/alertpay/callback.php";
            $returnURL_Cancel=$params["clientExecURL"];
        }
        $amount = $currency->format($params['currencytype'], $params['invoiceTotal'] , false, false);
        $strRet = "<html>\n";
        $strRet .= "<head></head>\n";
        $strRet .= "<body>\n";
        $strRet .= "<form method=\"post\" name=\"frmAlertpay\" action=\"https://www.alertpay.com/PayProcess.aspx\" > ";
        $strRet .= "<input type=\"hidden\" name=\"ap_purchasetype\" value=\"item\"/> ";
        $strRet .= "<input type=\"hidden\" name=\"ap_merchant\" value=\"".$userid."\"/> ";
        $strRet .= "<input type=\"hidden\" name=\"ap_itemname\" value=\"".$itemName."\"/> ";
        $strRet .= "<input type=\"hidden\" name=\"ap_currency\" value=\"".$currencyType."\"/> ";

        //apc_1 stands for the invoice id
        $strRet .= "<input type=\"hidden\" name=\"apc_1\" value=\"".$params['invoiceNumber']."\"/> ";

        $strRet .= "<input type=\"hidden\" name=\"ap_returnurl\" value=\"".$returnURL."\"/> ";
        $strRet .= "<input type=\"hidden\" name=\"ap_quantity\" value=\"1\"/> ";
        $strRet .= "<input type=\"hidden\" name=\"ap_amount\" value=\"".$amount."\"/> ";
        $strRet .= "<input type=\"hidden\" name=\"ap_cancelurl\" value=\"".$returnURL_Cancel."\"/> ";
        $strRet .= "<input type=\"image\" name=\"ap_image\" src=\"https://www.alertpay.com//PayNow/24615329D5CA4035BDD585F0B6BF1A1Da.gif\"/> ";
        $strRet .= "<script language=\"JavaScript\">\n";
        $strRet .= "document.forms['frmAlertpay'].submit();\n";
        $strRet .= "</script>\n";

        $strRet .= "</form> ";
        $strRet .= "</form>\n";
        $strRet .= "</body>\n</html>\n";
        echo $strRet;
        exit;
    }

    function credit($params){
    }
    
}

?>
