예제 #1
0
 /**
  * Send message
  *
  * @return boolean
  */
 public function send()
 {
     if (\XLite\Core\Config::getInstance()->XC->WebmasterKit->logMail) {
         \XLite\Logger::getInstance()->logCustom('mail-messages', 'From: ' . $this->mail->From . PHP_EOL . 'To: ' . $this->get('to') . PHP_EOL . 'Subject: ' . $this->mail->Subject . PHP_EOL . $this->mail->Body . PHP_EOL . PHP_EOL);
     }
     return parent::send();
 }
예제 #2
0
 /**
  * Constructor
  * Creates directory for locks if needed
  */
 public function __construct()
 {
     if (!\Includes\Utils\FileManager::isExists(rtrim(static::LOCK_DIR, LC_DS))) {
         \Includes\Utils\FileManager::mkdirRecursive(rtrim(static::LOCK_DIR, LC_DS));
     }
     if (!\Includes\Utils\FileManager::isReadable(static::LOCK_DIR) || !\Includes\Utils\FileManager::isWriteable(static::LOCK_DIR)) {
         \XLite\Logger::getInstance()->log('Cannot create lock for keys', LOG_DEBUG);
     }
     parent::__construct();
 }
예제 #3
0
 /**
  * Perform actual mapping
  * 
  * @return mixed
  */
 protected function performMap()
 {
     $response = json_decode($this->inputData->body);
     $result = null;
     if (isset($response->error)) {
         \XLite\Logger::logCustom("PitneyBowes", 'ConfirmOrder: ' . $response->error . ' - ' . $response->message, false);
     } else {
         $result = $response;
     }
     return $result;
 }
예제 #4
0
파일: Logger.php 프로젝트: kingsj/core
 /**
  * Constructor
  * FIXME: is it really needed?
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     if (\XLite\Module\CDev\DrupalConnector\Handler::getInstance()->checkCurrentCMS()) {
         // FIXME
         if (defined('LC_CONNECTOR_ROOT')) {
             $path = realpath(LC_CONNECTOR_ROOT . '/../..') . LC_DS;
             $this->filesRepositories[$path] = 'drupal root';
         }
     }
 }
예제 #5
0
 /**
  * Start Doctrine entity manager
  *
  * @return void
  */
 public function startEntityManager()
 {
     parent::startEntityManager();
     if (!defined('LC_CACHE_BUILDING')) {
         if (\XLite\Module\XC\WebmasterKit\Core\Profiler::getInstance()->enabled) {
             static::$em->getConnection()->getConfiguration()->setSQLLogger(\XLite\Module\XC\WebmasterKit\Core\Profiler::getInstance());
         } elseif (\XLite\Core\Config::getInstance()->XC->WebmasterKit->logSQL) {
             static::$em->getConnection()->getConfiguration()->setSQLLogger(\XLite\Logger::getInstance());
         }
     }
 }
예제 #6
0
 /**
  * Return current module object
  *
  * @return \XLite\Model\Module
  * @throws \Exception
  */
 public function getModule()
 {
     if (!isset($this->module)) {
         $this->module = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->find($this->getModuleID());
         if (!$this->module) {
             \XLite\Core\TopMessage::addError('Add-on does not exist.');
             \XLite\Logger::getInstance()->log('Add-on does not exist (ID: ' . $this->getModuleID() . ')', LOG_ERR);
             $this->redirect($this->buildURL('addons_list_installed'));
         }
     }
     return $this->module;
 }
예제 #7
0
 /**
  * Perform actual mapping
  * 
  * @return mixed
  */
 protected function performMap()
 {
     $response = json_decode($this->inputData->body);
     $result = null;
     if (isset($response->error)) {
         \XLite\Logger::logCustom("PitneyBowes", 'CreateInboundParcels: ' . $response->error . ' - ' . $response->message, false);
     } elseif (isset($response->parcelIdentifiers) && is_array($response->parcelIdentifiers)) {
         $result = $response->parcelIdentifiers;
     } elseif (isset($response->parcelIdentifier)) {
         $result = array($response);
     }
     return $result;
 }
