Exemple #1
0
 if ($mode == 'return') {
     if (fn_check_payment_script('paypal.php', $_REQUEST['order_id'])) {
         $order_info = fn_get_order_info($_REQUEST['order_id'], true);
         fn_pp_save_mode($order_info);
         if ($order_info['status'] == 'O') {
             $edp_data = fn_generate_ekeys_for_edp(array('status_from' => STATUS_INCOMPLETED_ORDER, 'status_to' => 'O'), $order_info);
             fn_order_notification($order_info, $edp_data);
         }
         if (fn_allowed_for('MULTIVENDOR')) {
             if ($order_info['status'] == STATUS_PARENT_ORDER) {
                 $child_orders = db_get_hash_single_array("SELECT order_id, status FROM ?:orders WHERE parent_order_id = ?i", array('order_id', 'status'), $_REQUEST['order_id']);
                 foreach ($child_orders as $order_id => $order_status) {
                     if ($order_status == 'O') {
                         $order_info = fn_get_order_info($order_id, true);
                         $edp_data = fn_generate_ekeys_for_edp(array('status_from' => STATUS_INCOMPLETED_ORDER, 'status_to' => 'O'), $order_info);
                         fn_order_notification($order_info, $edp_data);
                     }
                 }
             }
         }
     }
     fn_order_placement_routines('route', $_REQUEST['order_id'], false);
 } elseif ($mode == 'cancel') {
     $order_info = fn_get_order_info($_REQUEST['order_id']);
     fn_pp_save_mode($order_info);
     $pp_response['order_status'] = 'N';
     $pp_response["reason_text"] = __('text_transaction_cancelled');
     if (!empty($_REQUEST['payer_email'])) {
         $pp_response['customer_email'] = $_REQUEST['payer_email'];
     }
     if (!empty($_REQUEST['payer_id'])) {
Exemple #2
0
 public static function orderPlacementRoutines($order_id, $force_notification = array(), $clear_cart = true, $action = '')
 {
     // don't show notifications
     // only clear cart
     $order_info = fn_get_order_info($order_id, true);
     $display_notification = true;
     fn_set_hook('placement_routines', $order_id, $order_info, $force_notification, $clear_cart, $action, $display_notification);
     if (!empty($_SESSION['cart']['placement_action'])) {
         if (empty($action)) {
             $action = $_SESSION['cart']['placement_action'];
         }
         unset($_SESSION['cart']['placement_action']);
     }
     if (AREA == 'C' && !empty($order_info['user_id'])) {
         $__fake = '';
         fn_save_cart_content($__fake, $order_info['user_id']);
     }
     $edp_data = fn_generate_ekeys_for_edp(array(), $order_info);
     fn_order_notification($order_info, $edp_data, $force_notification);
     // Empty cart
     if ($clear_cart == true && substr_count('OPT', $order_info['status']) > 0) {
         $_SESSION['cart'] = array('user_data' => !empty($_SESSION['cart']['user_data']) ? $_SESSION['cart']['user_data'] : array(), 'profile_id' => !empty($_SESSION['cart']['profile_id']) ? $_SESSION['cart']['profile_id'] : 0, 'user_id' => !empty($_SESSION['cart']['user_id']) ? $_SESSION['cart']['user_id'] : 0);
         db_query('DELETE FROM ?:user_session_products WHERE session_id = ?s AND type = ?s', Session::getId(), 'C');
     }
     $is_twg_hook = true;
     $_error = false;
     fn_set_hook('order_placement_routines', $order_id, $force_notification, $order_info, $_error, $is_twg_hook);
 }
Exemple #3
0
function fn_order_placement_routines($action = '', $order_id = 0, $force_notification = array(), $clear_cart = true, $area = AREA)
{
    if (Embedded::isLeft() && !Embedded::isEnabled()) {
        Embedded::enable();
    }
    if ($action == 'checkout_redirect') {
        if ($area == 'A') {
            fn_redirect("order_management.edit?order_id=" . reset($_SESSION['cart']['processed_order_id']));
        } else {
            fn_redirect('checkout.checkout');
        }
    } elseif (in_array($action, array('save', 'repay', 'route')) && !empty($order_id)) {
        $order_info = fn_get_order_info($order_id, true);
        $display_notification = true;
        fn_set_hook('placement_routines', $order_id, $order_info, $force_notification, $clear_cart, $action, $display_notification);
        if (!empty($_SESSION['cart']['placement_action'])) {
            if (empty($action)) {
                $action = $_SESSION['cart']['placement_action'];
            }
            unset($_SESSION['cart']['placement_action']);
        }
        if ($area == 'C' && !empty($order_info['user_id'])) {
            $__fake = '';
            fn_save_cart_content($__fake, $order_info['user_id']);
        }
        $edp_data = fn_generate_ekeys_for_edp(array(), $order_info);
        fn_order_notification($order_info, $edp_data, $force_notification);
        $_error = false;
        if ($action == 'save') {
            if ($display_notification) {
                fn_set_notification('N', __('congratulations'), __('text_order_saved_successfully'));
            }
        } else {
            if ($order_info['status'] == STATUS_PARENT_ORDER) {
                $child_orders = db_get_hash_single_array("SELECT order_id, status FROM ?:orders WHERE parent_order_id = ?i", array('order_id', 'status'), $order_id);
                $status = reset($child_orders);
                $child_orders = array_keys($child_orders);
            } else {
                $status = $order_info['status'];
            }
            if (in_array($status, fn_get_order_paid_statuses())) {
                if ($action == 'repay') {
                    fn_set_notification('N', __('congratulations'), __('text_order_repayed_successfully'));
                } else {
                    fn_set_notification('N', __('order_placed'), __('text_order_placed_successfully'));
                }
            } elseif ($status == STATUS_BACKORDERED_ORDER) {
                fn_set_notification('W', __('important'), __('text_order_backordered'));
            } else {
                if ($area == 'A' || $action == 'repay') {
                    if ($status != STATUS_CANCELED_ORDER) {
                        $_payment_info = db_get_field("SELECT data FROM ?:order_data WHERE order_id = ?i AND type = 'P'", $order_id);
                        if (!empty($_payment_info)) {
                            $_payment_info = unserialize(fn_decrypt_text($_payment_info));
                            $_msg = !empty($_payment_info['reason_text']) ? $_payment_info['reason_text'] : '';
                            $_msg .= empty($_msg) ? __('text_order_placed_error') : '';
                            fn_set_notification('E', '', $_msg);
                        }
                    }
                } else {
                    $_error = true;
                    if (!empty($child_orders)) {
                        array_unshift($child_orders, $order_id);
                    } else {
                        $child_orders = array();
                        $child_orders[] = $order_id;
                    }
                    $_SESSION['cart'][$status == STATUS_INCOMPLETED_ORDER ? 'processed_order_id' : 'failed_order_id'] = $child_orders;
                }
                if ($status == STATUS_INCOMPLETED_ORDER || $action == 'repay' && $status == STATUS_CANCELED_ORDER) {
                    fn_set_notification('W', __('important'), __('text_transaction_cancelled'));
                }
            }
        }
        // Empty cart
        if ($clear_cart == true && $_error == false) {
            $_SESSION['cart'] = array('user_data' => !empty($_SESSION['cart']['user_data']) ? $_SESSION['cart']['user_data'] : array(), 'profile_id' => !empty($_SESSION['cart']['profile_id']) ? $_SESSION['cart']['profile_id'] : 0, 'user_id' => !empty($_SESSION['cart']['user_id']) ? $_SESSION['cart']['user_id'] : 0);
            $_SESSION['shipping_rates'] = array();
            unset($_SESSION['shipping_hash']);
            db_query('DELETE FROM ?:user_session_products WHERE session_id = ?s AND type = ?s', Session::getId(), 'C');
        }
        fn_set_hook('order_placement_routines', $order_id, $force_notification, $order_info, $_error);
        if ($area == 'A') {
            fn_redirect("orders.details?order_id={$order_id}");
        } else {
            fn_redirect('checkout.' . ($_error ? 'checkout' : "complete?order_id={$order_id}"));
        }
    } elseif ($action == 'index_redirect') {
        fn_redirect(fn_url('', 'C', 'http'));
    } else {
        fn_redirect(fn_url($action, 'C', 'http'));
    }
}
Exemple #4
0
             );
 
             $_data = array(
                 'data' => serialize($shippings),
                 'order_id' => $_REQUEST['order_id'],
                 'type' => 'L',
             );
 
             db_query('REPLACE INTO ?:order_data ?e', $_data);
         }*/
 $edp_data = array();
 $order_info = fn_get_order_info($_REQUEST['order_id'], false, true, false, true);
 if (!empty($_REQUEST['activate_files'])) {
     $edp_data = fn_generate_ekeys_for_edp(array(), $order_info, $_REQUEST['activate_files']);
 }
 fn_order_notification($order_info, $edp_data, fn_get_notification_rules($_REQUEST));
 if (!empty($_REQUEST['prolongate_data']) && is_array($_REQUEST['prolongate_data'])) {
     foreach ($_REQUEST['prolongate_data'] as $ekey => $v) {
         $newttl = fn_parse_date($v, true);
         db_query('UPDATE ?:product_file_ekeys SET ?u WHERE ekey = ?s', array('ttl' => $newttl), $ekey);
     }
 }
 // Update file downloads section
 if (!empty($_REQUEST['edp_downloads'])) {
     foreach ($_REQUEST['edp_downloads'] as $ekey => $v) {
         foreach ($v as $file_id => $downloads) {
             $max_downloads = db_get_field("SELECT max_downloads FROM ?:product_files WHERE file_id = ?i", $file_id);
             if (!empty($max_downloads)) {
                 db_query('UPDATE ?:product_file_ekeys SET ?u WHERE ekey = ?s', array('downloads' => $max_downloads - $downloads), $ekey);
             }
         }
     foreach ($_REQUEST['order_ids'] as $v) {
         fn_delete_order($v);
     }
 }
 if ($mode == 'update_details') {
     fn_trusted_vars('update_order');
     // Update customer's email if its changed in customer's account
     if (!empty($_REQUEST['update_customer_details']) && $_REQUEST['update_customer_details'] == 'Y') {
         $u_id = db_get_field("SELECT user_id FROM ?:orders WHERE order_id = ?i", $_REQUEST['order_id']);
         $current_email = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $u_id);
         db_query("UPDATE ?:orders SET email = ?s WHERE order_id = ?i", $current_email, $_REQUEST['order_id']);
     }
     // Log order update
     fn_log_event('orders', 'update', array('order_id' => $_REQUEST['order_id']));
     db_query('UPDATE ?:orders SET ?u WHERE order_id = ?i', $_REQUEST['update_order'], $_REQUEST['order_id']);
     //Update shipping info
     if (!empty($_REQUEST['update_shipping'])) {
         foreach ($_REQUEST['update_shipping'] as $group_key => $shipment) {
             $shipment['shipment_data']['order_id'] = $_REQUEST['order_id'];
             $shipment_id = isset($shipment['shipment_id']) ? $shipment['shipment_id'] : 0;
             fn_update_shipment($shipment['shipment_data'], $shipment_id, $group_key, true);
         }
     }
     // Add new shipping info
     /*if (!empty($_REQUEST['add_shipping'])) {
         $shipping = db_get_field('SELECT shipping FROM ?:shipping_descriptions WHERE shipping_id = ?i', $_REQUEST['add_shipping']['shipping_id']);
         $shippings[$_REQUEST['add_shipping']['shipping_id']] = array(
             'shipping' => $shipping,
             'tracking_number' => $_REQUEST['add_shipping']['tracking_number'],
             'carrier' => $_REQUEST['add_shipping']['carrier'],
         );
Exemple #6
0
function fn_order_placement_routines($order_id, $force_notification = array(), $clear_cart = true, $action = '')
{
    $order_info = fn_get_order_info($order_id, true);
    if (!empty($_SESSION['cart']['placement_action'])) {
        if (empty($action)) {
            $action = $_SESSION['cart']['placement_action'];
        }
        unset($_SESSION['cart']['placement_action']);
    }
    if (AREA == 'C' && !empty($order_info['user_id'])) {
        $__fake = '';
        fn_save_cart_content($__fake, $order_info['user_id']);
    }
    $edp_data = fn_generate_ekeys_for_edp(array(), $order_info);
    fn_order_notification($order_info, $edp_data, $force_notification);
    $_error = false;
    if ($action == 'save') {
        fn_set_notification('N', fn_get_lang_var('congratulations'), fn_get_lang_var('text_order_saved_successfully'));
    } else {
        if ($order_info['status'] == STATUS_PARENT_ORDER) {
            $child_orders = db_get_hash_single_array("SELECT order_id, status FROM ?:orders WHERE parent_order_id = ?i", array('order_id', 'status'), $order_id);
            $status = reset($child_orders);
            $child_orders = array_keys($child_orders);
        } else {
            $status = $order_info['status'];
        }
        if (substr_count('OP', $status) > 0) {
            if ($action == 'repay') {
                fn_set_notification('N', fn_get_lang_var('congratulations'), fn_get_lang_var('text_order_repayed_successfully'));
            } else {
                fn_set_notification('N', fn_get_lang_var('order_placed'), fn_get_lang_var('text_order_placed_successfully'));
            }
        } elseif ($status == 'B') {
            fn_set_notification('N', fn_get_lang_var('order_placed'), fn_get_lang_var('text_order_backordered'));
        } else {
            if (AREA == 'A' || $action == 'repay') {
                if ($status != 'I') {
                    fn_set_notification('E', fn_get_lang_var('order_placed'), fn_get_lang_var('text_order_placed_error'));
                }
            } else {
                $_error = true;
                if (!empty($child_orders)) {
                    array_unshift($child_orders, $order_id);
                } else {
                    $child_orders = array();
                    $child_orders[] = $order_id;
                }
                $_SESSION['cart'][$status == 'N' ? 'processed_order_id' : 'failed_order_id'] = $child_orders;
            }
            if ($status == 'N' || $action == 'repay' && $status == 'I') {
                fn_set_notification('N', fn_get_lang_var('cancelled'), fn_get_lang_var('text_transaction_cancelled'));
            }
        }
    }
    // Empty cart
    if ($clear_cart == true && $_error == false) {
        $_SESSION['cart'] = array('user_data' => !empty($_SESSION['cart']['user_data']) ? $_SESSION['cart']['user_data'] : array(), 'profile_id' => !empty($_SESSION['cart']['profile_id']) ? $_SESSION['cart']['profile_id'] : 0, 'user_id' => !empty($_SESSION['cart']['user_id']) ? $_SESSION['cart']['user_id'] : 0);
        db_query('DELETE FROM ?:user_session_products WHERE session_id = ?s AND type = ?s', Session::get_id(), 'C');
    }
    fn_set_hook('order_placement_routines', $order_id, $force_notification, $order_info);
    $prefix = Registry::get('settings.General.secure_auth') == 'Y' && AREA == 'C' ? Registry::get('config.https_location') . '/' : '';
    if (AREA == 'A' || $action == 'repay') {
        fn_redirect($prefix . INDEX_SCRIPT . "?dispatch=orders.details&order_id={$order_id}", true);
    } else {
        fn_redirect($prefix . INDEX_SCRIPT . "?dispatch=checkout." . ($_error == true ? Registry::get('settings.General.one_page_checkout') == 'Y' ? "checkout" : "summary" : "complete&order_id={$order_id}"), true);
    }
}
function fn_charge_subscription($subscription_id)
{
    $_SESSION['cart'] = isset($_SESSION['cart']) ? $_SESSION['cart'] : array();
    $cart =& $_SESSION['cart'];
    $_SESSION['customer_auth'] = isset($_SESSION['customer_auth']) ? $_SESSION['customer_auth'] : array();
    $customer_auth =& $_SESSION['customer_auth'];
    fn_clear_cart($cart, true);
    $customer_auth = fn_fill_auth();
    $subscription = fn_get_recurring_subscription_info($subscription_id);
    if ($subscription['status'] != 'A') {
        fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('rb_subscription_inactive'));
    } else {
        $product_data = array();
        foreach ($subscription['order_info']['items'] as $k => $item) {
            if (!empty($subscription['order_info']['items'][$k]['extra']['recurring_plan_id']) && $subscription['order_info']['items'][$k]['extra']['recurring_plan_id'] == $subscription['plan_id'] && $subscription['order_info']['items'][$k]['extra']['recurring_duration'] == $subscription['orig_duration']) {
                $product_data[$subscription['order_info']['items'][$k]['product_id']] = array('amount' => $subscription['order_info']['items'][$k]['amount'], 'extra' => array('recurring_plan_id' => $subscription['plan_id'], 'recurring_force_calculate' => true, 'recurring_subscription_id' => $subscription['subscription_id'], 'recurring_plan' => $subscription['order_info']['items'][$k]['extra']['recurring_plan'], 'recurring_duration' => $subscription['order_info']['items'][$k]['extra']['recurring_duration']));
                if (!empty($subscription['order_info']['items'][$k]['extra']['product_options'])) {
                    $product_data[$subscription['order_info']['items'][$k]['product_id']]['product_options'] = $subscription['order_info']['items'][$k]['extra']['product_options'];
                }
            }
        }
        $cart['user_id'] = $subscription['user_id'];
        $u_data = db_get_row("SELECT user_id, user_type, tax_exempt FROM ?:users WHERE user_id = ?i", $cart['user_id']);
        $customer_auth = fn_fill_auth($u_data);
        $cart['user_data'] = array();
        fn_add_product_to_cart($product_data, $cart, $customer_auth);
        $cart['profile_id'] = 0;
        $cart['user_data'] = fn_get_user_info($customer_auth['user_id'], true, $cart['profile_id']);
        if (!empty($cart['user_data'])) {
            $profile_fields = fn_get_profile_fields('O', $customer_auth);
            $cart['ship_to_another'] = fn_check_shipping_billing($cart['user_data'], $profile_fields);
        }
        fn_calculate_cart_content($cart, $customer_auth, 'A', true, 'I');
        $cart['payment_id'] = $subscription['order_info']['payment_id'];
        $cart['payment_info'] = $subscription['order_info']['payment_info'];
        $cart['recurring_subscription_id'] = $subscription_id;
        list($order_id, $process_payment) = fn_place_order($cart, $customer_auth);
        if (!empty($order_id)) {
            $order_info = fn_get_order_info($order_id, true);
            $evt_data = array('subscription_id' => $subscription_id, 'timestamp' => $order_info['timestamp'], 'event_type' => 'C');
            db_query("INSERT INTO ?:recurring_events ?e", $evt_data);
            if ($process_payment == true) {
                fn_start_payment($order_id);
            }
            $edp_data = fn_generate_ekeys_for_edp(array(), $order_info);
            fn_order_notification($order_info, $edp_data);
        }
    }
}