Example #1
0
        }
    }
    $transaction = PayPalOrder::getTransactionDetails($ppec, $payment_status);
    $ppec->context->cookie->id_cart = $cart->id;
    $ppec->validateOrder((int) $cart->id, $payment_type, $order_total, $ppec->displayName, $message, $transaction, (int) $cart->id_currency, false, $customer->secure_key, $ppec->context->shop);
}
/* If Previous steps succeed, ready (means 'ready to pay') will be set to true */
if ($ppec->ready && !empty($ppec->token) && (Tools::isSubmit('confirmation') || $ppec->type == 'payment_cart')) {
    /* Check modification on the product cart / quantity */
    if ($ppec->isProductsListStillRight()) {
        $cart = $ppec->context->cart;
        $customer = new Customer((int) $cart->id_customer);
        // When all information are checked before, we can validate the payment to paypal
        // and create the prestashop order
        $ppec->doExpressCheckout();
        validateOrder($customer, $cart, $ppec);
        unset($ppec->context->cookie->{PaypalExpressCheckout::$cookie_name});
        if (!$ppec->currentOrder) {
            $ppec->logs[] = $ppec->l('Cannot create order');
        } else {
            $id_order = (int) $ppec->currentOrder;
            $order = new Order($id_order);
        }
        /* Check payment details to display the appropriate content */
        if (isset($order) && $ppec->result['ACK'] != "Failure") {
            $values = array('key' => $customer->secure_key, 'id_module' => (int) $ppec->id, 'id_cart' => (int) $cart->id, 'id_order' => (int) $ppec->currentOrder);
            if (version_compare(_PS_VERSION_, '1.5', '<')) {
                $query = http_build_query($values, '', '&');
                Tools::redirectLink(_MODULE_DIR_ . $ppec->name . '/express_checkout/payment.php?' . $query);
            } else {
                $link = $ppec->context->link->getModuleLink('paypal', 'submit', $values);
Example #2
0
function postOrder()
{
    $request = \Slim\Slim::getInstance()->request();
    $order = json_decode($request->getBody());
    $ordersSql = "INSERT INTO orders (email_id, status, created_at, updated_at) VALUES (:email_id, :status, :created_at, :updated_at)";
    $orderItemsSql = "INSERT INTO order_items (order_id, name, price, quantity, created_at, updated_at) VALUES (:order_id, :name, :price, :quantity, :created_at, :updated_at)";
    $valid = json_decode(validateOrder($order));
    if (!$valid->status) {
        echo json_encode($valid);
        return;
    }
    $db = getConnection();
    try {
        $timestamp = date('Y-m-d G:i:s');
        $ordersStmt = $db->prepare($ordersSql);
        $ordersStmt->bindParam("email_id", $order->email_id);
        $ordersStmt->bindParam("status", $order->status);
        $ordersStmt->bindParam("created_at", $timestamp);
        $ordersStmt->bindParam("updated_at", $timestamp);
        $orderItemsStmt = $db->prepare($orderItemsSql);
        $orderItemsStmt->bindParam("name", $order->name);
        $orderItemsStmt->bindParam("price", $order->price);
        $orderItemsStmt->bindParam("quantity", $order->quantity);
        $orderItemsStmt->bindParam("created_at", $timestamp);
        $orderItemsStmt->bindParam("updated_at", $timestamp);
        $db->beginTransaction();
        $ordersStmt->execute();
        $order->id = $db->lastInsertId();
        $orderItemsStmt->bindParam("order_id", $order->id);
        $orderItemsStmt->execute();
        $db->commit();
        $db = null;
        echo json_encode(array("status" => true, "message" => "order posted successfully", "order" => $order));
    } catch (PDOException $e) {
        $db->rollBack();
        echo json_encode(array("status" => false, "message" => $e->getMessage()));
    }
}
function getIcons($where = '', $parameters = array(), $orderby = '', $start = 0, $limit = 0)
{
    global $smcFunc;
    validateWhere($where);
    validateOrder($orderby);
    $parameters += array('start' => $start, 'limit' => $limit);
    $sql = $smcFunc['db_query']('', '
		SELECT id_icon, icon 
		FROM {db_prefix}adk_icons 
		' . $orderby . '
		' . $where . '
		' . (empty($limit) && empty($start) ? '' : 'LIMIT {int:start}, {int:limit}'), $parameters);
    $icons = array();
    while ($row = $smcFunc['db_fetch_assoc']($sql)) {
        $icons[] = array('id' => $row['id_icon'], 'icon' => $row['icon']);
    }
    $smcFunc['db_free_result']($sql);
    return $icons;
}
function getDownloadCategories($id_cat = 0, $where = '', $parameters = array(), $orderby = 'c.roworder ASC')
{
    global $smcFunc, $context, $scripturl, $user_info, $adkportal, $current_load;
    //And validate where and order
    if (!empty($where)) {
        $where = ' AND ' . $where;
    }
    validateOrder($orderby);
    //Load categories
    $sql = $smcFunc['db_query']('', 'SELECT
		c.id_cat, c.title, c.description, c.roworder, c.image, c.total, c.id_parent, c.groups_can_view, c.groups_can_add, c.error
		FROM {db_prefix}adk_down_cat AS c
		WHERE 1=1
			' . (!$user_info['is_admin'] && !allowedTo('adk_downloads_manage') ? 'AND (FIND_IN_SET(' . implode(', c.groups_can_view) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', c.groups_can_view) != 0)' : '') . '
			' . $where . '
		' . $orderby, $parameters);
    $context['all_cat'] = array();
    $context['all_parent'] = array();
    $width = 30;
    //Set the index_cat
    $index_cat = array();
    while ($row = $smcFunc['db_fetch_assoc']($sql)) {
        if ($row['id_parent'] == $id_cat) {
            $context['all_cat'][$row['id_cat']] = array('post' => array(), 'id_cat' => $row['id_cat'], 'title' => $row['title'], 'description' => parse_bbc($row['description']), 'roworder' => $row['roworder'], 'image' => $row['image'], 'total' => !empty($context['all_cat'][$row['id_cat']]['total']) ? $context['all_cat'][$row['id_cat']]['total'] + $row['total'] : $row['total'], 'has_error' => !empty($row['error']));
            //Return The Last Download ;)
            $context['all_cat'][$row['id_cat']]['post'] = PleaseCheckMyLastDownload($row['id_cat']);
            //For RewriteUrls
            $context['rewrite_adk']['cat'][$row['id_cat']] = $row['title'];
            $context['rewrite_adk']['download'][$context['all_cat'][$row['id_cat']]['post']['id']] = $context['all_cat'][$row['id_cat']]['post']['download'];
        } else {
            $context['all_parent'][$row['id_parent']][$row['id_cat']] = '<a href="' . $scripturl . '?action=downloads;cat=' . $row['id_cat'] . '">' . $row['title'] . '</a>';
            $context['all_cat'][$row['id_parent']]['total'] = !empty($context['all_cat'][$row['id_parent']]['total']) ? $context['all_cat'][$row['id_parent']]['total'] + $row['total'] : $row['total'];
            $context['all_parent_new'][$row['id_parent']][] = array('has_error' => !empty($row['error']), 'id_cat' => $row['id_cat'], 'title' => $row['title']);
            //For RewriteUrls
            $context['rewrite_adk']['cat'][$row['id_cat']] = $row['title'];
        }
    }
    //So let's clean unused categories
    if ($current_load[0] == 'action' && $current_load[1] == 'downloads') {
        foreach ($context['all_cat'] as $id_cat => $cat_info) {
            if (empty($cat_info['title'])) {
                unset($context['all_cat'][$id_cat]);
            }
        }
    }
    $smcFunc['db_free_result']($sql);
}