예제 #8
0
 /**
  * Perform actual mapping
  * 
  * @return mixed
  */
 protected function performMap()
 {
     $response = json_decode($this->inputData->body);
     $orders = array();
     $rates = array();
     if (isset($response->error)) {
         \XLite\Logger::logCustom("PitneyBowes", 'CreateOrder: ' . $response->error . ' - ' . $response->message, false);
     } elseif (isset($response->order) && is_array($response->order)) {
         foreach ($response->order as $quote) {
             $orders[] = $quote;
             $rates[] = $this->mapSingleQuote($quote->order);
         }
     }
     return array('orders' => array_filter($orders), 'rates' => array_filter($rates));
 }
예제 #9
0
 /**
  * Process callback
  *
  * @return void
  */
 protected function doActionCallback()
 {
     $transaction = $this->detectTransaction();
     if ($transaction) {
         $this->transaction = $transaction;
         $transaction->getPaymentMethod()->getProcessor()->processCallback($transaction);
         $cart = $transaction->getOrder();
         if ($cart instanceof \XLite\Model\Cart) {
             $cart->tryClose();
         }
         $transaction->getOrder()->setPaymentStatusByTransaction($transaction);
         $transaction->getOrder()->update();
         \XLite\Core\Database::getEM()->flush();
     } else {
         \XLite\Logger::getInstance()->log('Request callback with undefined payment transaction' . PHP_EOL . 'Data: ' . var_export(\XLite\Core\Request::getInstance()->getData(), true), LOG_ERR);
     }
     $this->set('silent', true);
 }
예제 #10
0
파일: AForm.php 프로젝트: kingsj/core
 /**
  * Get request data
  *
  * @return mixed
  */
 public function getRequestData()
 {
     $data = null;
     $validator = $this->getValidator();
     try {
         $validator->validate(\XLite\Core\Request::getInstance()->getData());
         $data = $validator->sanitize(\XLite\Core\Request::getInstance()->getData());
     } catch (\XLite\Core\Validator\Exception $exception) {
         $message = static::t($exception->getMessage(), $exception->getLabelArguments());
         if ($exception->isInternal()) {
             \XLite\Logger::getInstance()->log($message, LOG_ERR);
         } else {
             \XLite\Core\Event::invalidElement($exception->getPath(), $message);
         }
         $this->validationMessage = ($exception->getPublicName() ? static::t($exception->getPublicName()) . ': ' : '') . $message;
     }
     return $data;
 }
예제 #11
0
파일: MigrateToS3.php 프로젝트: kingsj/core
 /**
  * Process item
  *
  * @param mixed $item Item
  *
  * @return boolean
  */
 protected function processItem($item)
 {
     $result = false;
     $path = tempnam(LC_DIR_TMP, 'migrate_file');
     file_put_contents($path, $item->getBody());
     if (\Includes\Utils\FileManager::isExists($path)) {
         $localPath = $item->isURL() ? null : $item->getStoragePath();
         $result = $item->loadFromLocalFile($path, $item->getFileName() ?: basename($item->getPath()));
         if ($result && $localPath && \Includes\Utils\FileManager::isExists($localPath)) {
             \Includes\Utils\FileManager::deleteFile($localPath);
         }
         \Includes\Utils\FileManager::deleteFile($path);
     }
     if (!$result) {
         if (!isset($this->record['s3_error_count'])) {
             $this->record['s3_error_count'] = 0;
         }
         $this->record['s3_error_count']++;
         \XLite\Logger::getInstance()->log('Couldn\'t move image ' . $item->getPath() . ' (local file system to Amazon S3)', LOG_ERR);
     }
     return true;
 }
예제 #12
0
 /**
  * Process item
  *
  * @param mixed $item Item
  *
  * @return boolean
  */
 protected function processItem($item)
 {
     $result = false;
     $path = tempnam(LC_DIR_TMP, 'migrate_file');
     file_put_contents($path, $item->getBody());
     if (file_exists($path)) {
         $item->setS3Forbid(true);
         $localPath = $item->getStoragePath();
         $result = $item->loadFromLocalFile($path, $item->getFileName() ?: basename($item->getPath()));
         if ($localPath) {
             \XLite\Module\CDev\AmazonS3Images\Core\S3::getInstance()->delete($localPath);
         }
         unlink($path);
     }
     if (!$result) {
         if (!isset($this->record['s3_error_count'])) {
             $this->record['s3_error_count'] = 0;
         }
         $this->record['s3_error_count']++;
         \XLite\Logger::getInstance()->log('Couldn\'t move image ' . $item->getPath() . ' (Amazon S3 to local file system)', LOG_ERR);
     }
     return true;
 }
