Exemplo n.º 1
0
function do_renew()
{
    global $_SESSION;
    global $_amember_id;
    global $config, $db, $t, $vars, $plugins, $error;
    $member_id = intval($_amember_id);
    $error = array_merge((array) $error, (array) plugin_validate_member_form($vars));
    if (count($error)) {
        $t->assign('error', $error);
        return;
    }
    $vars['product_id'] = is_array($vars['product_id']) ? array_filter(array_map('intval', $vars['product_id'])) : intval($vars['product_id']);
    if (!$vars['product_id']) {
        $t->assign('error', _MEMBER_SELECT_PRODUCT);
        return;
    }
    if ($vars['coupon'] != '' && $config['use_coupons']) {
        $coupon = $db->coupon_get($vars['coupon'], $_SESSION[_amember_id]);
        if (is_string($coupon)) {
            $t->assign('error', $coupon);
            return;
        }
    }
    $pc =& new PriceCalculator();
    $pc->addProducts($vars['product_id']);
    if ($config['use_coupons'] && $vars['coupon'] != '') {
        $coupon = $db->coupon_get($vars['coupon'], $_SESSION[_amember_id]);
        if ($coupon['coupon_id']) {
            $pc->setCouponDiscount($coupon['discount'], split(',', trim($coupon['product_id'])));
        }
    }
    $pc->setPriceFieldsByPaysys($vars['paysys_id']);
    $pc->setTax(get_member_tax($member_id));
    $terms =& $pc->calculate();
    $price = $terms->total;
    if ($price == 0 && !product_get_trial($vars['product_id']) && ($terms->discount > 0 && !$coupon['is_recurring'] || !$terms->discount) && in_array('free', $plugins['payment'])) {
        $vars['paysys_id'] = 'free';
    }
    if ($config['product_paysystem']) {
        $pr = get_product(is_array($vars['product_id']) ? $vars['product_id'][0] : $vars['product_id']);
        $vars['paysys_id'] = $pr->config['paysys_id'];
    }
    if (!$vars['paysys_id']) {
        $t->assign('error', _MEMBER_SELECT_PAYMENT);
        return;
    }
    //check for agreement
    $display_agreement = 0;
    foreach ((array) $vars['product_id'] as $pid) {
        $product = $db->get_product($pid);
        if ($product['need_agreement']) {
            $display_agreement++;
        }
    }
    $member = $db->get_user($member_id);
    if ($display_agreement && !$member['data']['i_agree'] && !$vars['i_agree']) {
        display_agreement(serialize($vars));
        // defined in the  product.inc.php
        exit;
    }
    if ($vars['i_agree'] && !$member['data']['i_agree']) {
        $member['data']['i_agree']++;
        $db->update_user($member_id, $member);
    }
    ///
    do {
        // for easy exit using break;
        $paysys_id = $vars['paysys_id'];
        $product_id = $vars['product_id'];
        if (!is_array($product_id)) {
            $product_id = array($product_id);
        }
        foreach ((array) $vars['product_id'] as $pid) {
            $error = check_product_scope($pid, $_amember_id);
            if ($error) {
                break;
            }
        }
        if ($error = check_product_requirements($product_id, get_product_requirements_for_member($_amember_id))) {
            break;
        }
        //        if ($terms->discount > 0)
        $vars['COUPON_CODE'] = $vars['coupon'];
        global $payment_additional_fields;
        $additional_values = array();
        foreach ($payment_additional_fields as $f) {
            $fname = $f['name'];
            if (isset($vars[$fname])) {
                $additional_values[$fname] = $vars[$fname];
            }
        }
        $additional_values['COUPON_DISCOUNT'] = $terms->discount;
        $additional_values['TAX_AMOUNT'] = $terms->tax;
        $taxes = $prices = array();
        foreach ($terms->lines as $pid => $line) {
            $prices[$pid] = $line->total;
            if ($line->tax) {
                $taxes[$pid] = $line->tax;
            }
        }
        $additional_values['TAXES'] = $taxes;
        $product =& get_product($product_id[0]);
        $begin_date = $product->get_start($member_id);
        $expire_date = $product->get_expire($begin_date, null, $terms);
        //yyyy-mm-dd
        // add payment
        $payment_id = $db->add_waiting_payments($member_id, $product_id, $paysys_id, $price, $prices, $begin_date, $expire_date, $vars, $additional_values);
        $error = plugin_do_payment($paysys_id, $payment_id, $member_id, is_array($product_id) ? $product_id[0] : $product_id, $price, $begin_date, $expire_date, $vars);
        if ($error) {
            $db->delete_payment($payment_id);
            break;
        }
        exit;
    } while (0);
    //if we here, error was occured
    $t->assign('error', $error);
    return;
}
Exemplo n.º 2
0
        $pc->addProducts($vars['product_id']);
        if ($config['use_coupons'] && $vars['coupon'] != '') {
            $coupon = $db->coupon_get($vars['coupon']);
            if ($coupon['coupon_id']) {
                $pc->setCouponDiscount($coupon['discount'], split(',', trim($coupon['product_id'])));
            }
        }
        $pc->setPriceFieldsByPaysys($vars['paysys_id']);
        $pc->setTax(get_member_tax(null));
        $terms =& $pc->calculate();
        $price = $terms->total;
        if ($config['product_paysystem']) {
            $pr = get_product(is_array($vars['product_id']) ? $vars['product_id'][0] : $vars['product_id']);
            $vars['paysys_id'] = $pr->config['paysys_id'];
        }
        if (!$price && !product_get_trial($vars['product_id']) && ($terms->discount > 0 && !$coupon['is_recurring'] || !$terms->discount) && in_array('free', $plugins['payment'])) {
            $vars['paysys_id'] = 'free';
        }
    }
}
if ($vars['do_payment'] && check_payment_form()) {
    //check for agreement
    $display_agreement = 0;
    foreach ((array) $vars['product_id'] as $pid) {
        $product = $db->get_product($pid);
        if ($product['need_agreement']) {
            $display_agreement++;
        }
    }
    if ($display_agreement && !$vars['i_agree']) {
        display_agreement(serialize($vars));