$data = mysql_fetch_array($result);
$echoData = $data['data'];
$result = select_query("tblgatewaylog", "data", array("gateway" => "WPICPDATA" . $invoiceid));
$data = mysql_fetch_array($result);
$cvv = $data['data'];
if (!$echoData) {
    logTransaction("WorldPay Invisible XML Callback", $_REQUEST, "echoData Not Found");
    echo "An Error Occurred. Please Contact Support.";
    exit;
} else {
    logTransaction("WorldPay Invisible XML Callback", $_REQUEST, "Received");
}
delete_query("tblgatewaylog", array("gateway" => "WPIECHODATA" . $invoiceid));
delete_query("tblgatewaylog", array("gateway" => "WPIORDERCODE" . $invoiceid));
delete_query("tblgatewaylog", array("gateway" => "WPICPDATA" . $invoiceid));
getCCVariables($invoiceid);
if ($params['cardtype'] == "American Express") {
    $merchantCode = $params['merchantcodeamex'];
} else {
    $merchantCode = $params['merchantcode1'];
}
$password = $params['merchantpw'];
$instId = $params['instid'];
$cookiestore = $params['cookiestore'];
$orderDescription = "Invoice #" . $params['invoiceid'];
$orderAmount = $params['amount'] * 100;
$raworderAmount = $params['amount'];
$invoiceID = $params['invoiceid'];
$orderShopperEmail = $params['clientdetails']['email'];
$orderShopperID = $params['clientdetails']['userid'];
$orderShopperFirstName = $params['clientdetails']['firstname'];
Example #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;
}
Example #3
0
     $result = payflowpro_capture($params, $auth);
     if ($result['status'] == "success") {
         logTransaction("PayFlow Pro 3D Capture", $result['rawdata'], "Successful");
         addInvoicePayment($invoiceid, $result['transid'], "", "", "payflowpro", "on");
         sendMessage("Credit Card Payment Confirmation", $invoiceid);
         $callbacksuccess = true;
     } else {
         logTransaction("PayFlow Pro 3D Capture", $result['rawdata'], "Failed");
     }
 } else {
     if (strcasecmp("N", $paresstatus) == 0) {
         logTransaction("PayFlow Pro 3D Secure Callback", $_REQUEST, "Auth Failed");
     } else {
         logTransaction("PayFlow Pro 3D Secure Callback", $_REQUEST, "Unexpected Status, Capture Anyway");
         $auth = array("paresstatus" => $paresstatus, "cavv" => $cavv, "eciflag" => $eciflag, "xid" => $xid);
         $params = getCCVariables($invoiceid);
         if (isset($_SESSION['Centinel_Details'])) {
             $params['cardtype'] = $_SESSION['Centinel_Details']['cardtype'];
             $params['cardnum'] = $_SESSION['Centinel_Details']['cardnum'];
             $params['cardexp'] = $_SESSION['Centinel_Details']['cardexp'];
             $params['cccvv'] = $_SESSION['Centinel_Details']['cccvv'];
             $params['cardstart'] = $_SESSION['Centinel_Details']['cardstart'];
             $params['cardissuenum'] = $_SESSION['Centinel_Details']['cardissuenum'];
             unset($_SESSION['Centinel_Details']);
         }
         $result = payflowpro_capture($params, $auth);
         if ($result['status'] == "success") {
             logTransaction("PayFlow Pro 3D Capture", $result['rawdata'], "Successful");
             addInvoicePayment($invoiceid, $result['transid'], "", "", "payflowpro", "on");
             sendMessage("Credit Card Payment Confirmation", $invoiceid);
             $callbacksuccess = true;
Example #4
0
function captureCCPayment($invoiceid, $cccvv = "", $passedparams = false)
{
    global $params;
    if (!$passedparams) {
        $params = getCCVariables($invoiceid);
    }
    if ($cccvv) {
        $params['cccvv'] = $cccvv;
    }
    if ($params['paymentmethod'] == "offlinecc") {
        return false;
    }
    if (!$params['cardnum'] && !$params['gatewayid'] && !$params['cccvv']) {
        sendMessage("Credit Card Payment Due", $invoiceid);
    } else {
        $captureresult = call_user_func($params['paymentmethod'] . "_capture", $params);
        if (is_array($captureresult)) {
            $result = select_query("tblpaymentgateways", "value", array("gateway" => $params['paymentmethod'], "setting" => "name"));
            $data = mysql_fetch_array($result);
            $gatewayname = $data['value'];
            logTransaction($gatewayname, $captureresult['rawdata'], ucfirst($captureresult['status']));
            if ($captureresult['status'] == "success") {
                addInvoicePayment($params['invoiceid'], $captureresult['transid'], $params['originalamount'], $captureresult['fee'], $params['paymentmethod'], "on");
                sendMessage("Credit Card Payment Confirmation", $params['invoiceid']);
                return true;
            }
            sendMessage("Credit Card Payment Failed", $params['invoiceid']);
        } else {
            if ($captureresult == "success") {
                return true;
            }
        }
    }
    return false;
}