예제 #13
0
 /**
  * Uninstall module
  *
  * @param \XLite\Model\Module $module    Module object
  * @param array               &$messages Messages list
  *
  * @return boolean
  */
 public function uninstallModule(\XLite\Model\Module $module, &$messages)
 {
     $result = false;
     // Get module pack
     $pack = new \XLite\Core\Pack\Module($module);
     $dirs = $pack->getDirs();
     $nonWritableDirs = array();
     // Check module directories permissions
     foreach ($dirs as $dir) {
         if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) {
             $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
         }
     }
     $params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName()));
     if (empty($nonWritableDirs)) {
         $yamlData = array();
         $yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName());
         foreach ($yamlFiles as $yamlFile) {
             $yamlData[] = \Includes\Utils\FileManager::read($yamlFile);
         }
         if (!$module->checkModuleMainClass()) {
             $classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass());
             if (\Includes\Utils\FileManager::isFileReadable($classFile)) {
                 require_once $classFile;
             }
         }
         // Call uninstall event method
         $r = $module->callModuleMethod('callUninstallEvent', 111);
         if (111 == $r) {
             \XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called');
         }
         // Remove from FS
         foreach ($dirs as $dir) {
             \Includes\Utils\FileManager::unlinkRecursive($dir);
         }
         \Includes\Utils\ModulesManager::disableModule($module->getActualName());
         \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
         // Remove module from DB
         try {
             // Refresh module entity as it was changed by disableModule() method above
             $module = $this->find($module->getModuleID());
             $this->delete($module);
         } catch (\Exception $e) {
             $messages[] = $e->getMessage();
         }
         if ($module->getModuleID()) {
             $messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params);
         } else {
             if (!empty($yamlData)) {
                 foreach ($yamlData as $yaml) {
                     \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
                 }
             }
             $messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params);
             $result = true;
         }
     } else {
         $messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs)));
     }
     return $result;
 }
예제 #14
0
파일: AView.php 프로젝트: kirkbauer2/kirkxc
 /**
  * Attempts to display widget using its template
  *
  * @param string $template Template file name OPTIONAL
  *
  * @return void
  */
 public function display($template = null)
 {
     // todo: use meaning name
     $flag = null !== $template;
     if ($flag || $this->checkVisibility()) {
         if (!$this->isCloned && !$flag) {
             $this->initView();
         }
         $cacheAvailable = $this->isCacheAllowed($template);
         $content = $cacheAvailable ? $this->getCachedContent() : null;
         if (null !== $content) {
             print $content;
         } else {
             if ($cacheAvailable) {
                 ob_start();
             }
             // Body of the old includeCompiledFile() method
             list($this->currentSkin, $this->currentLocale, $normalized) = $this->getTemplateFile($template);
             if (null === $normalized) {
                 \XLite\Logger::getInstance()->log(sprintf('Empty compiled template. View class: %s, view main template: %s', get_class($this), $this->getTemplate()), \LOG_DEBUG);
             } else {
                 $compiled = \XLite\Singletons::$handler->flexy->prepare($normalized);
                 // Collect the specific data to send it to the finalizeTemplateDisplay method
                 $profilerData = $this->prepareTemplateDisplay($normalized);
                 static::$viewsTail[] = $normalized;
                 include $compiled;
                 array_pop(static::$viewsTail);
                 $this->finalizeTemplateDisplay($template, $profilerData);
             }
             if ($cacheAvailable) {
                 $this->setCachedContent(ob_get_contents());
                 ob_end_flush();
             }
         }
     }
 }
예제 #15
0
 /**
  * Call controller action
  *
  * @return void
  */
 protected function callAction()
 {
     $action = $this->getAction();
     $method = 'doAction' . \Includes\Utils\Converter::convertToPascalCase($action);
     if (method_exists($this, $method)) {
         // Call method doAction<action-name-in-camel-case>
         $this->{$method}();
     } else {
         \XLite\Logger::getInstance()->log('Handler for the action "' . $action . '" is not defined for the "' . get_class($this) . '" class');
     }
     $this->actionPostprocess($action);
 }
