Пример #1
0
 $itnVerifyRequest = implode('&', $itnPostDataValuePairs);
 if (!pfValidData($pfHost, $itnVerifyRequest, "{$pfHost}/eng/query/validate")) {
     pflog("ITN mismatch for {$itnVerifyRequest}\n");
     pflog('ITN not OK');
     $error = true;
     return false;
 }
 pflog('ITN OK');
 pflog("ITN verified for {$itnVerifyRequest}\n");
 if ($error == false and $_POST['payment_status'] == "COMPLETE") {
     $user_id = intval($_POST['custom_int1']);
     $mc_gross = $_POST['amount_gross'];
     $membership_id = $_POST['m_payment_id'];
     $txn_id = $_POST['pf_payment_id'];
     $total = Core::getCart($user_id);
     $v1 = compareFloatNumbers($mc_gross, $total->totalprice, "=");
     if ($v1 == true) {
         $row = $db->first("SELECT * FROM " . Membership::mTable . " WHERE id=" . (int) $membership_id);
         $username = getValueById("username", Users::uTable, (int) $user_id);
         $data = array('txn_id' => $txn_id, 'membership_id' => $row->id, 'user_id' => (int) $user_id, 'rate_amount' => $total->originalprice, 'tax' => $total->totaltax, 'coupon' => $total->coupon, 'total' => $total->totalprice, 'ip' => $_SERVER['REMOTE_ADDR'], 'created' => "NOW()", 'pp' => "PayFast", 'currency' => "ZAR", 'status' => 1);
         $db->insert(Membership::pTable, $data);
         $udata = array('membership_id' => $row->id, 'mem_expire' => $user->calculateDays($row->id), 'trial_used' => $row->trial == 1 ? 1 : 0, 'memused' => 1);
         $db->update(Users::uTable, $udata, "id=" . (int) $user_id);
         /* == Notify Administrator == */
         require_once BASEPATH . "lib/class_mailer.php";
         $row2 = Core::getRowById(Content::eTable, 5);
         $body = str_replace(array('[USERNAME]', '[ITEMNAME]', '[PRICE]', '[STATUS]', '[PP]', '[IP]'), array($username, $row->title, $core->formatMoney($mc_gross), "Completed", "PayPal", $_SERVER['REMOTE_ADDR']), $row2->body);
         $newbody = cleanOut($body);
         $mailer = Mailer::sendMail();
         $message = Swift_Message::newInstance()->setSubject($row2->subject)->setTo(array($core->site_email => $core->site_name))->setFrom(array($core->site_email => $core->site_name))->setBody($newbody, 'text/html');
         $mailer->send($message);
Пример #2
0
}
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__) . '/ipn_errors.log');
if (isset($_POST['processStripePayment'])) {
    require_once dirname(__FILE__) . '/lib/Stripe.php';
    $key = $db->first("SELECT * FROM gateways WHERE name = 'stripe'");
    $stripe = array("secret_key" => $key->extra, "publishable_key" => $key->extra3);
    Stripe::setApiKey($stripe['secret_key']);
    try {
        $charge = Stripe_Charge::create(array("amount" => round($_POST['amount'] * 100, 0), "currency" => $_POST['currency_code'], "card" => array("number" => $_POST['card-number'], "exp_month" => $_POST['card-expiry-month'], "exp_year" => $_POST['card-expiry-year'], "cvc" => $_POST['card-cvc']), "description" => $_POST['item_name']));
        $json = json_decode($charge);
        $amount_charged = round($json->{'amount'} / 100, 2);
        /* == Payment Completed == */
        $row = $db->first("SELECT * FROM " . Membership::mTable . " WHERE id=" . intval($_POST['item_number']));
        $total = Core::getCart();
        if ($row and compareFloatNumbers($amount_charged, $total->totalprice, "=")) {
            $data = array('txn_id' => time(), 'membership_id' => $row->id, 'user_id' => $user->uid, 'rate_amount' => $total->originalprice, 'tax' => $total->totaltax, 'coupon' => $total->coupon, 'total' => $total->totalprice, 'ip' => $_SERVER['REMOTE_ADDR'], 'date' => "NOW()", 'pp' => "Stripe", 'currency' => sanitize($_POST['currency_code']), 'status' => 1);
            $db->insert(Membership::pTable, $data);
            $udata = array('membership_id' => $row->id, 'mem_expire' => $user->calculateDays($row->id), 'trial_used' => $row->trial == 1 ? 1 : 0);
            $db->update(Users::uTable, $udata, "id=" . $user->uid);
            $jn['type'] = 'success';
            $jn['message'] = 'Thank you payment completed';
            print json_encode($jn);
            /* == Notify Administrator == */
            require_once BASEPATH . "lib/class_mailer.php";
            $row2 = Core::getRowById(Content::eTable, 5);
            $body = str_replace(array('[USERNAME]', '[ITEMNAME]', '[PRICE]', '[STATUS]', '[PP]', '[IP]'), array($user->username, $row->title, $core->formatMoney($amount_charged), "Completed", "Stripe", $_SERVER['REMOTE_ADDR']), $row2->body);
            $newbody = cleanOut($body);
            $mailer = Mailer::sendMail();
            $message = Swift_Message::newInstance()->setSubject($row2->subject)->setTo(array($core->site_email => $core->site_name))->setFrom(array($core->site_email => $core->site_name))->setBody($newbody, 'text/html');
            $mailer->send($message);
Пример #3
0
/**
 * compareFloatNumbers()
 * 
 * @param mixed $float1
 * @param mixed $float2
 * @param string $operator
 * @return
 */
function compareFloatNumbers($float1, $float2, $operator = '=')
{
    // Check numbers to 5 digits of precision
    $epsilon = 1.0E-5;
    $float1 = (double) $float1;
    $float2 = (double) $float2;
    switch ($operator) {
        // equal
        case "=":
        case "eq":
            if (abs($float1 - $float2) < $epsilon) {
                return true;
            }
            break;
            // less than
        // less than
        case "<":
        case "lt":
            if (abs($float1 - $float2) < $epsilon) {
                return false;
            } else {
                if ($float1 < $float2) {
                    return true;
                }
            }
            break;
            // less than or equal
        // less than or equal
        case "<=":
        case "lte":
            if (compareFloatNumbers($float1, $float2, '<') || compareFloatNumbers($float1, $float2, '=')) {
                return true;
            }
            break;
            // greater than
        // greater than
        case ">":
        case "gt":
            if (abs($float1 - $float2) < $epsilon) {
                return false;
            } else {
                if ($float1 > $float2) {
                    return true;
                }
            }
            break;
            // greater than or equal
        // greater than or equal
        case ">=":
        case "gte":
            if (compareFloatNumbers($float1, $float2, '>') || compareFloatNumbers($float1, $float2, '=')) {
                return true;
            }
            break;
        case "<>":
        case "!=":
        case "ne":
            if (abs($float1 - $float2) > $epsilon) {
                return true;
            }
            break;
        default:
            die("Unknown operator '" . $operator . "' in compareFloatNumbers()");
    }
    return false;
}