Exemple #1
0
function user_has_recurring_subscriptions($member)
{
    global $config, $db;
    $core_cc_plugins = cc_core_get_plugins($only_recurring = true);
    foreach ($db->get_user_payments($member['member_id'], 1) as $p) {
        if ($p['expire_date'] < date('Y-m-d')) {
            continue;
        }
        if ($p['data']['CANCELLED']) {
            continue;
        }
        if (!in_array($p['paysys_id'], $core_cc_plugins)) {
            continue;
        }
        $pr = $db->get_product($p['product_id']);
        if (!$pr['is_recurring']) {
            continue;
        }
        return 1;
    }
    return 0;
}
function cc_core_check_expire_dates()
{
    global $db, $config;
    $dat = date('Y-m-d', time() + 3600 * 24 * 10);
    // 10 days later
    $plugins = array();
    foreach ((array) cc_core_get_plugins($only_recurring = true) as $plugin) {
        $payments = $db->get_expired_payments($dat, $dat, $plugin);
        foreach ($payments as $p) {
            if ($p['data']['CANCELLED']) {
                continue;
            }
            $member_id = $p['member_id'];
            $member = $db->get_user($member_id);
            $product_id = $p['product_id'];
            if ($renewed[$member_id][$product_id]++) {
                continue;
            }
            $product =& get_product($product_id);
            if (!$product->config['is_recurring']) {
                continue;
            }
            if ($product->config['rebill_times'] && !cc_core_check_rebill_times($product->config['rebill_times'], $p)) {
                continue;
            }
            /// do check
            $e = $member['data']['cc-expire'];
            if ($e == '') {
                continue;
            }
            $edat = date("Y-m-t", strtotime('20' . substr($e, 2, 2) . '-' . substr($e, 0, 2) . '-01'));
            if ($edat < $dat) {
                $expires = substr($e, 0, 2) . '/20' . substr($e, 2, 2);
                if ($config['card_expires']) {
                    mail_card_expires_member($member, $p['payment_id'], $product, $expires);
                }
            }
        }
    }
}
function do_rebill()
{
    global $config, $db;
    $t = new_smarty();
    $vars = get_input_vars();
    if ($vars['dat'] == '') {
        die('[dat] cannot be empty');
    }
    $dat = $vars['dat'];
    if (time() - strtotime($dat) > 3600 * 24 * 30) {
        die("Rebill cannot be called for periods longer than 30 days from nows");
    }
    if (time() - strtotime($dat) < 0) {
        die("Rebill cannot be called for future dates - please wait the date ");
    }
    $t->display('admin/header.inc.html');
    $hdat = strftime($config['date_format'], strtotime($dat));
    if (!$vars['paysys_id']) {
        print "\n\t<h2>Manual CC Rebill {$hdat}</h2>\n\t<br><br><p>Are you sure you want to run rebill process for date {$hdat} ?\n\t<a href='rebill_log.php?do=rebill_stats'>Click here to cancel and back to rebill reports</a>\n\t</p>";
        print "<p><b>Make sure to do not close browser windows and do not start any new rebill processes until it is finished, else it may result to double billing of customers</p></b>";
        $options = "";
        foreach (cc_core_get_plugins(true) as $p) {
            $options .= "<option value='{$p}'>{$p}</option>\n";
        }
        $dat = htmlentities($vars['dat']);
        print "<form method='post' action='rebill_log.php'>\n\t<select name='paysys_id'>\n\t<option value=''>*** Select a Payment System to continue ***</option>\n\t{$options}</select> <br />\n\t<label><input type='checkbox' name='repeat_declined' value='1' />\n\tRe-process payments that were marked as declined\n\t</label><br />\n\t<input type='submit' value='Continue'>\n\t<input type='hidden' name='dat' value='{$dat}'>\n\t<input type='hidden' name='do' value='rebill'>\n\t</form>\n\t";
    } else {
        // do rebill
        print "\n\t\t<h2>Manual CC Rebill {$hdat} - {$vars['paysys_id']}</h2>";
        print "<p><b>Please do not stop/exit your browser, do not run other payment processes until this process is finished!</b></p>";
        for ($i = 0; $i < 100; $i++) {
            print "          \n";
        }
        // to flush browser/apache buffer for sure
        print " Rebilling Process started at " . strftime($config['time_format']) . "....<br />\n";
        ob_end_flush();
        $dat = date('Y-m-d', strtotime($vars['dat']));
        $was = $db->query_one("SELECT COUNT(*) FROM {$db->config[prefix]}rebill_log");
        cc_core_rebill($vars['paysys_id'], $dat, $from_cron = false, intval($vars['repeat_declined']));
        $now = $db->query_one("SELECT COUNT(*) FROM {$db->config[prefix]}rebill_log");
        $added = $now - $was;
        print " Rebilling Process finished at " . strftime($config['time_format']) . ".<br />\n\t\t <b>{$added}</b> transactions processed. <br />\n";
        print "<br /><a href='rebill_log.php?do=rebill_stats'>Go back to Rebilling Stats</a>";
    }
    $t->display('admin/footer.inc.html');
}