예제 #16
0
파일: Callback.php 프로젝트: kingsj/core
 /**
  * Process callback
  *
  * @return void
  */
 protected function doActionCallback()
 {
     $txn = null;
     $txnIdName = 'txnId';
     if (isset(\XLite\Core\Request::getInstance()->txn_id_name)) {
         /**
          * some of gateways can't accept return url on run-time and
          * use the one set in merchant account, so we can't pass
          * 'order_id' in run-time, instead pass the order id parameter name
          */
         $txnIdName = \XLite\Core\Request::getInstance()->txn_id_name;
     }
     if (isset(\XLite\Core\Request::getInstance()->{$txnIdName})) {
         $txn = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Transaction')->find(\XLite\Core\Request::getInstance()->{$txnIdName});
     }
     if (!$txn) {
         $methods = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findAllActive();
         foreach ($methods as $method) {
             if (method_exists($method->getProcessor(), 'getCallbackOwnerTransaction')) {
                 $txn = $method->getProcessor()->getCallbackOwnerTransaction();
                 if ($txn) {
                     break;
                 }
             }
         }
     }
     if ($txn) {
         $txn->getPaymentMethod()->getProcessor()->processCallback($txn);
         $cart = $txn->getOrder();
         if (!$cart->isOpen()) {
             // TODO: move it to \XLite\Controller\ACustomer
             if ($cart->isPayed()) {
                 $status = $txn->isCaptured() ? \XLite\Model\Order::STATUS_PROCESSED : \XLite\Model\Order::STATUS_AUTHORIZED;
             } else {
                 if ($txn->isRefunded()) {
                     $status = \XLite\Model\Order::STATUS_DECLINED;
                 } elseif ($txn->isFailed()) {
                     $status = \XLite\Model\Order::STATUS_FAILED;
                 } else {
                     $status = \XLite\Model\Order::STATUS_QUEUED;
                 }
             }
             $cart->setStatus($status);
         }
     } else {
         \XLite\Logger::getInstance()->log('Request callback with undefined payment transaction' . PHP_EOL . 'Data: ' . var_export(\XLite\Core\Request::getInstance()->getData(), true), LOG_ERR);
     }
     \XLite\Core\Database::getEM()->flush();
     $this->set('silent', true);
 }
예제 #17
0
 /**
  * Add log message
  *
  * @param boolean $status   Status
  * @param array   $request  Request data
  * @param array   $response Response data
  *
  * @return void
  */
 protected function logResponse($status, $request, $response)
 {
     if (\XLite\Core\Config::getInstance()->XC->AuctionInc->debugMode) {
         \XLite\Logger::logCustom('AuctionInc', array('status' => $status, 'request' => $request, 'response' => $response));
     }
 }
예제 #18
0
파일: Main.php 프로젝트: kewaunited/xcart
 /**
  * Add record to the module log file
  *
  * @param string $message Text message OPTIONAL
  * @param mixed  $data    Data (can be any type) OPTIONAL
  *
  * @return void
  */
 public static function addLog($message = null, $data = null)
 {
     if ($message && $data) {
         $msg = array('message' => $message, 'data' => $data);
     } else {
         $msg = $message ?: ($data ?: null);
     }
     if (!is_string($msg)) {
         $msg = var_export($msg, true);
     }
     \XLite\Logger::logCustom(self::getModuleName(), $msg);
 }
예제 #19
0
 /**
  * Import data
  *
  * @param array $data Row set Data
  *
  * @return boolean
  */
 protected function importData(array $data)
 {
     $model = $this->detectModel($data);
     if ($model) {
         $this->setMetaData('updateCount', (int) $this->getMetaData('updateCount') + 1);
     } else {
         $this->setMetaData('addCount', (int) $this->getMetaData('addCount') + 1);
     }
     if (!$model) {
         $model = $this->createModel($data);
         \XLite\Core\Database::getEM()->persist($model);
     }
     $result = $this->updateModel($model, $data);
     if ($result) {
         try {
             \XLite\Core\Database::getEM()->flush();
         } catch (\Exception $e) {
             \XLite\Logger::getInstance()->registerException($e);
             $result = false;
         }
     }
     return $result;
 }
