Example #1
0
        ipnLog("empty response");
        die;
    }
    if (isset($response['error'])) {
        ipnLog("error");
        ipnLog(json_encode($response));
        die;
    }
    $notification = $response['notification'];
    $customer = $response['customer'];
    $trasaction = $response['transaction'];
    //ipnLog("....");
    //ipnLog(json_encode($notification));
    addNotification($notification);
    addCustomer($customer);
    addTransaction($trasaction);
}
/**
 * @param String $data
 */
function ipnLog($data)
{
    //Check log.log file permissions
    $date = date('Y-m-d H:i');
    file_put_contents("log.log", "[" . $date . "]" . $data . " \n", FILE_APPEND);
}
function addNotification($notification)
{
    $params = array('id' => null, 'txn_id' => $notification->getTxnId(), 'txn_type' => $notification->getTxnType(), 'receiver_email' => $notification->getReceiverEmail(), 'payment_status' => $notification->getPaymentStatus(), 'pending_reason' => $notification->getPendingReason(), 'reason_code' => $notification->getReasonCode(), 'custom' => $notification->getCustom(), 'invoice' => $notification->getInvoice());
    insert('notification', $params);
}
Example #2
0
    $amount = format_as_currency($amount);
    insert_query("tblaffiliateshistory", array("affiliateid" => $id, "date" => toMySQLDate($date), "affaccid" => $refid, "description" => $description, "amount" => $amount));
    update_query("tblaffiliates", array("balance" => "+=" . $amount), array("id" => (int) $id));
    redir("action=edit&id=" . $id);
    exit;
}
if ($action == "withdraw") {
    check_token("WHMCS.admin.default");
    insert_query("tblaffiliateswithdrawals", array("affiliateid" => $id, "date" => "now()", "amount" => $amount));
    update_query("tblaffiliates", array("balance" => "-=" . $amount, "withdrawn" => "+=" . $amount), array("id" => (int) $id));
    if ($payouttype == "1") {
        $result = select_query("tblaffiliates", "", array("id" => (int) $id));
        $data = mysql_fetch_array($result);
        $id = (int) $data['id'];
        $clientid = (int) $data['clientid'];
        addTransaction($clientid, "", "Affiliate Commissions Withdrawal Payout", "0", "0", $amount, $paymentmethod, $transid);
    } else {
        if ($payouttype == "2") {
            $result = select_query("tblaffiliates", "", array("id" => (int) $id));
            $data = mysql_fetch_array($result);
            $id = (int) $data['id'];
            $clientid = (int) $data['clientid'];
            insert_query("tblcredit", array("clientid" => $clientid, "date" => "now()", "description" => "Affiliate Commissions Withdrawal", "amount" => $amount));
            update_query("tblclients", array("credit" => "+=" . $amount), array("id" => $clientid));
            logActivity("Processed Affiliate Commissions Withdrawal to Credit Balance - User ID: " . $clientid . " - Amount: " . $amount);
        }
    }
    redir("action=edit&id=" . $id);
    exit;
}
if ($sub == "delete") {
$aInt->requiredFiles(array("gatewayfunctions", "invoicefunctions"));
$aInt->valUserID($userid);
if ($sub == "add") {
    check_token("WHMCS.admin.default");
    if ($invoiceid) {
        $transuserid = get_query_val("tblinvoices", "userid", array("id" => $invoiceid));
        if (!$transuserid) {
            redir("error=invalidinvid");
        } else {
            if ($transuserid != $userid) {
                redir("error=wronguser");
            }
        }
        addInvoicePayment($invoiceid, $transid, $amountin, $fees, $paymentmethod, "", $date);
    } else {
        addTransaction($userid, 0, $description, $amountin, $fees, $amountout, $paymentmethod, $transid, $invoiceid, $date);
    }
    if ($addcredit) {
        if ($transid) {
            $description .= " (Trans ID: " . $transid . ")";
        }
        insert_query("tblcredit", array("clientid" => $userid, "date" => toMySQLDate($date), "description" => $description, "amount" => $amountin));
        update_query("tblclients", array("credit" => "+=" . $amountin), array("id" => (int) $userid));
    }
    redir("userid=" . $userid);
    exit;
}
if ($sub == "save") {
    check_token("WHMCS.admin.default");
    update_query("tblaccounts", array("gateway" => $paymentmethod, "date" => toMySQLDate($date), "description" => $description, "amountin" => $amountin, "fees" => $fees, "amountout" => $amountout, "transid" => $transid, "invoiceid" => $invoiceid), array("id" => $id));
    logActivity("Modified Transaction (User ID: " . $userid . " - Transaction ID: " . $id . ")");
Example #4
0
} else {
    $reqperm = "List Transactions";
}
$aInt = new WHMCS_Admin($reqperm);
$aInt->title = $aInt->lang("transactions", "title");
$aInt->sidebar = "billing";
$aInt->icon = "transactions";
$aInt->requiredFiles(array("gatewayfunctions", "invoicefunctions"));
if ($action == "add") {
    check_token("WHMCS.admin.default");
    checkPermission("Add Transaction");
    if ($client) {
        $currency = 0;
    }
    if (!$invoiceids) {
        addTransaction($client, $currency, $description, $amountin, $fees, $amountout, $paymentmethod, $transid, $invoiceid, $date);
        if ($client && $addcredit) {
            if ($transid) {
                $description .= " (" . $aInt->lang("transactions", "transid") . (": " . $transid . ")");
            }
            insert_query("tblcredit", array("clientid" => $client, "date" => toMySQLDate($date), "description" => $description, "amount" => $amountin));
            update_query("tblclients", array("credit" => "+=" . $amountin), array("id" => (int) $client));
        }
    } else {
        $invoiceids = trim($invoiceids);
        if (substr($invoiceids, 0 - 1) == ",") {
            $invoiceids = substr($invoiceids, 0, 0 - 1);
        }
        $query = select_query("tblinvoices", "SUM(total)", "id IN (" . $invoiceids . ")");
        $data = mysql_fetch_assoc($query);
        $invoicestotal = $data[0];
Example #5
0
     break;
 case 5:
     //sends sms to get stock level
     getStock();
     break;
 case 6:
     //generate random id for transaction
     generate_random_password(5);
     break;
 case 7:
     //add sale to db
     addSale();
     break;
 case 8:
     //all transaction to db
     addTransaction();
     break;
 case 9:
     //get all purchases with a given transaction id
     displaySale();
     break;
 case 10:
     //set the total value of a transaction
     setTotal();
     break;
 case 11:
     //display all transactions
     allTransaction();
     break;
 case 12:
     deleteSale();
<?php

include 'db_helper.php';
if ($_GET['f'] == 'add' && $_GET['sid'] && $_GET['tid'] && $_GET['class'] && $_GET['duration']) {
    addTransaction($_GET['sid'], $_GET['tid'], $_GET['class'], $_GET['duration']);
} elseif ($_GET['f'] == 'get' && $_GET['p1']) {
    getTransaction($_GET['p1']);
} elseif ($_GET['f'] == 'upd' && $_GET['p1'] && $_GET['p2'] && $_GET['p3'] && $_GET['p4']) {
    updateTransaction($_GET['p1'], $_GET['p2'], $_GET['p3'], $_GET['p4']);
} elseif ($_GET['f'] == 'list' && $_GET['sid'] && $_GET['con']) {
    listTransaction($_GET['sid'], $_GET['con']);
} elseif ($_GET['f'] == 'list' && $_GET['tid'] && $_GET['con']) {
    listTransactionWithTutorID($_GET['tid'], $_GET['con']);
} elseif ($_GET['f'] == 'con' && $_GET['tid'] && $_GET['sid'] && $_GET['rate'] && $_GET['class']) {
    confirmTrasaction($_GET['tid'], $_GET['sid'], $_GET['rate'], $_GET['class']);
}
function confirmTrasaction($tid, $sid, $rate, $class)
{
    $dbQuery = sprintf("UPDATE Transaction SET rate='%d', Confirmed = '%d' WHERE S_ID = '%d'AND T_ID = '%d' AND Class = '%d'", $rate, 1, $sid, $tid, $class);
    $result = getDBResultAffected($dbQuery);
    //header("Content-type: application/json");
    echo json_encode($result);
}
function getTransaction($email)
{
    $dbQuery = sprintf("SELECT name FROM Transaction WHERE email = '%s'", mysql_real_escape_string($email));
    //
    $result = getDBResultRecord($dbQuery);
    //header("Content-type: application/json");
    echo json_encode($result);
}
Example #7
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;
}
Example #8
0
 * DATABASE CREDENTIALS
 * --------------------
 */
$dbhost = 'localhost';
$dbuser = '******';
$dbpass = '******';
$dbname = 'checking';
/*
 * HANDLE HTTP REQUESTS
 * --------------------
 */
// Handle POST request to set starting amount
if (isset($_POST['txtStartingAmount'])) {
    $startingAmount = $_POST['txtStartingAmount'];
    $conn = connectDatabase();
    addTransaction("Starting Amount", $startingAmount, $startingAmount);
    mysql_close($conn);
}
/*
 * HELPER FUNCTIONS
 * ----------------
 */
function connectDatabase($host, $user, $pass)
{
    global $dbhost, $dbuser, $dbpass, $dbname;
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if (!$conn) {
        die('Could not connect: ' . mysql_error());
    }
    $res = mysql_query(sprintf("USE %s", $dbname));
    return $conn;
Example #9
0
         addNotification($_POST['sent_to'], $text, $_SESSION['uid'], $url);
     } else {
         deleteSuggestion($_POST['project_id'], $_POST['sent_to'], $_SESSION['uid']);
     }
     $responce['result'] = 'OK';
     echo json_encode($responce);
     break;
 case 'add-transaction':
     require_once DIR_APP . 'users.php';
     require_once DIR_APP . 'projects.php';
     $project_id = $_POST['project_id'];
     $project_title = $_POST['project_title'];
     $user_id = $_SESSION['uid'];
     $author_id = $_POST['created_by'];
     $amount = $_POST['amount'];
     addTransaction($user_id, $amount, $project_title, $project_id, $author_id);
     $responce['result'] = 'OK';
     echo json_encode($responce);
     break;
 case 'notifyOwner':
     require_once DIR_APP . 'users.php';
     require_once DIR_APP . 'projects.php';
     $project_id = $_POST['project_id'];
     $project_title = $_POST['project_title'];
     $user_id = $_SESSION['uid'];
     $author_id = $_POST['created_by'];
     $user_name = getUserNameById($_SESSION['uid']);
     $url = SITE_URL . '/home.php?iid=' . $project_id;
     $text = $user_name . ' wants to view your project ' . $project_title;
     addNotification($author_id, $text, $user_id, $url);
     $responce['result'] = 'OK';
Example #10
0
function createTestRelease($release, $testProjectID)
{
    $connID = connectTLDB();
    $sql = "insert " . "into " . "nodes_hierarchy " . "(name, parent_id, node_type_id, node_order) " . "values ('" . $release . "', " . $testProjectID . ", " . "5, " . "0 " . ")";
    $rs = mysql_query($sql);
    // retrieve new planID
    $sql = "select " . "id " . "from " . "nodes_hierarchy " . "where " . "name='" . $release . "' and " . "parent_id =" . $testProjectID . " and " . "node_type_id=5";
    $rs = mysql_query($sql);
    if (mysql_num_rows($rs)) {
        $row = mysql_fetch_array($rs);
        $releaseID = $row[0];
    } else {
        $releaseID = "NOT_FOUND";
    }
    // if release entry created, add new TP entry
    if ($releaseID != "NOT_FOUND") {
        $sql = "insert " . "into " . "testplans " . "(id, testproject_id) " . "values ('" . $releaseID . "', " . $testProjectID . ")";
        $rs = mysql_query($sql);
        // retrieve new planID
        $sql = "select " . "id " . "from " . "testplans " . "where " . "id=" . $releaseID . " and " . "testproject_id =" . $testProjectID;
        $rs = mysql_query($sql);
        if (mysql_num_rows($rs)) {
            $row = mysql_fetch_array($rs);
            $releaseID = $row[0];
            $transID = addTransaction();
            if ($transID == "NOT_FOUND") {
                mysql_close($connID);
                return "NOT_FOUND";
            }
            $eventID = addEvent($transID, $release, $releaseID);
            if ($eventID == "NOT_FOUND") {
                mysql_close($connID);
                return "NOT_FOUND";
            } else {
                return $releaseID;
            }
        } else {
            $releaseID = "NOT_FOUND";
            mysql_close($connID);
            return $releaseID;
        }
    }
}