public static function setAttemptStatus(Attempt $attemptModel, $status) { if (!in_array($status, self::$_statuses) || !$attemptModel->attempt_id) { return false; } $attemptModel->status = $status; $attemptModel->save(false); }
public function createHandle() { $pr = DirectoryHelpers::getPagerank(e(Input::get('url'))); $valid_domain = function ($domain_name) { return preg_match("/^([a-z\\d](-*[a-z\\d])*)(\\.([a-z\\d](-*[a-z\\d])*))*\$/i", $domain_name) && preg_match("/^.{1,253}\$/", $domain_name) && preg_match("/^[^\\.]{1,63}(\\.[^\\.]{1,63})*\$/", $domain_name); //length of each label }; $format_url = rtrim(str_replace(['http://', 'https://'], '', e(Input::get('url'))), '/'); if (!$valid_domain($format_url)) { Session::put('category_id', e(Input::get('category_id'))); return Redirect::back()->with('url_error', trans('directory.invalid_url'))->withInput(); } $url_details = parse_url(e(Input::get('url'))); $final_url = isset($url_details['scheme']) ? $url_details['scheme'] . '://' . $format_url : 'http://' . $format_url; Input::merge(array('url' => $final_url)); $nice_input_names = ['category_id' => trans('directory.select_category'), 'name' => trans('directory.name'), 'url' => trans('directory.url'), 'format_url' => trans('directory.url'), 'description' => trans('directory.description'), 'keywords' => trans('directory.keywords')]; $rules = ['category_id' => 'not_in:"0"', 'name' => 'required|between:6,260', 'url' => 'required|url|between:6,100|unique:domains', 'description' => 'required|between:200,1000', 'keywords' => 'between:5,255']; if (!Auth::check()) { $nice_input_names['g-recaptcha-response'] = 'captcha'; $rules['g-recaptcha-response'] = 'required|recaptcha'; } $coma_replace = function ($string) { return str_replace(',', ', ', $string); }; if (strlen(str_replace(' ', '', e(Input::get('description')))) < 200 && Auth::user()->type != User::ADMIN_USER) { $attempt = new Attempt(); $attempt->user_id = Auth::check() ? Auth::user()->id : null; $attempt->category_id = (int) e(Input::get('category_id')); $attempt->url = 'http://' . $format_url; $attempt->name = e(Input::get('name')); $attempt->description = $coma_replace(DirectoryHelpers::correctText(e(Input::get('description')), '.')); $attempt->keywords = $coma_replace(e(Input::get('keywords'))); $attempt->save(); return Redirect::back()->with('error', 'Descrierea este prea scurtă')->withInput(); } $validator = Validator::make(array_map('trim', Input::all()), $rules, [], $nice_input_names); if ($validator->fails()) { Session::put('category_id', e(Input::get('category_id'))); return Redirect::back()->withErrors($validator)->withInput(); } $status = Acl::isSuperAdmin() ? 1 : 0; $domain = new Domain(); $domain->category_id = (int) e(Input::get('category_id')); $domain->status = $status; $domain->name = $coma_replace(e(Input::get('name'))); $domain->url = 'http://' . $format_url; $domain->page_rank = $pr; $domain->description = $coma_replace(DirectoryHelpers::correctText(e(Input::get('description')), '.')); $domain->keywords = $coma_replace(e(Input::get('keywords'))); try { $domain->thumb = DirectoryHelpers::generateThumb($domain->url); } catch (Exception $ex) { Log::error($ex->getMessage()); } if ($domain->save()) { Acl::addAdmin($domain); return Redirect::route('domain.create')->with('success', trans('directory.domain_added')); } return Redirect::back()->with('error', trans('directory.domain_add_error')); }
private function createAttempt($attemptType, $amount) { $attemptModel = new Attempt(); $attemptModel->created = 'NOW():sql'; $attemptModel->order_id = $this->orderModel->order_id; $attemptModel->gateway_id = $this->gatewayModel->gateway_id; $attemptModel->status = Attempt::NEW_STATUS; $attemptModel->attempt_type = $attemptType; $attemptModel->attempt_number = Attempt::getAttemptNumberByOrderID($this->orderModel->order_id); $attemptModel->amount = $amount; $attemptModel->save(); $this->attemptModel = $attemptModel; //add attempt model to payment system $this->_ps->setModel($this->attemptModel); }
public static function createAttempt($billing_cycle = null) { $msql = SafeMySQL::getInstance(); // Select attempt $sql = "SELECT NOW() as `created`, o.order_id, o.gateway_id, 'debit' as `attempt_type`, IF(MAX(a2.attempt_number) IS NULL, 1, MAX(a2.attempt_number)+1) as `attempt_number`, `o`.`amount_product` + `o`.`amount_shipping` as `amount`, 'new' as `status`\n FROM `orders` as `o`\n LEFT JOIN `attempts` as `a` ON `o`.`order_id`=`a`.`order_id` AND `a`.`status` IN ('new', 'inprogress', 'submitted', 'success', 'chargeback')\n LEFT JOIN `attempts` as `a2` ON `o`.`order_id`=`a2`.`order_id`\n LEFT JOIN `cron_upd` as `cr` ON `o`.`order_id`=`cr`.`id` AND `cr`.`type`= 'orders'\n WHERE `o`.`status` = 'new'\n AND `o`.`updated` < DATE_SUB(NOW(), INTERVAL 10 MINUTE)\n AND FIND_IN_SET('pay', `o`.`flags`)>0\n AND FIND_IN_SET('test', `o`.`flags`)=0\n AND `a`.`attempt_id` IS NULL\n AND `cr`.`id` IS NULL "; if ($billing_cycle !== null) { $sql .= " AND `o`.`billing_cycle` "; if ($billing_cycle) { $sql .= " > 0 "; } else { $sql .= " = 0 "; } } $sql .= "\n\t\t\t\t\tGROUP BY `o`.`order_id`\n ORDER BY `o`.`order_id`\n LIMIT 1"; $result = $msql->getRow($sql); if (!$result) { return false; } $modelAttempt = new Attempt(); $sql = "INSERT IGNORE INTO cron_upd (`type`, `id`) VALUES ('orders', ?i)"; $msql->query($sql, $result['order_id']); $c = $msql->affectedRows(); if (!$c) { return $modelAttempt; } $modelAttempt->created = $result['created']; $modelAttempt->order_id = $result['order_id']; $modelAttempt->gateway_id = $result['gateway_id']; $modelAttempt->attempt_type = $result['attempt_type']; $modelAttempt->attempt_number = $result['attempt_number']; $modelAttempt->amount = $result['amount']; $modelAttempt->status = $result['status']; $modelAttempt->save(); return $modelAttempt; /* $sql = "DELETE FROM cron_upd WHERE `type` = 'orders' AND `id`=?i"; $msql->query($sql, $result['order_id']); */ /* try { // Open transaction $msql->query("START TRANSACTION"); $attemptID=null; if($result) { $sql="INSERT INTO `attempts` SET ?u"; $msql->query($sql, $result); $attemptID=$msql->insertId(); } // Close transaction $msql->query("COMMIT"); } catch (Exception $e) { // An exception has been thrown $msql->query("ROLLBACK"); return false; } return ($attemptID)?Attempt::model()->findByPk($attemptID):false; */ /* $sql="INSERT INTO `attempts` (`created`, `order_id`, `gateway_id`, `attempt_type`, `attempt_number`, `amount`, `status`) SELECT NOW(), o.order_id, o.gateway_id, 'debit', IF(MAX(a2.attempt_number) IS NULL, 1, MAX(a2.attempt_number)+1), `o`.`amount_product` + `o`.`amount_shipping`, 'new' FROM `orders` as `o` LEFT JOIN `attempts` as `a` ON `o`.`order_id`=`a`.`order_id` AND `a`.`status` IN ('new', 'inprogress', 'submitted', 'success', 'chargeback') LEFT JOIN `attempts` as `a2` ON `o`.`order_id`=`a2`.`order_id` WHERE `o`.`status` = 'new' AND `o`.`updated` < DATE_SUB(NOW(), INTERVAL 10 MINUTE) AND FIND_IN_SET('pay', `o`.`flags`)>0 AND FIND_IN_SET('test', `o`.`flags`)=0 AND `a`.`attempt_id` IS NULL GROUP BY `o`.`order_id` ORDER BY `o`.`order_id` LIMIT 1"; $msql->query($sql); if(!$attepmtID=$msql->insertId()) return false; $model=Attempt::model() ->findByPk($attemptID); return ($model->attempt_id)?$model:false; */ }
public function attempt($type, $data) { $attempt = new Attempt(); $attempt->type = $type; $attempt->data = $data; $attempt->ip_address = $this->app->request->getClientIp(); return $attempt->save(); }