예제 #20
0
 /**
  * Log import notice 
  * 
  * @param string               $message  Message
  * @param integer              $position Row position OPTIONAL
  * @param string               $column   Column name OPTIONAL
  * @param string               $value    Cell value OPTIONAL
  * @param \XLite\Model\Product $product  Product OPTIONAL
  *  
  * @return void
  */
 protected function logImportWarning($message, $position = null, $column = null, $value = null, \XLite\Model\Product $product = null)
 {
     $message = trim($message);
     $this->importCell['warning_count']++;
     if (isset($position)) {
         $message .= PHP_EOL . 'Row number: ' . ($position + 2);
     }
     if (isset($column)) {
         $message .= PHP_EOL . 'Column: ' . $column;
     }
     if (isset($value)) {
         $message .= PHP_EOL . 'Cell value: ' . var_export($value, true);
     }
     if (isset($product)) {
         if ($product->getProductId()) {
             $message .= PHP_EOL . 'Product id: ' . $product->getProductId();
         } elseif ($product->getSku()) {
             $message .= PHP_EOL . 'Product SKU: ' . $product->getSku();
         }
     }
     \XLite\Logger::getInstance()->logCustom('import', $message);
 }
예제 #21
0
 /**
  * Orders collect garbage
  *
  * @return void
  */
 public function collectGarbage()
 {
     // Remove old temporary orders
     $list = $this->findAllExpiredTemporaryOrders();
     if (count($list)) {
         foreach ($list as $order) {
             \XLite\Core\Database::getEM()->remove($order);
         }
         \XLite\Core\Database::getEM()->flush();
         // Log operation only in debug mode
         \XLite\Logger::getInstance()->log(\XLite\Core\Translation::getInstance()->translate('X expired shopping cart(s) have been successfully removed', array('count' => count($list))));
     }
 }
예제 #22
0
 /**
  * Write error to log
  *
  * @param string $error Error message
  * @param mixed $logData Log data
  *
  * @return void
  */
 public static function writeLogError($error, $logData = null)
 {
     if (!is_null($logData)) {
         if (is_scalar($logData)) {
             $logData = strval($logData);
         } else {
             $logData = var_export($logData, true);
         }
         $logData = $error . PHP_EOL . $logData;
     } else {
         $logData = $error;
     }
     \XLite\Logger::getInstance()->logCustom(self::LOG_FILE_ERROR, $logData, true);
 }
예제 #23
0
 /**
  * "Upload" handler for category images.
  *
  * @return void
  */
 protected function doActionSelectUploadLanguageFile()
 {
     $result = null;
     $error = null;
     $message = null;
     $key = 'uploaded_file';
     $cell = isset($_FILES[$key]) ? $_FILES[$key] : null;
     if ($cell) {
         $size = null;
         switch ($cell['error']) {
             case UPLOAD_ERR_OK:
                 $path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, $cell['name']);
                 if (move_uploaded_file($cell['tmp_name'], $path)) {
                     $result = $path;
                 }
                 break;
             case UPLOAD_ERR_INI_SIZE:
                 $size = ini_get('upload_max_filesize');
             case UPLOAD_ERR_FORM_SIZE:
                 $size = $size ?: \XLite\Core\Request::getInstance()->MAX_FILE_SIZE;
                 $error = 'File size exceeds the maximum size (' . $size . ')';
                 $size = \XLite\Core\Converter::convertShortSizeToHumanReadable($size);
                 $message = \XLite\Core\Translation::lbl('File size exceeds the maximum size', array('size' => $size));
                 break;
             case UPLOAD_ERR_PARTIAL:
                 $error = 'The uploaded file was only partially uploaded';
             case UPLOAD_ERR_NO_FILE:
                 $error = $error ?: 'No file was uploaded';
             case UPLOAD_ERR_NO_TMP_DIR:
                 $error = $error ?: 'Missing a temporary folder';
             case UPLOAD_ERR_CANT_WRITE:
                 $error = $error ?: 'Failed to write file to disk';
             case UPLOAD_ERR_EXTENSION:
                 $message = \XLite\Core\Translation::lbl('The file was not loaded because of a failure on the server.');
                 $error = $error ?: 'File upload stopped by extension';
                 break;
             default:
         }
     }
     if ($result && $message) {
         \XLite\Logger::getInstance()->log('Upload file error: ' . $error ?: $message, LOG_ERR);
     }
     $this->doActionSelectLanguageFile($result, $message);
 }
예제 #24
0
 /**
  * Stop script execution
  *
  * :FIXME: - must be static
  *
  * @param string $message Text to display
  *
  * @return void
  */
 protected function doDie($message)
 {
     if (!$this instanceof \XLite\Logger) {
         \XLite\Logger::getInstance()->log($message, LOG_ERR);
     }
     if ($this instanceof XLite || \XLite::getInstance()->getOptions(array('log_details', 'suppress_errors'))) {
         $message = 'Internal error. Contact the site administrator.';
     }
     die($message);
 }
