Beispiel #1
0
if ($databaseName == null || $databaseName == "") {
    die("Invalid parameter databaseName!");
}
if ($campaignId == null || $campaignId == "") {
    die("Invalid parameter campaignId!");
}
/***
Campaign transaction status is the field budget_validated of table PERIODS
    N -> budget not validated
    Y -> the Sales application has accepted the payment from the manager, the campaign is funded

***/
function changeCampaignStatus($campaign_id, $new_validated_status, $instance)
{
    $filter = "";
    $periodFilter = PERIODS . ".`id` = {$campaign_id} ";
    $filter = " AND NOT budget_validated = 'Y' ";
    $sql = "UPDATE {$instance}." . PERIODS . ",{$instance}." . USER_REVIEWS . " SET `budget_validated` = '{$new_validated_status}' WHERE " . USER_REVIEWS . ".period_id = " . PERIODS . ".id AND {$periodFilter} {$filter}";
    $ret = mysql_unbuffered_query($sql);
    if ($ret) {
        if (mysql_affected_rows() == 1) {
            return "Payment accepted.";
        } else {
            return "Period was already funded.";
        }
    } else {
        return 'error SQL in changeCampaignStatus' . mysql_error();
    }
}
$ret = changeCampaignStatus($campaignId, "Y", $databaseName);
echo $ret;
Beispiel #2
0
function sendCCPayment($domain, $databaseName, $fname, $lname, $company, $ref_ids, $email, $phone, $street, $city, $state, $zip, $country, $card_type, $card_number, $cvv, $exp_date, $total, $sub_amt, $can_contact, $ip, $lm_type, $lm_description, $lm_user_id)
{
    //collect confirmed payees and run paypal transaction
    // Set request-specific fields.
    $currency = 'USD';
    // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
    //build nvp string
    $nvp = '';
    $nvp .= '&PAYMENTACTION=Sale';
    $nvp .= '&IPADDRESS=' . urlencode($ip);
    $nvp .= '&AMT=' . urlencode($total);
    $nvp .= '&CURRENCYCODE=' . urlencode($currency);
    $nvp .= '&CREDITCARDTYPE=' . urlencode($card_type);
    $nvp .= '&ACCT=' . urlencode($card_number);
    $nvp .= '&EXPDATE=' . urlencode($exp_date);
    $nvp .= '&CVV2=' . urlencode($cvv);
    $nvp .= '&FIRSTNAME=' . urlencode($fname);
    $nvp .= '&LASTNAME=' . urlencode($lname);
    $nvp .= '&STREET=' . urlencode($street);
    $nvp .= '&CITY=' . urlencode($city);
    $nvp .= '&STATE=' . urlencode($state);
    $nvp .= '&ZIP=' . urlencode($zip);
    $nvp .= '&COUNTRYCODE=' . urlencode($country);
    // store customer data if required, return customer_id for payment
    $cust = storeCustomerData($domain, $fname, $lname, $company, $ref_ids, $email, $phone, $street, $city, $state, $zip, $country, $can_contact);
    if (isset($cust["error"])) {
        return array('error' => "Buyer", 'errorMsg' => "Error in Buyer Creation: " . $cust["error"]);
    } else {
        $cust = $cust['customer_id'];
    }
    $buyer = storeBuyerData($cust, $fname, $lname, $company, $email, $phone, $street, $city, $state, $zip, $country);
    if (isset($ret["error"])) {
        return array('error' => "Buyer", 'errorMsg' => "Error in Buyer Creation: " . $ret["error"]);
    }
    $buyer_id = $buyer["buyer_id"];
    //  $instance = getInstanceNameFromDomain($domain);
    $instance = $databaseName;
    if ($instance == "") {
        return array('error' => "Invalid domain", 'errorMsg' => "Invalid domain: " . $domain);
    }
    $ret = changeCampaignStatus($ref_ids, "R", $instance);
    if (isset($ret["error"])) {
        return array('error' => "Recognition", 'errorMsg' => "Error in Recognition Period Update (R): " . $ret["error"]);
    }
    // Execute the API operation; see the PPHttpPost function in the paypal-functions.php file.
    $PPResponseAr = PPHttpPost('DoDirectPayment', $nvp);
    $warningMsg = "";
    if (isset($PPResponseAr["ACK"])) {
        $transactionID = "";
        if (isset($PPResponseAr["TRANSACTIONID"])) {
            $transactionID = $PPResponseAr["TRANSACTIONID"];
        }
        $longMessage = "";
        if (isset($PPResponseAr["L_LONGMESSAGE0"])) {
            $longMessage = urldecode($PPResponseAr["L_LONGMESSAGE0"]);
        }
        $save = storePaymentData($cust, $card_type, $PPResponseAr["ACK"], $total, $sub_amt, $transactionID, $ip, $lm_type, $domain, $ref_ids, $lm_description, $lm_user_id, $buyer_id, $longMessage);
        if (isset($save['error'])) {
            $payment = -1;
            $warningMsg .= '<p>Warning: ' . $save['error'] . "</p>";
        } else {
            $payment = $save['payment_id'];
        }
    }
    if (isset($PPResponseAr["ACK"]) && ("SUCCESS" == strtoupper($PPResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($PPResponseAr["ACK"]))) {
        $ret = changeCampaignStatus($ref_ids, "Y", $instance);
        if (isset($ret["error"])) {
            $warningMsg .= "<p>Warning: Error in Recognition Period Update (Y), " . $ret["error"] . "</p>";
        }
        $invoice = 1000000 + intval($payment);
        $invoice = $cust . '' . $invoice;
        //payment posted
        /**
         *   $PPResponseAr["TIMESTAMP"] 
         *   $PPResponseAr["CORRELATIONID"]
         *   $PPResponseAr["ACK"]
         *   $PPResponseAr["VERSION"] 
         *   $PPResponseAr["BUILD"]
         *   $PPResponseAr["AMT"]
         *   $PPResponseAr["CURRENCYCODE"] 
         *   $PPResponseAr["AVSCODE"] //X 
         *   $PPResponseAr["CVV2MATCH"]  //M
         *   $PPResponseAr["TRANSACTIONID"]
         */
        $name = $fname . ' ' . $lname;
        success_notify($name, $email, $company, $street, $city, $state, $zip, $country, $phone, $lm_description, $total, $invoice, $PPResponseAr["TRANSACTIONID"]);
        $messJournal = "A payment has been made for a Recognition Period!";
        if ("SUCCESSWITHWARNING" == strtoupper($PPResponseAr["ACK"])) {
            $messJournal .= " Warning in Paypal transaction.";
        }
        // Make a notice in journal
        $data = array('user' => JOURNAL_API_USER, 'pwd' => sha1(JOURNAL_API_PWD), 'message' => $messJournal);
        ob_start();
        $res = CURLHandler::Post(JOURNAL_API_URL, $data);
        ob_end_clean();
        $ret = array('success' => strtoupper($PPResponseAr["ACK"]), 'transactionID' => $PPResponseAr["TRANSACTIONID"], 'warning' => $warningMsg);
    } else {
        // We are not in an asynchronous process so put back the campaign in card
        $ret = changeCampaignStatus($ref_ids, "C", $instance);
        if (isset($ret["error"])) {
            $warningMsg .= "<p>Warning: Error in Recognition Period Update (N), " . $ret["error"] . "</p>";
        }
        if (isset($PPResponseAr["L_SEVERITYCODE0"])) {
            $errorMsg = $PPResponseAr["ACK"] . ", " . $PPResponseAr["L_SEVERITYCODE0"] . ': ' . urldecode($PPResponseAr["L_SHORTMESSAGE0"]) . ' (' . $PPResponseAr["L_ERRORCODE0"] . ') - ' . urldecode($PPResponseAr["L_LONGMESSAGE0"]) . $warningMsg;
        } else {
            $errorMsg = $PPResponseAr["ACK"] . ", " . $PPResponseAr["errorMsg"] . $warningMsg;
        }
        fail_notify($fname . ' ' . $lname, $email, $company, $street, $city, $state, $zip, $country, $phone, $lm_description, $total, $errorMsg);
        if (isset($PPResponseAr["L_SEVERITYCODE0"])) {
            $ret = array('error' => $PPResponseAr["L_ERRORCODE0"], 'errorMsg' => $errorMsg);
        } else {
            $ret = array('error' => $PPResponseAr["ACK"], 'errorMsg' => $errorMsg);
        }
    }
    return $ret;
}