$app->error($e); } } else { $app->flash('info', 'Your cart is empty. Please, fill up your cart with some of our products and come back to the checkout later.'); $app->redirect($app->view()->url('/')); } }); $app->get('/shop/expresscheckout/return', $require_ssl, function () use($app, $db, $config) { if (isset($_GET["token"]) && isset($_GET["PayerID"])) { $token = $_GET["token"]; $payerid = $_GET["PayerID"]; $cart = $app->view()->getData('cart'); $payment = new \Helpers\Payment($config); try { $result = $payment->do_express_checkout($token, $payerid, $cart); \Data\OrderRepository::add_order($db, $_SESSION['user_id'], $cart['total'], $cart['tax']); // \Data\ProductsRepository::update_stock($db, $cart); \Data\CartRepository::clear_cart($db, $_SESSION['user_id']); unset($_SESSION['user_id']); $app->view()->set_template('layouts/basic.php'); $app->render('shop/payment.php', array('page_title' => 'ORDER CONFIRMATION', 'title' => 'ORDER', 'subtitle' => 'Thank you for placing your order at WildVapor Inc', 'message' => $result)); } catch (\Exception $e) { $app->error($e); } } else { $app->error(new \Exception('This is an error. Don\'t panic!!!!!!!!!!...')); } }); $app->get('/shop/expresscheckout/cancel', $require_ssl, function () use($app, $db, $config) { $app->view()->set_template('layouts/basic.php'); $app->render('shop/payment.php', array('page_title' => 'Payment Cancel', 'title' => 'Cancel', 'subtitle' => 'You have canceled your payment at WildVapor Inc.', 'message' => 'We are very sorry for your cancelation, we hope that you start buying our products again soon.'));
$app->redirect($app->view()->url_secure('/users/' . $id . '/account')); } $data['use_same_address'] = isset($data['use_same_address']) ? 1 : 0; $stmt = \Data\UserRepository::update_user($db, $data, $id); if ($stmt) { $app->flash('info', 'User Updated.'); $app->redirect($app->view()->url('/users/' . $id)); } else { $app->error(new \Exception('Error updating user. Please, try again later.')); } }); $app->get('/users/:id/orders', $authenticate, function ($id) use($app, $db) { if ($id != $_SESSION['user_id']) { $app->notFound(); } $orders = \Data\OrderRepository::get_orders_by_user_id($db, $id); $app->view()->set_template('layouts/basic.php'); $app->render('users/orders.php', array('page_title' => 'Your Orders', 'orders' => $orders)); }); $app->get('/users/:uid/orders/:oid', $authenticate, function ($uid, $oid) use($app, $db) { if ($uid != $_SESSION['user_id']) { $app->notFound(); } $order_contents = \Data\OrderRepository::get_order_contents($db, $oid); if ($order_contents) { $app->view()->set_template('layouts/basic.php'); $app->render('users/order_contents.php', array('page_title' => 'Your Order', 'order_contents' => $order_contents, 'order_id' => $oid)); } else { $app->notFound(); } });