예제 #25
0
 /**
  * Set sale price parameters for products list
  *
  * @param resource $stream Stream
  *
  * @return void
  */
 protected function addFromStreamAction($stream)
 {
     $product = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->find(\XLite\Core\Request::getInstance()->product_id);
     if (!is_resource($stream)) {
         \XLite\Logger::getInstance()->log('No valid resource supplied to add pin codes controller.' . ' Data type: ' . gettype($stream), LOG_ERR);
         \XLite\Core\TopMessage::addError('Unknown error occurred');
     } elseif (!$product) {
         \XLite\Logger::getInstance()->log('No valid product id supplied to add pin codes controller.' . ' Request data: ' . print_r(\XLite\Core\Request::getInstance()->getData(), true), LOG_ERR);
         \XLite\Core\TopMessage::addError('Unknown error occurred');
     } else {
         $codes = array();
         $created = 0;
         $duplicates = 0;
         $exceededLength = 0;
         $maxLength = 64;
         for ($data = fgetcsv($stream); false !== $data; $data = fgetcsv($stream)) {
             $code = trim($data[0]);
             if (strlen($code) > $maxLength) {
                 $exceededLength++;
                 $code = '';
             }
             if (!empty($code)) {
                 $existing = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\PINCodes\\Model\\PinCode')->findOneBy(array('product' => $product->getId(), 'code' => $code));
                 if (!$existing) {
                     $existing = in_array($code, $codes);
                 }
                 if ($existing) {
                     $duplicates++;
                 } else {
                     $object = new \XLite\Module\CDev\PINCodes\Model\PinCode();
                     $object->setCode($code);
                     $object->setProduct($product);
                     \XLite\Core\Database::getEM()->persist($object);
                     $created++;
                 }
                 $codes[] = $code;
                 if (1000 < count($codes)) {
                     \XLite\Core\Database::getEM()->flush();
                     $codes = array();
                 }
             }
         }
         \XLite\Core\Database::getEM()->flush();
         if ($created) {
             \XLite\Core\TopMessage::addInfo(static::t('X PIN codes created successfully.', array('count' => $created)));
         }
         if ($duplicates) {
             \XLite\Core\TopMessage::addWarning(static::t('X PIN code duplicates ignored.', array('count' => $duplicates)));
         }
         if ($exceededLength) {
             \XLite\Core\TopMessage::addError(static::t('X PIN codes longer than Y characters ignored.', array('count' => $exceededLength, 'max' => $maxLength)));
         }
         if (!$created && !$duplicates && !$exceededLength) {
             \XLite\Core\TopMessage::addError(static::t('No valid code found.'));
         }
     }
 }
