/**
  * @param $propertyId
  * @return mixed
  */
 public function removeFavourite($propertyId)
 {
     $response = VendirunApi::makeRequest('property/removeFavourite', ['token' => Session::get('token'), 'property_id' => $propertyId]);
     if (!$response->getSuccess()) {
         Session::flash('vendirun-alert-error', $response->getError());
     }
     return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.propertyView', ['id' => $propertyId]);
 }
 public function __construct()
 {
     parent::__construct();
     if (!CustomerHelper::checkLoggedinCustomer()) {
         $path = Request::getPathInfo() . (Request::getQueryString() ? '?' . Request::getQueryString() : '');
         Session::put('attemptedAction', $path);
         Session::save();
         Redirect::route(LocaleHelper::localePrefix() . 'vendirun.register')->send();
     }
 }
 /**
  * @return mixed
  */
 public function processReset()
 {
     try {
         VendirunApi::makeRequest('customer/passwordReset', ['email' => Request::get('email'), 'token' => Request::get('token'), 'password' => Request::get('password')]);
         return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.passwordResetOk');
     } catch (FailResponseException $e) {
         $data['pageTitle'] = trans('vendirun::customer.recoverPassword');
         $data['alertMessage'] = trans('vendirun::customer.recoverPasswordFail2');
         $data['token'] = Request::get('token');
         return View::make('vendirun::customer.password.reset-form', $data);
     }
 }
 /**
  * @param $slug
  * @return mixed
  */
 public function post($slug)
 {
     $data = [];
     try {
         $post = VendirunApi::makeRequest('blog/post', ['slug' => $slug, 'token' => CustomerHelper::checkLoggedinCustomer()]);
         $data['post'] = $post->getData();
     } catch (FailResponseException $e) {
         $errors = json_decode($e->getMessage());
         if (isset($errors->try_with_login)) {
             if (CustomerHelper::checkLoggedinCustomer()) {
                 return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.noPermissions');
             }
             return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.register')->withErrors('Please login to view this content');
         }
         abort('404');
     }
     return View::make('vendirun::blog.post', $data);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $segment = $request->segment(1);
     if (in_array($segment, LocaleHelper::validLocales())) {
         app()->setLocale($segment);
     } else {
         $clientInfo = VendirunApi::makeRequest('client/publicInfo')->getData();
         app()->setLocale($clientInfo->primary_language->language_code);
     }
     // if it's a CMS page, we need to get rid of the locale part of the URL so we get the actual slug
     if ($request->route()->getName() == 'vendirun.cmsPage') {
         $path = $request->route()->parameter('catchall');
         $pathArray = explode('/', $path);
         if (in_array($pathArray[0], LocaleHelper::validLocales())) {
             $request->route()->setParameter('catchall', str_replace($request->segment(1) . '/', '', $path));
         }
     }
     return $next($request);
 }
 /**
  * @param      $productId
  * @param      $productName
  * @param int $variationId
  * @param bool $addToCart
  * @return string
  */
 private function getProductRoute($productId, $productName, $variationId = 0, $addToCart = false)
 {
     return route(LocaleHelper::localePrefix() . $addToCart ? 'vendirun.productAddToCart' : 'vendirun.productView', array_merge(['productId' => $productId, 'productName' => urlencode(strtolower($productName)), 'variationId' => $variationId], Request::query()));
 }
 /**
  * Returns full list of available actions with the relevant URI listed
  */
 public function index()
 {
     return $this->respond(true, ['cart' => ['calculate' => ['method' => 'GET', 'endpoint' => route(LocaleHelper::localePrefix() . 'vendirun.api.cart.calculate'), 'requiredParameters' => ['shippingCountryId' => 'int'], 'optionalParameters' => ['shippingType' => 'string']], 'add' => ['method' => 'POST', 'endpoint' => route(LocaleHelper::localePrefix() . 'vendirun.api.cart.add'), 'requiredParameters' => ['productVariationId' => 'int'], 'optionalParameters' => ['quantity' => 'int']], 'remove' => ['method' => 'POST', 'endpoint' => route(LocaleHelper::localePrefix() . 'vendirun.api.cart.remove'), 'requiredParameters' => ['productVariationId' => 'int'], 'optionalParameters' => ['quantity' => 'int']]], 'product' => ['find' => ['method' => 'GET', 'endpoint' => route(LocaleHelper::localePrefix() . 'vendirun.api.product.find', ['productId' => '*productId*']), 'requiredParameters' => ['productId' => 'int'], 'optionalParameters' => []]]]);
 }
 /**
  * @param $callbackData
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 private function doEmailVerification($callbackData)
 {
     try {
         $params = ['email' => $callbackData['email'], 'callback_url' => route(LocaleHelper::localePrefix() . 'vendirun.emailConfirmAction'), 'callback_data' => json_encode($callbackData)];
         VendirunApi::makeRequest('customer/verifyEmail', $params);
         return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.emailConfirm');
     } catch (FailResponseException $e) {
         return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.register')->withInput()->withErrors($e->getMessage());
     }
 }
 /**
  * @param OrderRepository   $orderRepository
  * @param int               $orderId
  * @return \Illuminate\Http\RedirectResponse
  */
 public function paypalSuccess(OrderRepository $orderRepository, $orderId)
 {
     $order = $orderRepository->find($orderId, Session::get('orderOneTimeToken', NULL));
     $paymentGateway = new PaypalPaymentGateway($order, $orderRepository);
     $paymentGateway->confirmPayment(Request::all());
     return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.checkoutSuccess', ['orderId' => $order->getId()]);
 }
 /**
  * Clear the search and redirect to index
  */
 public function clearSearch()
 {
     Session::forget('searchParams');
     return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.propertySearch');
 }