/**
  * set all settings
  * @return mixed
  */
 private function getPlenigoSettings()
 {
     $sqlResult = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('company_i_d, company_private_key', 'tx_plenigofornews_domain_model_plenigosetting');
     if (class_exists('\\plenigo\\PlenigoManager')) {
         $this->plenigoInstance = \plenigo\PlenigoManager::configure($sqlResult['company_private_key'], $sqlResult['company_i_d']);
     }
     return $sqlResult;
 }
Ejemplo n.º 2
0
 /**
  * Returns a response to a POST RestClient request to a specific
  * end-point on the plenigo REST API.
  *
  * @param string $endPoint The REST end-point to access.
  * @param bool $oauth TRUE if the needed request is going to the OAuth API.
  * @param array  $params   Optional params to pass to the request.
  *
  * @return the request result.
  */
 protected static function postRequest($endPoint, $oauth = false, array $params = array())
 {
     if ($oauth) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "OAUTH POST REQUEST");
         $url = PlenigoManager::get()->getUrlOAuth() . $endPoint;
     } else {
         $url = PlenigoManager::get()->getUrl() . $endPoint;
     }
     return RestClient::post($url, $params);
 }
 /**
  * This method builds the encoded data from the Checkout Object.
  *
  * @param string $dataToEncode the string data to encode.
  *
  * @return string The encoded data
  */
 private function buildEncodedData($dataToEncode)
 {
     $secret = PlenigoManager::get()->getSecret();
     return EncryptionUtils::encryptWithAES($secret, $dataToEncode);
 }
Ejemplo n.º 4
0
 /**
  * Perform field validations when creating the Checkout object and throws Exceptions if needed
  * 
  * @throws PlenigoException if strict validations fail
  */
 private function performValidation()
 {
     $clazz = get_class();
     if (!is_null($this->title) && strlen($this->title) > self::TITLE_MAX_LENGTH) {
         \plenigo\PlenigoManager::notice($clazz, self::ERR_MSG_TITLE_TOO_LONG);
     }
     if (!is_null($this->productId) && strlen($this->productId) > self::PROD_ID_MAX_LENGTH) {
         throw new PlenigoException(self::ERR_MSG_PROD_ID_TOO_LONG);
     }
 }
 /**
  * Create an array with the Company ID, the Secret, a given page size and an optional Last ID for product
  * or category listings.
  *
  * @param int $pageSize The number of items on a single page (min:10, max:100)
  * @param string $lastID Optional. A string containing the last ID of the current page
  * @return array A key=>value array to convert to queryString for the URL
  */
 private static function configureListParams($pageSize = 10, $lastID = null)
 {
     $size = max(min($pageSize, 100), 10);
     return array(ApiParams::COMPANY_ID => PlenigoManager::get()->getCompanyId(), ApiParams::SECRET => PlenigoManager::get()->getSecret(), 'size' => $size, 'lastId' => !is_null($lastID) ? $lastID : '');
 }
Ejemplo n.º 6
0
 /**
  * <p>Retrieves the product and suscriptions list for the current (logged in) 
  * user, then returns it as an associative array with this sintax</p>
  * <pre>
  * array (
  *   'singleProducts' => array (
  *     0 => array(
  *        'productId' => 'xxxx',
  *        'title' => 'prod title',
  *        'buyDate' => 'YYYY-MM-DD HH:mm:ss +0100',
  *     ),
  *   ),
  *   'subscriptions' => array (
  *     0 => array(
  *        'productId' => 'yyyyyy',
  *        'title' => 'Subscription title',
  *        'buyDate' => 'YYYY-MM-DD HH:mm:ss +0100',
  *        'endDate' => 'YYYY-MM-DD HH:mm:ss +0100',
  *     ),
  *   ),
  * )</pre>
  * 
  * @return array The associative array containing the bought products/subscriptions or an empty array
  * @throws PlenigoException If the compay ID and/or the Secret key is rejected
  */
 public static function getProductsBought()
 {
     $res = array();
     $customer = self::getCustomerInfo();
     $clazz = get_class();
     if (is_null($customer)) {
         PlenigoManager::notice($clazz, self::ERR_MSG_CUSTOMER);
         return $res;
     }
     PlenigoManager::notice($clazz, "customer is good=" . print_r($customer, true));
     $testModeText = PlenigoManager::get()->isTestMode() ? 'true' : 'false';
     $params = array(ApiParams::COMPANY_ID => PlenigoManager::get()->getCompanyId(), ApiParams::SECRET => PlenigoManager::get()->getSecret(), ApiParams::TEST_MODE => $testModeText);
     $url = str_ireplace(ApiParams::URL_USER_ID_TAG, $customer->getCustomerId(), ApiURLs::USER_PRODUCTS);
     $request = static::getRequest($url, false, $params);
     $userDataRequest = new static($request);
     try {
         $response = $userDataRequest->execute();
     } catch (PlenigoException $exc) {
         $errorCode = ErrorCode::getTranslation(ApiURLs::USER_PRODUCTS, $exc->getCode());
         if (empty($errorCode) || is_null($errorCode)) {
             $errorCode = $exc->getCode();
         }
         $clazz = get_class();
         PlenigoManager::error($clazz, self::ERR_MSG_USER_LIST, $exc);
         throw new PlenigoException(self::ERR_MSG_USER_LIST, $exc->getCode(), $exc);
     }
     if (!is_null($response)) {
         PlenigoManager::notice($clazz, "Product list is accessible=" . print_r($response, true));
         $res = get_object_vars($response);
     } else {
         PlenigoManager::notice($clazz, "Product list NOT accesible!");
     }
     return $res;
 }