예제 #26
0
 /**
  * Get callback request owner transaction or null
  *
  * @return \XLite\Model\Payment\Transaction
  */
 public function getCallbackOwnerTransaction()
 {
     if ($this->detectedTransaction) {
         return $this->detectedTransaction;
     }
     $request = \XLite\Core\Request::getInstance();
     if (!$request->xpcBackReference || !$request->txnId) {
         // This is not X-Payments callback
         return null;
     }
     $logMessage = $parentId = $updateData = '';
     do {
         // Check IP address
         if (!$this->checkIpAddress()) {
             $logMessage = self::getIncorrectIpAddrressError();
             $this->detectedTransaction = $transaction;
             break;
         }
         // Search transaction by back reference from request
         $transaction = $this->searchTransactionByBackReference($request->xpcBackReference);
         if (!$transaction) {
             $logMessage = 'Cannot detect transaction';
             $this->detectedTransaction = null;
             break;
         }
         if ($request->action == 'check_cart') {
             // This is check cart callback request
             $logMessage = 'Check cart callback request received';
             $this->detectedTransaction = $transaction;
             break;
         }
         try {
             // Extract decrypted data into array (exception can be thrown here)
             $updateData = $this->client->processApiResponse($request->updateData);
             // Save decrypted and parsed data
             $this->updateData = $updateData;
         } catch (\XLite\Module\CDev\XPaymentsConnector\Core\XpcResponseException $exception) {
             // Error extracting the data from callback request
             $logMessage = $exception->getMessage();
             $this->detectedTransaction = null;
             break;
         }
         if (!isset($updateData['parentId'])) {
             // Parent ID is not received
             // This is calback of X-Payments payment method
             $logMessage = 'Card present payment method callback request';
             $this->detectedTransaction = $transaction;
             break;
         }
         $parentId = $updateData['parentId'];
         if ($this->isSavedCardsPaymentMethod()) {
             if ($transaction->getDataCell('is_recharge') && 'Y' == $transaction->getDataCell('is_recharge')->getValue()) {
                 // This transaction is recharge for AOM
                 $logMessage = 'Recharge transaction for AOM found';
                 $this->detectedTransaction = $transaction;
             } else {
                 // Search Saved Card transaction in profile.
                 // Order is now being placed by customer.
                 $this->detectedTransaction = $this->searchSavedCardTransaction($transaction, $logMessage);
             }
             break;
         }
         if (!$this->isSavedCardTransaction($transaction)) {
             // Try to find a transaction with the same txnId received from X-Payments.
             // If it exists, it means that it was created by recharge callback from X-Payments.
             // And this request is a secondary action: capture/void/refund
             $secondaryTransactionForExtrnalRecharge = $this->searchTransactionByTxnId($request->txnId);
             if ($secondaryTransactionForExtrnalRecharge) {
                 // Use the already existing transaction
                 $this->detectedTransaction = $secondaryTransactionForExtrnalRecharge;
                 $logMessage = 'Found a transaction for which this is a secondary action';
             } else {
                 // Create new order for subscription/recharge created on X-Payments side
                 // by the original card present transaction passed by backreference
                 $this->detectedTransaction = $this->createChildTransaction($transaction, $updateData);
                 $logMessage = 'Create new transaction in the order callback request';
             }
             break;
             // Just in case
         }
     } while (false);
     // So it can in break
     $logMessage = $logMessage . PHP_EOL . 'Callback Backreference: ' . var_export($request->xpcBackReference, true) . PHP_EOL . 'Callback txnId: ' . var_export($request->txnId, true) . PHP_EOL . 'Transaction ID: ' . ($transaction ? $transaction->getTransactionId() : 'n/a') . PHP_EOL . 'Parent ID: ' . ($parentId ? $parentId : 'n/a') . PHP_EOL . 'Data: ' . ($updateData ? var_export($updateData, true) : 'n/a');
     \XLite\Logger::getInstance()->logCustom(static::LOG_FILE_NAME, $logMessage);
     return $this->detectedTransaction;
 }
예제 #27
0
파일: XLite.php 프로젝트: kewaunited/xcart
 /**
  * Run application
  *
  * @param boolean $adminZone Admin interface flag OPTIONAL
  *
  * @return \XLite
  */
 public function run($adminZone = false)
 {
     // Set current area
     static::$adminZone = (bool) $adminZone;
     // Clear some data
     static::clearDataOnStartup();
     // Initialize logger
     \XLite\Logger::getInstance();
     // Initialize modules
     $this->initModules();
     if (\XLite\Core\Request::getInstance()->isCLI()) {
         // Set skin for console interface
         \XLite\Core\Layout::getInstance()->setConsoleSkin();
     } elseif (true === static::$adminZone) {
         // Set skin for admin interface
         \XLite\Core\Layout::getInstance()->setAdminSkin();
     }
     return $this;
 }
예제 #28
0
 /**
  * Logging the data under Velocity
  * Available if developer_mode is on in the config file
  *
  * @param mixed $data
  *
  * @return void
  */
 protected static function log($data)
 {
     if (LC_DEVELOPER_MODE) {
         \XLite\Logger::logCustom('Velocity', $data);
     }
 }
예제 #29
0
 /**
  * Log callback
  *
  * @param array $list Callback data
  *
  * @return void
  */
 protected function logCallback(array $list)
 {
     \XLite\Logger::getInstance()->log($this->transaction->getPaymentMethod()->getServiceName() . ' payment gateway : callback' . PHP_EOL . 'Data: ' . var_export($list, true), LOG_DEBUG);
 }
예제 #30
0
파일: API.php 프로젝트: kewaunited/xcart
 /**
  * Save API call to the log file
  *
  * @param string $url          API endpoint
  * @param string $callName     Call name
  * @param string $requestData  Request XML
  * @param string $responseData Response XML
  *
  * @return void
  */
 public static function logApiCall($url, $callName, $requestData, $responseData)
 {
     \XLite\Logger::logCustom('CAPOST', var_export(array('Request URL' => $url, 'Request XML (' . $callName . ')' => $requestData, 'Response XML' => \XLite\Core\XML::getInstance()->getFormattedXML($responseData)), true));
 }