Esempio n. 1
0
function getGatewayVariables($gateway, $invoiceid = "", $amount = "0.00")
{
    global $whmcs;
    global $CONFIG;
    global $_LANG;
    global $clientsdetails;
    $res = loadGatewayModule($gateway);
    if (!$res) {
        exit("Gateway Module '" . $gateway . "' is Missing or Invalid");
    }
    $gateway = WHMCS_Gateways::makesafename($gateway);
    if (!function_exists($gateway . "_link")) {
        eval("function " . $gateway . "_link({$params}) { return '<form method=\"post\" action=\"" . $params['systemurl'] . "/creditcard.php\" name=\"paymentfrm\"><input type=\"hidden\" name=\"invoiceid\" value=\"" . $params['invoiceid'] . "\"><input type=\"submit\" value=\"" . $params['langpaynow'] . "\"></form>'; }");
    }
    $GATEWAY = array();
    $GATEWAY['paymentmethod'] = $gateway;
    $result = select_query("tblpaymentgateways", "", array("gateway" => $gateway));
    while ($data = mysql_fetch_array($result)) {
        $gVgwsetting = $data['setting'];
        $gVgwvalue = $data['value'];
        $GATEWAY["" . $gVgwsetting] = "" . $gVgwvalue;
    }
    $GATEWAY['companyname'] = $CONFIG['CompanyName'];
    if ($CONFIG['SystemSSLURL']) {
        $GATEWAY['systemurl'] = $CONFIG['SystemSSLURL'];
    } else {
        $GATEWAY['systemurl'] = $CONFIG['SystemURL'];
    }
    $GATEWAY['returnurl'] = $GATEWAY['systemurl'];
    $GATEWAY['langpaynow'] = $_LANG['invoicespaynow'];
    if ($invoiceid) {
        $clientsdetails['fullstate'] = $clientsdetails['state'];
        if (!function_exists("convertStateToCode")) {
            require ROOTDIR . "/includes/clientfunctions.php";
        }
        $clientsdetails['state'] = convertStateToCode($clientsdetails['state'], $clientsdetails['country']);
        $result = select_query("tblclients", "tblinvoices.invoicenum,tblclients.currency,tblcurrencies.code", array("tblinvoices.id" => $invoiceid), "", "", "", "tblinvoices ON tblinvoices.userid=tblclients.id INNER JOIN tblcurrencies ON tblcurrencies.id=tblclients.currency");
        $data = mysql_fetch_array($result);
        $invoicenum = $data['invoicenum'];
        $invoice_currency_id = $data['currency'];
        $invoice_currency_code = $data['code'];
        if (!trim($invoicenum)) {
            $invoicenum = $invoiceid;
        }
        $GATEWAY['description'] = $CONFIG['CompanyName'] . " - " . $_LANG['invoicenumber'] . $invoicenum;
        $GATEWAY['invoiceid'] = $invoiceid;
        $GATEWAY['clientdetails'] = $clientsdetails;
        $GATEWAY['returnurl'] = $GATEWAY['systemurl'] . "/viewinvoice.php?id=" . $invoiceid;
        if ($GATEWAY['convertto']) {
            $result = select_query("tblcurrencies", "code", array("id" => $GATEWAY['convertto']));
            $data = mysql_fetch_array($result);
            $converto_currency_code = $data['code'];
            $converto_amount = convertCurrency($amount, $invoice_currency_id, $GATEWAY['convertto']);
            $GATEWAY['amount'] = format_as_currency($converto_amount);
            $GATEWAY['currency'] = $converto_currency_code;
            $GATEWAY['basecurrencyamount'] = format_as_currency($amount);
            $GATEWAY['basecurrency'] = $invoice_currency_code;
        }
        if (!$GATEWAY['currency']) {
            $GATEWAY['amount'] = format_as_currency($amount);
            $GATEWAY['currency'] = $invoice_currency_code;
        }
    }
    return $GATEWAY;
}
Esempio n. 2
0
function refundInvoicePayment($transid, $amount, $sendtogateway, $addascredit = "", $sendemail = true, $refundtransid = "")
{
    $result = select_query("tblaccounts", "", array("id" => $transid));
    $data = mysql_fetch_array($result);
    $transid = $data['id'];
    if (!$transid) {
        return "amounterror";
    }
    $userid = $data['userid'];
    $invoiceid = $data['invoiceid'];
    $gateway = $data['gateway'];
    $fullamount = $data['amountin'];
    $fees = $data['fees'];
    $gatewaytransid = $data['transid'];
    $rate = $data['rate'];
    $gateway = WHMCS_Gateways::makesafename($gateway);
    $result = select_query("tblaccounts", "SUM(amountout),SUM(fees)", array("refundid" => $transid));
    $data = mysql_fetch_array($result);
    $alreadyrefunded = $data[0];
    $alreadyrefundedfees = $data[1];
    $fullamount -= $alreadyrefunded;
    $fees -= $alreadyrefundedfees * (0 - 1);
    if ($fees <= 0) {
        $fees = 0;
    }
    $result = select_query("tblaccounts", "SUM(amountin),SUM(amountout)", array("invoiceid" => $invoiceid));
    $data = mysql_fetch_array($result);
    $invoicetotalpaid = $data[0];
    $invoicetotalrefunded = $data[1];
    if (!$amount) {
        $amount = $fullamount;
    }
    if (!$amount || $fullamount < $amount) {
        return "amounterror";
    }
    $amount = format_as_currency($amount);
    if ($addascredit) {
        addTransaction($userid, 0, "Refund of Transaction ID " . $gatewaytransid . " to Credit Balance", 0, $fees * (0 - 1), $amount, "", "", $invoiceid, "", $transid, $rate);
        addTransaction($userid, 0, "Credit from Refund of Invoice ID " . $invoiceid, $amount, $fees, 0, "", "", "", "", "", "");
        logActivity("Refunded Invoice Payment to Credit Balance - Invoice ID: " . $invoiceid, $userid);
        insert_query("tblcredit", array("clientid" => $userid, "date" => "now()", "description" => "Credit from Refund of Invoice ID " . $invoiceid, "amount" => $amount));
        update_query("tblclients", array("credit" => "+=" . $amount), array("id" => (int) $userid));
        if ($invoicetotalpaid - $invoicetotalrefunded - $amount <= 0) {
            update_query("tblinvoices", array("status" => "Refunded"), array("id" => $invoiceid));
            run_hook("InvoiceRefunded", array("invoiceid" => $invoiceid));
        }
        if ($sendemail) {
            sendMessage("Invoice Refund Confirmation", $invoiceid, array("invoice_refund_type" => "credit"));
        }
        return "creditsuccess";
    }
    $result = select_query("tblpaymentgateways", "value", array("gateway" => $gateway, "setting" => "convertto"));
    $data = mysql_fetch_array($result);
    $convertto = $data['value'];
    if ($convertto) {
        $result = select_query("tblclients", "currency", array("id" => $userid));
        $data = mysql_fetch_array($result);
        $fromcurrencyid = $data['currency'];
        $convertedamount = convertCurrency($amount, $fromcurrencyid, $convertto, $rate);
    }
    if ($gateway) {
        $params = getCCVariables($invoiceid);
    }
    if ($sendtogateway && function_exists($gateway . "_refund")) {
        $params['amount'] = $convertedamount ? $convertedamount : $amount;
        $params['transid'] = $gatewaytransid;
        $params['paymentmethod'] = $gateway;
        $gatewayresult = call_user_func($gateway . "_refund", $params);
        $refundtransid = $gatewayresult['transid'];
        $rawdata = $gatewayresult['rawdata'];
        if (isset($gatewayresult['fees'])) {
            $fees = $gatewayresult['fees'];
        }
        $gatewayresult = $gatewayresult['status'];
        $result = select_query("tblpaymentgateways", "value", array("gateway" => $gateway, "setting" => "name"));
        $data = mysql_fetch_array($result);
        $gatewayname = $data['value'];
        logTransaction($gatewayname . " Refund", $rawdata, ucfirst($gatewayresult));
    } else {
        $gatewayresult = "manual";
        run_hook("ManualRefund", array("transid" => $transid, "amount" => $amount));
    }
    if ($gatewayresult == "success" || $gatewayresult == "manual") {
        addTransaction($userid, 0, "Refund of Transaction ID " . $gatewaytransid, 0, $fees * (0 - 1), $amount, $gateway, $refundtransid, $invoiceid, "", $transid, $rate);
        logActivity("Refunded Invoice Payment - Invoice ID: " . $invoiceid . " - Transaction ID: " . $transid, $userid);
        $result = select_query("tblinvoices", "total", array("id" => $invoiceid));
        $data = mysql_fetch_array($result);
        $invoicetotal = $data[0];
        if ($invoicetotalpaid - $invoicetotalrefunded - $amount <= 0) {
            update_query("tblinvoices", array("status" => "Refunded"), array("id" => $invoiceid));
            run_hook("InvoiceRefunded", array("invoiceid" => $invoiceid));
        }
        if ($sendemail) {
            sendMessage("Invoice Refund Confirmation", $invoiceid, array("invoice_refund_type" => "gateway"));
        }
    }
    return $gatewayresult;
}
Esempio n. 3
0
             exit("Invalid Payment Gateway Name");
         }
         $gatewaypath = ROOTDIR . "/modules/gateways/" . $paymentmethod . ".php";
         if (file_exists($gatewaypath)) {
             require_once $gatewaypath;
         }
         if (!function_exists($paymentmethod . "_link")) {
             redir("invoiceid=" . (int) $invoiceid, "creditcard.php");
         }
     }
     $result = select_query("tblinvoices", "", array("userid" => $client->getID(), "id" => $invoiceid));
     $data = mysql_fetch_array($result);
     $id = $data['id'];
     $total = $data['total'];
     $paymentmethod = $data['paymentmethod'];
     $paymentmethod = WHMCS_Gateways::makesafename($paymentmethod);
     $clientsdetails = getClientsDetails($client->getID());
     $params = getGatewayVariables($paymentmethod, $id, $total);
     $paymentbutton = call_user_func($paymentmethod . "_link", $params);
     $ca->setTemplate("forwardpage");
     $ca->assign("message", $_LANG['forwardingtogateway']);
     $ca->assign("code", $paymentbutton);
     $ca->assign("invoiceid", $id);
     $ca->output();
     exit;
 }
 $smartyvalues['subtotal'] = formatCurrency($subtotal);
 if ($credit) {
     $smartyvalues['credit'] = formatCurrency($credit);
 }
 if ($tax) {