/** * This method is called before the first test is executed. */ public static function setUpBeforeClass() { $transaction = \Transaction::getInstance(); $user = new \User(); $user->setTimezone("Europe/Paris"); $transaction->setUser($user); }
/** * Initialize the experiment and set all required tracking things * * @param string $experimentName * @param array $experimentConfig */ private static function startExperiment($experimentName, array $experimentConfig) { wfDebug(sprintf("%s[%s] using %s class with %s params\n", __METHOD__, $experimentName, $experimentConfig['handler'], json_encode($experimentConfig['params']))); new $experimentConfig['handler']($experimentConfig['params'] ?: []); // mark a transaction with an experiment name \Transaction::getInstance()->set(\Transaction::PARAM_AB_PERFORMANCE_TEST, $experimentName); // set a global JS variable with an experiment name global $wgHooks; $wgHooks['WikiaSkinTopScripts'][] = function (array &$vars, &$scripts) use($experimentName) { $vars['wgABPerformanceTest'] = $experimentName; return true; }; /* * Start the session to bypass CDN cache * * We don't want to polute the CDN cache with the A/B performance testing tracking data. * As the test are run for only a small subset of the traffic, start the session for client * that are in the test groups to bypass the CDN cache. */ if (session_id() == '') { wfSetupSession(); wfDebug(__METHOD__ . " - session started\n"); // log started sessions global $wgUser; WikiaLogger::instance()->info(__METHOD__, ['experiment' => $experimentName, 'session_id' => session_id(), 'is_anon' => $wgUser->isAnon()]); } }
/** * Returns the formatter instance. Creates a new one if doesn't exist yet. * Uses the timezone of the user of the current transaction. * * @return Formatter */ public static function getInstance() { if (!self::$theInstance) { $user = Transaction::getInstance()->getUser(); self::$theInstance = new Formatter($user->getTimezone(), $user->getLocale()); } return self::$theInstance; }
/** * This method is called before the first test is executed. */ public static function setUpBeforeClass() { $transaction = \Transaction::getInstance(); $user = new \User(); $user->setTimezone("Europe/Paris"); $transaction->setUser($user); $zend_locale = new \Zend_Locale("en_US"); \Zend_Registry::set('Zend_Locale', $zend_locale); }
/** * Returns the DataConverter instance. Creates a new one if doesn't exist yet. * Uses the timezone of the user of the current transaction. * @return DataConverter */ public static function getInstance() { if (!self::$theInstance) { $timezone = Transaction::getInstance()->getUser()->getTimezone(); $locale = Transaction::getInstance()->getUser()->getLocale(); self::$theInstance = new DataConverter($timezone, $locale); } return self::$theInstance; }
public static function setUpBeforeClass() { $transaction = \Transaction::getInstance(); $user = new \User(); $user->setTimezone("America/Los_Angeles"); $user->setLocale("en_US"); $user->setIsAdmin(true); $transaction->setUser($user); }
public function getItems() { $user = Transaction::getInstance()->getUser(); $items = array(); foreach ($this->xml->item as $element) { $item = new MenuItem($this, $element); if ($item->getId() == $this->mainMenuId) { $item->setSelected(true); } if (!$item->isAdminOnly() || $user->isAdmin()) { $items[] = $item; } } return $items; }
public function service() { try { session_name($this->sessionName); Zend_Session::start(); $transaction = Transaction::getInstance(); $transaction->setUser($this->getContext()->getUser()); self::initTranslator($this->getContext()->getUser()->getLocale()); $this->validate(); $this->invokeControllerMethod(); } catch (Exception $e) { $this->handleException($e); } $logTimeEnabled = Config::getInstance()->getBoolean('webapp/logging/timeLog/enabled', false); if ($logTimeEnabled) { $this->timeLogger->end(); } }
public static function escapeString($str, $withQuotes = true) { if ($str === null) { return "null"; } $db = Transaction::getInstance()->getDB(); $escaped = ''; if (method_exists($db, 'getDB')) { $caller = self::getCallerFunction(); Logger::warning("Depracated: Avoid SQLUtils::escapeString. Use prepared statement. Called by: {$caller}"); $escaped = $db->getDB()->real_escape_string($str); } else { $escaped = mysql_real_escape_string($str); } if ($withQuotes) { $escaped = "'" . $escaped . "'"; } return $escaped; }
/** * Get the unit from the form. If it's defined and different than the * display unit, convert the value and set it back into this control's value. * Then, format with proper number of digits. * * Do not call this method more than once! */ protected function convert() { $user = Transaction::getInstance()->getUser(); if ($this->getValue() !== null && Zend_Locale_Format::isNumber($this->getValue(), array("locale" => $user->getLocale()))) { $form = $this->getForm(); // Get the 'hidden' value, which indicates the unit of the current value. $unit = $form->getValue($this->getUnitFieldName()); // If the unit is different, convert if ($unit && $unit != $this->displayUnit) { $measure = MeasureUtils::newMeasure($unit, $this->getValue(), $user->getLocale()); $unitInfo = MeasureUtils::getUnitInfo($this->displayUnit); $measure->setType($unitInfo['constantName']); // Sets the new value without rounding and without formatting $this->setValue($measure->getValue(-1, $user->getLocale())); } $format = Formatter::getInstance(); // Format and round the value $this->setValue($format->number($format->getNumber($this->getValue()), $this->decimalDigits)); } }
/** * Create a new DateTime object representing the current date/time in the * given timezone. * * @param $timezone (String) the timezone to evaluate the given time in. If * null, the current user's account's timezone will be used. * @return DateTime */ public static function makeDateFromTimestamp($timestamp, $timezone = null) { if (!$timezone) { $timezone = Transaction::getInstance()->getUser()->getTimezone(); } $date = new DateTime("@{$timestamp}"); $tz = new DateTimeZone($timezone); $date->setTimezone($tz); return $date; }
private function startTransaction() { $transaction = Transaction::getInstance(); $user = new User(); $timezone = Config::getInstance()->getString("properties/anonymousUserTimezone"); $user->setTimezone($timezone); // TODO: set id to root. $user->setId(1); $transaction->setUser($user); }
* along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ require_once '../../core.php'; //change to your gateway's name define('GWNAME', 'othertestgateway'); define('INVOICE', (int) $_REQUEST['inv']); define('AMOUNT', (int) $_REQUEST['received']); define('KEY', $_REQUEST['secretkey']); define('COMMENT', ''); $gm = GatewayModule::getInstance(); $curr = Currency::getInstance(); $service = Service::getInstance(); $invoice = Invoice::getInstance(); $tr = Transaction::getInstance(); //finding ID for this gateway $gwid = $gm->GetID(GWNAME); if (!$gwid) { die("This gateway is not activated and configured to accept payments"); } $gmdata = $gm->FetchData($gwid); $invdata = $invoice->FetchData(INVOICE); $currency = $curr->FetchData($curr->GetID($gmdata['currency'], 'name')); //$currency = $curr->GetCurrency('',$gmdata['currency']); $gateway_data = unserialize($gmdata['data']); if ($invdata['amount'] > AMOUNT * $currency['rate']) { echo "Received amount is not enough for this invoice"; //send some notifications exit; } elseif ($gateway_data['key'] != KEY) {
public static function ManageTrans() { $xtpl = self::$xtpl; $user = User::getInstance(); $gm = GatewayModule::getInstance(); if (!is_numeric(self::$page)) { $page = 1; } else { $page = self::$page; } $xtpl->assign('FINCURR', 'current'); $xtpl->assign('MANAGETRANS', 'current'); $trans = Transaction::getInstance(); $transbutch = $trans->GetButch(self::$per_page, 1, 'id', 'DESC', self::$per_page * $page - self::$per_page); if (count($transbutch) > 0) { for ($i = 0; $i < count($transbutch); $i++) { $username = ''; $gatewayname = ''; if (!is_numeric($transbutch[$i]['customerid']) || !is_string($username = $user->GetUsername($transbutch[$i]['customerid']))) { self::add_message($xtpl, 'attention', 'User #' . $transbutch[$i]['customerid'] . ' not found for transaction #' . $transbutch[$i]['id']); } else { $xtpl->assign('USERNAME', $username); } if (!is_numeric($transbutch[$i]['gatewayid']) || !is_string($gatewayname = $gm->GetName($transbutch[$i]['gatewayid']))) { self::add_message($xtpl, 'attention', 'Payment gateway #' . $transbutch[$i]['gatewayid'] . ' not found for transaction #' . $transbutch[$i]['id']); } else { $xtpl->assign('GATEWAYNAME', $gatewayname); } $xtpl->assign('TRANS', $transbutch[$i]); $xtpl->parse('main.managetrans.transtable.transrow'); } for ($i = 1; $i <= self::count_pages($trans->Calculate()); $i++) { if ($page == $i) { $xtpl->assign('CURRENT', 'current'); } else { $xtpl->assign('CURRENT', ''); } $xtpl->assign('NUM', $i); if (preg_match('/page=[0-9]+/', self::$request_uri)) { $link = preg_replace('/page=[0-9]+/', 'page=' . $i, self::$request_uri); } else { $link = self::$request_uri . '&page=' . $i; } $xtpl->assign('LINK', $link); $xtpl->parse('main.managetrans.transtable.page'); } $xtpl->parse('main.managetrans.transtable'); } else { $xtpl->parse('main.managetrans.transinfo'); } $xtpl->parse('main.managetrans'); $xtpl->parse('main'); $xtpl->out('main'); }
/** * Localization array for the Jquery UI date time picker. * @return array */ private function getDatePickerLocalization() { $daysArr = Zend_Locale_Data::getList(Transaction::getInstance()->getUser()->getLocale(), "days"); $weekArr = Zend_Locale_Data::getList(Transaction::getInstance()->getUser()->getLocale(), "week"); $firstDay = $daysArr['format']['narrow'][$weekArr["firstDay"]] - 1; $tr = Application::getTranslator(); // Most i18n values come from dedicated jquery.ui.datepicker-<LANG>.js // Make sure to include this file on all pages. // The fields defined here are the ones used by the datetimepicker extension. $regional = array("closeText" => $tr->_('Done'), "dateFormat" => $tr->_('m/dd/yy'), "firstDay" => $firstDay, "isRTL" => false, "showMonthAfterYear" => false, "yearSuffix" => ''); if ($this->showTime) { $regional["currentText"] = $tr->_('Now'); $regional["amNames"] = array('AM', 'A'); $regional["pmNames"] = array('PM', 'P'); // Important: timeFormat must be compatible with pattern used by Formatter::datetime for each locale $regional["timeFormat"] = $tr->_('h:mm TT'); $regional["timeSuffix"] = ''; $regional["timeOnlyTitle"] = $tr->_('Choose Time'); $regional["timeText"] = $tr->_('Time'); $regional["hourText"] = $tr->_('Hour'); $regional["minuteText"] = $tr->_('Minute'); $regional["secondText"] = $tr->_('Second'); $regional["millisecText"] = $tr->_('Millisecond'); $regional["timezoneText"] = $tr->_('Time Zone'); } return $regional; }
public function create() { $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); $request = $this->application->getRequest(); $orderID = $request->get('orderID'); $currencyID = $request->get('currencyID'); $amount = $request->get('amount'); $method = $request->get('method'); $gatewayTransactionID = $request->get('gatewayTransactionID'); if (intval($orderID) <= 0) { throw new Exception('Order ID is required'); } if (!isset($currencyID) || !isset($method) || !isset($gatewayTransactionID)) { throw new Exception('Complete required fields : currencyID, method, gatewayTransactionID'); } $transaction_result = new TransactionResult(); $transaction_result->currency->set($currencyID); // = $currencyID; $transaction_result->amount->set($amount); //= $amount; $transaction_result->gatewayTransactionID->set($gatewayTransactionID); // = $gatewayTransactionID; $transaction_result->setTransactionType(TransactionResult::TYPE_SALE); $order = CustomerOrder::getInstanceById($orderID); $order->loadAll(); $order_array = $order->toArray(); $user = User::getInstanceByID($order_array['userID']); $user->load(); $order->user->set($user); if ($current_transaction = Transaction::getInstance($order, $gatewayTransactionID)) { $current_transaction->method->set($method); $current_transaction->save(); } else { $new_transaction = Transaction::getNewInstance($order, $transaction_result); $new_transaction->method->set($method); $new_transaction->save(); if (!$this->finalizeOrder($order, $user)) { // Create new order for current user $new_order = CustomerOrder::getNewInstance($user); $new_order->beginTransaction(); $new_order->save(); $new_order->commit(); } } $parser = $this->getParser(); $apiFieldNames = $parser->getApiFieldNames(); $f = new ARSelectFilter(); $f->mergeCondition(new EqualsCond(new ARFieldHandle('Transaction', 'orderID'), $orderID)); $transactions = ActiveRecordModel::getRecordSetArray('Transaction', $f); $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); if (false && count($transactions) == 0) { throw new Exception('Transactions not found'); } while ($transaction = array_shift($transactions)) { $transaction_response = $response->addChild('transaction'); foreach ($transaction as $k => $v) { if (in_array($k, $apiFieldNames)) { $transaction_response->addChild($k, htmlentities($v)); } } } return new SimpleXMLResponse($response); }
private function markScriptExecuted($script) { $db = Transaction::getInstance()->getDB(); $sql = "insert into db_script (path, create_date) values ('" . $script->getFileRelPath() . "', SYSDATE())"; $db->query($sql); }
protected function registerPayment(TransactionResult $result, TransactionPayment $handler) { // transaction already registered? if (Transaction::getInstance($this->order, $result->gatewayTransactionID->get())) { $this->session->set('completedOrderID', $this->order->getID()); return new ActionRedirectResponse('checkout', 'completed'); } $transaction = Transaction::getNewInstance($this->order, $result); $transaction->setHandler($handler); $transaction->save(); $this->order->setPaidStatus(); if ($this->order->isPaid->get()) { $this->order->save(); } return $this->finalizeOrder(); }