public function request() { $api = new Api(); $data = []; if ($api->key()) { try { $data = $api->ContrInfo(); } catch (\Exception $e) { } } $rules = ['address1' => 'required', 'address2' => 'required', 'orderText' => 'required', 'comment' => '']; // тип формы "новый клиент" (иначе - авторизованный) if (!$api->key()) { Validation::prepareInput(['phone']); $rules['phone'] = 'required|phone'; $rules['email'] = 'required|email'; } Input::merge(array_map('trim', Input::all())); $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return $this->responseError($validator, $validator->errors()->first()); } $fields = array_keys($rules); foreach ($fields as $key) { $data[$key] = Input::get($key); } Mailer::requestOrderMessage($data); OrderRequest::unguard(); OrderRequest::create(['email' => $data['email'], 'phone' => Customer::instance()->phone($data['phone']), 'address1' => $data['address1'], 'address2' => $data['address2'], 'orderText' => $data['orderText'], 'comment' => $data['comment']]); return $this->responseSuccess(['email' => $data['email'], 'phone' => Customer::instance()->phone($data['phone']), 'address' => $data['address1']], 'Заказ оформлен'); }
/** * личный кабинет * * @return \Illuminate\View\View */ public function index() { if (Input::get('orderNumber')) { return Redirect::to('/account'); } Customer::instance()->closeIfNotMember(); $promo = null; $mainPage = Config::get('app.url'); $langReplace = App::getLocale() == 'ru' ? 'index' : App::getLocale(); $mainPage = str_replace('#lang#', $langReplace, $mainPage); try { $api = new Api(); if (!$api->key()) { return \Redirect::to($mainPage); } $user = $api->ContrInfo(); $promo = $this->promoInfo($user, $promo); //$token = PaymentCloud::getToken($user['id']); $agbisKey = $api->key(); $customer = Customer::instance()->initByExternalId($user['id']); if (!$customer->get()) { Reporter::errorLostExternalCustomer($user['id'], $user); $customer->cleanup(); $api->cleanup(); return \Redirect::to($mainPage); } $saveCard = $customer->isSaveCard(); $cards = PaymentCloud::getCustomersCards($api->id()); } catch (ApiException $e) { return \Redirect::to($mainPage); } $invite = new InviteComponent(); return View::make('ac::index', ['user' => $user, 'promo' => $promo, 'agbisKey' => $agbisKey, 'saveCard' => $saveCard, 'invite_url' => $invite->url(), 'cards' => $cards]); }
public function show() { $customer = $this->getCustomer(); if (!$customer) { return $this->responseError(['Данные не доступны'], 'Требуется авторизация', 401); } $api = new Api(); try { $key = $api->key(); Reporter::aggregateExternalInfoStart($key, $api->id(), $customer->get()->id); $client = $api->_cache_customer_info($key); $client['key'] = $key; try { $promo = $api->PromoCodeUse($key); } catch (ApiException $e) { if ($e->isDataError()) { $promo = null; } else { throw $e; } } $client['promo'] = $promo; Reporter::aggregateExternalInfoEnd($customer->get()->id); $customer->updateExternalInfo($client); return $this->responseSuccess($client, 'Данные клиента'); } catch (ApiException $e) { $api->cleanup(); return $this->responseException($e, 'Не удалось получить данные', 'customer'); } }
/** * логаут * @return \Response */ public function logout() { $api = new Api(); $key = Input::get('key'); if (!$key) { $key = $api->key(); } try { $api->Logout($key); return $this->responseSuccess([], 'Сессия остановлена'); } catch (\Exception $e) { return $this->responseException($e, 'Ошибка удаления сессии'); } }
protected function getCustomer() { $api = new Api(); Customer::instance()->closeIfNotMember(); // ключ из запроса $keyRequest = Input::get('key'); // наш ключ клиента $keyCustomer = Customer::instance()->key(); // id сессии агбиса $keyAgbis = $api->key(); // при наличии нашего ключа плюс ключа агбиса // это значит что мы держим вполне живую сессию if ($keyCustomer && $keyAgbis) { $customer = Customer::instance()->initByKey(); Reporter::customerTouchKey($keyCustomer, $keyAgbis, $customer->get()->agbis_id); return $customer; } Reporter::customerEmptyKey($keyCustomer, $keyAgbis); // нет своего ключа но есть ключ агбис или ключ запроса (он же ключ агбис) // это значит что свой ключ мы еще не выдали по какой то причине // поэтому работаем по ключу агбиса (из запроса - приоритетнее) Reporter::customerTouchExternalKey($keyRequest, $keyAgbis); $keyAgbis = $keyRequest ? $keyRequest : $keyAgbis; if ($keyAgbis) { try { $user = $api->_cache_customer_info($keyAgbis); $api->memory((object) ['id' => $user['id'], 'key' => $keyAgbis]); // получили человека по агбису, найдем его у нас и создадим свою сессию $customer = Customer::instance()->initByExternalId($user['id']); if ($customer) { $key = $customer->startSession(); Reporter::loginNewKey($customer->get()->agbis_id, $key); return $customer; } // иначе это значит, что в нашей базе пользователя нет // придется его выбросить и пусть авторизуется заново Reporter::customerLostExternalKey($keyAgbis); } catch (ApiException $e) { Reporter::customerFailExternalKey($keyAgbis); } } else { Reporter::customerEmptyExternalKey(); } Customer::instance()->destroySession(); return null; }