Example #1
1
function Process_Transaction($id, $event = "approve", $isonlytest = false, $idfield = 'reference_number')
{
    //approve - declined - rebill
    //refund
    //cancel
    //chargeback
    $trans = getTransactionInfo($id, $isonlytest, $idfield);
    if ($trans == -1) {
        toLog("error", "system", "Process_Transaction Invalid Transaction ID, {$idfield}={$id}, Test={$isonlytest} ", $id);
        return;
    }
    $id = $trans['transactionId'];
    toLog("notify", "system", "Process_Transaction Found Transaction ID, ReferenceId=" . $trans['reference_number'] . ", Test={$isonlytest}, Site ID:" . $trans['cs_ID'] . "  ", $id);
    $password_management_action = NULL;
    $notify_action = NULL;
    if (!strcasecmp($event, "approve")) {
        $password_management_action = "add";
        if (strcasecmp($trans['cs_notify_type'], "both") == 0 || strcasecmp($trans['cs_notify_type'], "approve only") == 0) {
            $notify_action = 1;
        }
    } else {
        if (!strcasecmp($event, "decline")) {
            if (strcasecmp($trans['cs_notify_type'], "both") == 0 || strcasecmp($trans['cs_notify_type'], "decline only") == 0) {
                $notify_action = 1;
            }
        } else {
            if (!strcasecmp($event, "rebill")) {
                if (($trans['cs_notify_event'] & 1) == 1) {
                    $notify_action = 2;
                }
            } else {
                if (!strcasecmp($event, "refund")) {
                    $password_management_action = "delete";
                    if (($trans['cs_notify_event'] & 8) == 8) {
                        $notify_action = 8;
                    }
                } else {
                    if (!strcasecmp($event, "cancellation")) {
                        if (($trans['cs_notify_event'] & 4) == 4) {
                            $notify_action = 4;
                        }
                    } else {
                        if (!strcasecmp($event, "chargeback")) {
                            $password_management_action = "delete";
                            if (($trans['cs_notify_event'] & 16) == 16) {
                                $notify_action = 16;
                            }
                        } else {
                            if (!strcasecmp($event, "revoke")) {
                                $password_management_action = "delete";
                                if (($trans['cs_notify_event'] & 32) == 32) {
                                    $notify_action = 32;
                                }
                            } else {
                                if (!strcasecmp($event, "expiration")) {
                                    $password_management_action = "delete";
                                    if (($trans['cs_notify_event'] & 128) == 128) {
                                        $notify_action = 128;
                                    }
                                } else {
                                    toLog("erroralert", "system", "Process_Transaction FAIL: {$event}", $id);
                                    return 0;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $m = isset($trans['cs_notify_retry']) && $trans['cs_notify_retry'] > -1 ? $trans['cs_notify_retry'] : "0";
    $posturl = $trans['cs_notify_url'];
    $done = 0;
    $succ = array("url" => $posturl, "head" => "Post Notification Not Enabled", "body" => "Post Notification Not Enabled");
    toLog("notify", "system", "Process_Transaction PARAMETERS Notify:{$notify_action} Post URL:{$posturl} PassManage:{$password_management_action} Trans:{$id} Event:{$event}", $id);
    if ($notify_action) {
        $postdata = array();
        switch ($notify_action) {
            case 1:
                //approve decline
                $postdata = Process_Transaction_ApproveDecline($trans);
                $posturl = $trans['cs_notify_url'];
                break;
            case 2:
                //rebill
                $postdata = Process_Transaction_Rebill($trans);
                $posturl = $trans['cs_notify_eventurl'];
                break;
            case 8:
                //refund
                $postdata = Process_Transaction_Refund($trans);
                $posturl = $trans['cs_notify_eventurl'];
                break;
            case 4:
                //cancel
                $postdata = Process_Transaction_Cancellation($trans);
                $posturl = $trans['cs_notify_eventurl'];
                break;
            case 16:
                //chargeback
                $postdata = Process_Transaction_Chargeback($trans);
                $posturl = $trans['cs_notify_eventurl'];
                break;
            case 32:
                //revoke
                $postdata = Process_Transaction_Revoke($trans);
                $posturl = $trans['cs_notify_eventurl'];
                break;
            case 128:
                //expiration
                $postdata = Process_Transaction_Expiration($trans);
                $posturl = $trans['cs_notify_eventurl'];
                break;
            default:
                //error
                break;
        }
        if ($trans['td_merchant_fields']) {
            $merchantvars = unserialize($trans['td_merchant_fields']);
            foreach ($merchantvars as $key => $val) {
                if (!isset($postdata[$key])) {
                    $postdata[$key] = $val;
                }
            }
        }
        $postdata['USERNAME'] = $trans['td_username'];
        $postdata['PASSWORD'] = $trans['td_password'];
        $postdata['FIRSTNAME'] = $trans['name'];
        $postdata['LASTNAME'] = $trans['surname'];
        $postdata['PASSWORD'] = $trans['td_password'];
        $postdata['ADDRESS'] = $trans['address'];
        $postdata['COUNTRY'] = $trans['country'];
        $postdata['CITY'] = $trans['city'];
        $postdata['STATE'] = $trans['state'];
        $postdata['ZIPCODE'] = $trans['zipcode'];
        $postdata['PHONENUMBER'] = $trans['phonenumber'];
        $postdata['EMAIL'] = $trans['email'];
        $postdata['TRANSACTIONDATE'] = $trans['transactionDate'];
        $postquery = "";
        foreach ($postdata as $key => $val) {
            $postquery .= ($postquery == "" ? "" : "&") . "{$key}=" . urlencode($val);
        }
        $parseurl = parse_url($posturl);
        $postmet = $parseurl['scheme'];
        $postser = $parseurl['host'];
        $postport = stristr($postmet, "https") !== FALSE ? "443" : "80";
        $postser = (stristr($postmet, "https") !== FALSE ? "ssl://" : "") . $postser;
        $done = 0;
        if ($isonlytest) {
            $postquery .= "&testmode=true";
        }
        //toLog("notify","system","Posting to: $posturl values: $postquery",$id);
        $succ['body'] = http_post2($postser, $postport, $posturl, $postquery);
        $succ['url'] = $posturl;
        $succ['data'] = $postdata;
        //if($succ < 0)
        $done = 1;
        //could not connect to server
        //else
        //	if(stristr($succ['head'],"HTTP/1.1") === FALSE || stristr($succ['head'],"HTTP/1.0") === FALSE || stristr($succ['head'],"HTTP/1.1 200 OK")!==FALSE || stristr($succ['head'],"HTTP/1.0 200 OK")!==FALSE)
        //		$done = 1; //successfully posted data
        //	else
        //		$done = 0; //problem with destination
        if ($done != 1) {
            toLog("notify", "system", "Notify Error: " . $succ['body'] . " {$posturl} with data {$postquery}", $id);
        } else {
            toLog("notify", "system", "Notify Success: " . $succ['body'] . " {$posturl} with data {$postquery}", $id);
        }
    }
    $ret[0] = array("succeeded" => $done, "response" => $succ);
    if ($password_management_action) {
        $ret[1] = post_passwordmgmt($trans, $password_management_action, $id);
    } else {
        toLog("notify", "system", "Notify No Password Management: {$posturl} with data {$postquery}", $id);
    }
    return $ret;
}
Example #2
0
require_once "includes/dbconnection.php";
$headerInclude = "transactions";
include 'includes/header.php';
require_once 'includes/function.php';
$sessionlogin = isset($HTTP_SESSION_VARS["sessionlogin"]) ? $HTTP_SESSION_VARS["sessionlogin"] : "";
if (isset($_POST['action'])) {
    $site = merchant_getWebSite($sessionlogin, $_POST['cs_id']);
    if ($site != 0 && $site['cs_member_updateurl'] != "") {
        $trans['td_username'] = $_POST['username'];
        $trans['td_password'] = $_POST['password'];
        $trans['cs_notify_retry'] = $site['cs_notify_retry'];
        $trans['cs_member_updateurl'] = $site['cs_member_updateurl'];
        $trans['cs_member_secret'] = $site['cs_member_secret'];
        $trans['amount'] = $_POST['amount'];
        echo "<b>Posting To: " . $trans['cs_member_updateurl'] . "</b><br>";
        $res = post_passwordmgmt($trans, $_POST['action'], true);
        echo "<textarea rows=10 cols=40>" . $res['response']['head'] . "</textarea><br>";
        echo "<textarea rows=10 cols=40>" . $res['response']['body'] . "</textarea><br>";
    } else {
        echo "<p><b>Invalid Site Selected</b></p>";
    }
}
$sites = merchant_getWebSites($sessionlogin);
beginTable();
?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%" height="60%">
	<tr><td>
	<select name="cs_ID" id="cs_ID">
	<option value="">Select Website</option>
	<?php 
echo get_fill_combo_conditionally("SELECT cs_ID,cs_name FROM `cs_company_sites` WHERE `cs_en_ID` = '" . $curUserInfo['en_ID'] . "' AND cs_hide = '0' ORDER BY `cs_name` ASC", $cs_ID);