Example #1
0
function ProcessAddOrder()
{
    global $tpl, $product, $user, $order, $error_list, $mail, $currency_code, $currency_unit;
    $user_id = $_REQUEST['user_id'];
    $product_id = $_REQUEST['product_id'];
    $confirm_user = $_REQUEST['confirm_user'];
    $email = $_REQUEST['email'];
    $date_order_mo = $_REQUEST['date_order'];
    //figure out what the timestamp for the month should be
    if ($date_order_mo < date('m')) {
        //year+1
        $date_order = strtotime(date('Y') + 1 . '/' . $date_order_mo . '/1');
    } else {
        $date_order = strtotime(date('Y') . '/' . $date_order_mo . '/1');
    }
    $i = 0;
    if (!$order->CheckActiveOrder($product_id, $user_id, $date_order)) {
        $error_list[$i] = "Order is already active for the selected month";
        $i++;
    } else {
        if ($product_id == "") {
            $error_list[$i] = "Please choose membership type";
            $i++;
        }
    }
    if (!is_array($error_list)) {
        $order_id = $order->AddOrder($user_id, $product_id, $date_order);
        $order_data = $order->GetOrder($order_id);
        $product_name = $order_data['name'];
        $product_desc = $order_data['description'];
        $product_price = $currency_code . ". " . $order_data['price'];
        $product_expire = date("Y-m-d", $order_data['date_expire']);
        $data_user = $user->CheckEmailExist($email);
        $username = $data_user['username'];
        $firstname = $data_user['firstname'];
        $lastname = $data_user['lastname'];
        if ($confirm_user) {
            $from_email = CFG_NOTIFY_EMAIL;
            $from_name = CFG_NOTIFY_FROM;
            $mail->ConfirmOrderEmail(CFG_SITE_NAME, $firstname, $lastname, $from_email, $from_name, $product_name, $product_desc, $product_price, $product_expire, $email);
            $mail->ReceivedOrderEmail(CFG_SITE_NAME, $firstname, $lastname, $from_email, $from_name, $product_name, $product_desc, $product_price, $date_order, $product_expire, CFG_SITE_MAIL);
            $order->UpdateLastEmailSent($order_id, time());
        }
        $message = "Adding order to user success.<br />";
        $message .= "<input type='button' value='back' onclick=\"javascript:window.location.href='order.php?pf=browse'\">";
        $tpl->assign('message', $message);
        $tpl->display('admin/generic.html');
    } else {
        ShowFormAddOrder();
    }
}
Example #2
0
function ProcessAddOrder()
{
    global $tpl, $product, $user, $order, $error_list, $mail, $coupon, $pay_class, $currency_code, $currency_unit, $dispatcher;
    $users = $user->CheckUserActive($_SESSION['SESSION_USERNAME']);
    $user_id = $users['user_id'];
    $username = $users['username'];
    $firstname = $users['firstname'];
    $lastname = $users['lastname'];
    $email = $users['email'];
    $password = $users['password'];
    $payment_gateway = $_REQUEST['payment_gateway'];
    $product_id = $_REQUEST['product_id'];
    $payment_gateway = $_REQUEST['payment_gateway'];
    $products = $product->GetProduct($product_id);
    $coupon_code = $_REQUEST['coupon_code'];
    $date_order_mo = $_REQUEST['date_order'];
    //figure out what the timestamp for the month should be
    if ($date_order_mo < date('m')) {
        //year+1
        $date_order = strtotime(date('Y') + 1 . '/' . $date_order_mo . '/1');
    } else {
        $date_order = strtotime(date('Y') . '/' . $date_order_mo . '/1');
    }
    $i = 0;
    if (!$order->CheckActiveOrder($product_id, $user_id, $date_order)) {
        $error_list[$i] = "Order already active for the selected month";
        $i++;
    } else {
        if ($product_id == "") {
            $error_list[$i] = "Please choose membership type";
            $i++;
        } elseif ($payment_gateway == "" && $products['price'] > 0) {
            $error_list[$i] = "Please select payment gateway";
            $i++;
        }
    }
    if (!is_array($error_list)) {
        $price = $products['price'];
        $name = $products['name'];
        $description = $products['description'];
        $item_name = $name . " ( " . $description . " )";
        $invoice_id = getInvoiceId();
        // let's trigger a hook
        $dispatcher->trigger("newInvoice", $invoice_id);
        //**** for coupon ****//
        if ($coupon_code != "") {
            $discount_data = $coupon->CheckProductDiscount($coupon_code, $product_id);
            if (!$discount_data) {
                $error_list[$i] = "Discount not found";
                $i++;
            } else {
                $percentage = strrpos($discount_data['coupon_value'], "%");
                if ($percentage) {
                    $percent = str_replace("%", "", $discount_data['coupon_value']);
                    $coupon_value_type = "percentage";
                    $percentage_coupon_value = $percent;
                    $net_price = $discount_data['price'] - $discount_data['price'] * ($percent / 100);
                } else {
                    $coupon_value_type = "price";
                    $price_coupon_value = $discount_data['coupon_value'];
                    $net_price = $discount_data['price'] - $discount_data['coupon_value'];
                }
                $price = $net_price;
                if ($price < 0) {
                    $price = 0;
                }
            }
        }
        if ($price == 0 || $payment_gateway == "cash_payments") {
            $user_exist = $user->CheckUserActive($username);
            if ($user_exist['user_id'] == "") {
                $user_id = $user->Add($username, $password, $password, $firstname, $lastname, $email);
            } else {
                $user_id = $user_exist['user_id'];
            }
            $order_id = $order->AddOrder($user_id, $product_id, $date_order);
            $order_data = $order->GetOrder($order_id);
            $product_name = $order_data['name'];
            $product_desc = $order_data['description'];
            $product_price = $order_data['price'];
            $product_expire = date("Y-m-d", $order_data['date_expire']);
            $from_email = CFG_NOTIFY_EMAIL;
            $from_name = CFG_NOTIFY_FROM;
            $mail->ConfirmOrderEmail(CFG_SITE_NAME, $firstname, $lastname, $from_email, $from_name, $product_name, $product_desc, $product_price, $product_expire, $email);
            $mail->ReceivedOrderEmail(CFG_SITE_NAME, $firstname, $lastname, $from_email, $from_name, $product_name, $product_desc, $product_price, $date_order, $product_expire, CFG_SITE_MAIL);
            $order->UpdateLastEmailSent($order_id, time());
            $login = $user->Login($username, $password, $expire);
            header("Location: index.php");
        } else {
            $currency_code = $currency_code;
            //$currency_unit ===== GLOBAL VARIABLE
            $return_url = CFG_SITE_URL;
            $cancel_url = CFG_SITE_URL;
            $total = $price;
            $custom = "{$product_id}&{$email}&{$username}&{$password}&{$firstname}&{$lastname}&{$coupon_code}&{$date_order}";
            if ($payment_gateway == "co" || $payment_gateway == "co_subscribe") {
                $gateway_data = $pay_class->GetPaymentGatewayDetail("2" . $payment_gateway);
            } else {
                $gateway_data = $pay_class->GetPaymentGatewayDetail($payment_gateway);
            }
            switch ($payment_gateway) {
                case 'paypal_payments':
                    $notify_url = CFG_SITE_URL . '/payment/paypal.ipn.php';
                    $paypal_payments_email = $gateway_data['payment_gateway_account'];
                    $paypal_email = $paypal_payments_email;
                    include 'payment/paypal.php';
                    break;
                case ' paypal_subscribe':
                    $notify_url = CFG_SITE_URL . '/payment/paypal-subscribe.ipn.php';
                    $paypal_subscribe_email = $gateway_data['payment_gateway_account'];
                    $listing_period = $products['duration'];
                    $listing_period_code = strtoupper($products['duration_unit']);
                    $paypal_email = $paypal_subscribe_email;
                    include 'payment/paypal-subscribe.php';
                    break;
                case 'co':
                    $notify_url = CFG_SITE_URL . '/payment/2co.ipn.php';
                    $co_account = $gateway_data['payment_gateway_account'];
                    $list_co_account = explode("&", $co_account);
                    $co_sid = $list_co_account[0];
                    $co_secret = $list_co_account[1];
                    $co_recurring = 0;
                    //set subscribe
                    include 'payment/2co.php';
                    break;
                case 'co_subscribe':
                    $notify_url = CFG_SITE_URL . '/payment/2co-subscribe.ipn.php';
                    $co_account = $gateway_data['payment_gateway_account'];
                    $list_co_account = explode("&", $co_account);
                    $co_sid = $list_co_account[0];
                    $co_secret = $list_co_account[1];
                    $co_recurring = 1;
                    //set subscribe
                    $co_prod_id = $product_id;
                    include 'payment/2co-subscribe.php';
                    break;
                case 'alertpay':
                    $notify_url = CFG_SITE_URL . '/payment/alertpay.ipn.php';
                    $alertpay_account = $gateway_data['payment_gateway_account'];
                    $list_alertpay_account = explode("&", $alertpay_account);
                    $payalert_email = $list_alertpay_account[0];
                    $payalert_security_code = $list_alertpay_account[1];
                    $ap_currency = $currency_code;
                    $ap_purchasetype = "service";
                    //lainnya subscription & service
                    include 'payment/alertpay.php';
                    break;
                case 'alertpay_subscribe':
                    $notify_url = CFG_SITE_URL . '/payment/alertpay-subscribe.ipn.php';
                    $alertpay_subscribe_account = $gateway_data['payment_gateway_account'];
                    $list_alertpay_subscribe_account = explode("&", $alertpay_subscribe_account);
                    $payalert_email = $list_alertpay_subscribe_account[0];
                    $payalert_security_code = $list_alertpay_subscribe_account[1];
                    $ap_currency = $currency_code;
                    $ap_purchasetype = "subscription";
                    //lainnya subscription & service
                    if (strtolower($products['duration_unit']) == "d") {
                        $ap_timeunit = "Day";
                    } elseif (strtolower($products['duration_unit']) == "m") {
                        $ap_timeunit = "Month";
                    } elseif (strtolower($products['duration_unit']) == "y") {
                        $ap_timeunit = "Year";
                    }
                    $ap_periodlength = $products['duration'];
                    include 'payment/alertpay-subscribe.php';
                    break;
                case 'moneybookers':
                    $notify_url = CFG_SITE_URL . '/payment/moneybookers.ipn.php';
                    $moneybookers_email = $gateway_data['payment_gateway_account'];
                    include 'payment/moneybookers.php';
                    break;
            }
        }
    } else {
        ShowFormAddOrder();
    }
}