/**
  * Retrieves the user info from the cookie.
  * @return The Customer Information from the cookie
  * @throws \plenigo\PlenigoException whenever an error happens
  */
 public static function getCustomerInfo()
 {
     $cookieText = static::getCookieContents(PlenigoManager::PLENIGO_USER_COOKIE_NAME);
     if (!isset($cookieText) || is_null($cookieText) || !is_string($cookieText) || empty($cookieText)) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "Plenigo cookie not set!!");
         return null;
     }
     // For decryption purposes, the first part of the cookie only is necessary
     if (stristr($cookieText, '|') !== false) {
         $cookieText = stristr($cookieText, '|', true);
     }
     $data = EncryptionUtils::decryptWithAES(PlenigoManager::get()->getSecret(), $cookieText);
     $dataMap = SdkUtils::getMapFromString($data);
     if (!isset($dataMap[ApiResults::TIMESTAMP]) || !isset($dataMap[ApiResults::CUSTOMER_ID])) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "Plenigo cookie has missing components!!");
         return null;
     }
     $timestamp = $dataMap[ApiResults::TIMESTAMP];
     if (!is_numeric($timestamp)) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "Illegal value for the expiration date timestamp!");
         return null;
     }
     $customerId = $dataMap[ApiResults::CUSTOMER_ID];
     if (is_null($customerId) || !is_string($customerId) || empty($customerId)) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "Plenigo cookie CustomerID invalid!!");
         return null;
     }
     $timestampInMillis = intval($timestamp);
     return new Customer($customerId, $timestampInMillis);
 }
 /**
  * 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);
 }
 /**
  * This method parses the metered view data from the user in the cookie.
  *
  * @return MeteredUserData The metered user data
  */
 private static function getMeteredUserData()
 {
     $cookieText = static::getCookieContents(PlenigoManager::PLENIGO_VIEW_COOKIE_NAME);
     if (is_null($cookieText) || trim($cookieText) == false) {
         $clazz = get_class();
         PlenigoManager::notice($clazz, "Plenigo view cookie not set!!");
         return null;
     }
     $data = EncryptionUtils::decryptWithAES(PlenigoManager::get()->getCompanyId(), $cookieText, self::METERED_INIT_VECTOR);
     if (is_null($data) || strstr($data, '|') === false) {
         $clazz = get_class();
         PlenigoManager::error($clazz, "Cookie data could not be decrypted.");
         return null;
     }
     return static::parseMeteredUserData($data);
 }