Ejemplo n.º 7
0
 /**
  * This method follows the logic of validating the creation time of the cookie, 
  * this is a countermeasure for cookie spoofing to get metered views always active
  * 
  * @param plenigo\internal\models\MeteredUserData $meteredInfo the Metered Info subject to checking
  * @return boolean true if is a valid cookie, false otherwise
  */
 private static function checkCookieValidity(MeteredUserData $meteredInfo)
 {
     $period = $meteredInfo->getMeteredPeriod();
     $curTime = time();
     $timeLapse = $curTime - $meteredInfo->getCookieCreationTime();
     $olderThanADay = false;
     $olderThanAWeek = false;
     $olderThanAMonth = false;
     $olderThanAYear = false;
     if ($timeLapse > 0 && intval($timeLapse) > intval(static::TS_DAY_IN_MILLIS)) {
         $olderThanADay = true;
     }
     if ($timeLapse > 0 && intval($timeLapse) > intval(static::TS_DAY_IN_MILLIS * 7)) {
         $olderThanAWeek = true;
     }
     if ($timeLapse > 0 && intval($timeLapse) > intval(static::TS_DAY_IN_MILLIS * 30)) {
         $olderThanAMonth = true;
     }
     if ($timeLapse > 0 && intval($timeLapse) > intval(static::TS_DAY_IN_MILLIS * 365)) {
         $olderThanAYear = true;
     }
     if ($period === 'DAY' && $olderThanADay === true) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "View Cookie older than a day.");
         return false;
     }
     if ($period === 'WEEK' && $olderThanAWeek === true) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "View Cookie older than a week.");
         return false;
     }
     if ($period === 'MONTH' && $olderThanAMonth === true) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "View Cookie older than a month.");
         return false;
     }
     if ($period === 'YEAR' && $olderThanAYear === true) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "View Cookie older than a year.");
         return false;
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Return the company-ID
  * @return string Company-ID
  */
 public static function getCompanyID()
 {
     return \plenigo\PlenigoManager::get()->getCompanyId();
 }
Ejemplo n.º 9
0
 /**
  * This method generates the cross-site request forgery (CSRF) token.
  * 
  * @return string the CSRF Token or NULL if there is a problem generating the CSRF Token
  */
 public static function createCsrfToken()
 {
     $clazz = get_class();
     PlenigoManager::notice($clazz, "Creating a random CSRF Token!");
     $randomtoken = null;
     try {
         if (function_exists("openssl_random_pseudo_bytes")) {
             $randomtoken = md5(base64_encode(openssl_random_pseudo_bytes(32)));
         } else {
             $randomtoken = md5(uniqid(rand(), true));
         }
     } catch (Exception $exc) {
         $clazz = get_class();
         PlenigoManager::warn($clazz, self::ERR_MSG_TOKEN_CREATE, $exc);
     }
     return $randomtoken;
 }
Ejemplo n.º 10
0
 /**
  * Executes a cURL POST request at the given URL
  * with optional get parameters.
  *
  * @param string $url    The url to access.
  * @param array  $params An optional map of params to pass
  *                       on to the request as post values.
  *
  * @return the request response
  *
  * @throws \Exception on request error.
  */
 public static function post($url, array $params = array())
 {
     $curlRequest = static::createCurlRequest($url);
     $curlRequest->setOption(CURLOPT_POST, true);
     if (count($params) > 0) {
         $queryString = http_build_query($params);
         $curlRequest->setOption(CURLOPT_POSTFIELDS, $queryString);
     }
     $clazz = get_class();
     PlenigoManager::notice($clazz, "POST URL CALL=" . $url);
     return new static($curlRequest);
 }
 private function connect()
 {
     try {
         \plenigo\PlenigoManager::configure($this->plenigoSettings->getCompanyPrivateKey(), $this->plenigoSettings->getCompanyID(), $this->plenigoSettings->isTestMode());
     } catch (\Exception $e) {
         $GLOBALS['TSFE']->pageUnavailableAndExit($e->getMessage(), 'HTTP/1.1 500 Internal Server Error');
         throw $e;
     }
 }