/** * <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; }
/** * Obtain a list of categories in a paginated way. * * @param int $pageSize The size of the page, it will be trimmed to 10...100 * @param string $lastID the last id of the page that will set the page number to be requested * @return Array an asociative array as a ResultSet with totalElements, page size, last id and the list of products * @throws PlenigoException */ public static function getCategoryList($pageSize = 10, $lastID = null) { $clazz = get_class(); PlenigoManager::notice($clazz, "Getting Category Listing (page size=" . $pageSize . ' lastID=' . $lastID . ')'); $params = self::configureListParams($pageSize, $lastID); $request = static::getRequest(ApiURLs::LIST_CATEGORIES, false, $params); $catRequest = new static($request); try { $response = $catRequest->execute(); } catch (PlenigoException $exc) { $errorCode = ErrorCode::getTranslation(ApiURLs::LIST_CATEGORIES, $exc->getCode()); if (empty($errorCode) || is_null($errorCode)) { $errorCode = $exc->getCode(); } throw self::getException($exc, $errorCode, self::ERR_MSG_CAT_LIST); } try { $catData = get_object_vars($response); } catch (\Exception $exc) { $clazz = get_class(); PlenigoManager::error($clazz, self::ERR_MSG_CLIST_BUILD, $exc); throw new PlenigoException(self::ERR_MSG_CLIST_BUILD, $exc->getCode(), $exc); } return $catData; }
/** * Prepares the request to get the Access Token. * * @param string $type The type of Token Grant Type to use. * @param string $code The Access Code provided by the plenigo API. * @param string $redirectUri An optional redirect URI used to get the Access Code. * @param string $csrfToken An optional CSRF Token to pass to the request. * * @return TokenData The Token Data {@link \plenigo\models\TokenData}. * * @throws \Exception on request error. */ protected static function getToken($type, $code, $redirectUri = null, $csrfToken = null) { $map = array('grant_type' => $type, 'client_id' => PlenigoManager::get()->getCompanyId(), 'client_secret' => PlenigoManager::get()->getSecret()); if ($type == TokenGrantType::REFRESH_TOKEN) { $map['refresh_token'] = $code; } else { $map['code'] = $code; } if ($redirectUri !== null) { $map['redirect_uri'] = $redirectUri; } if ($csrfToken !== null) { $map['state'] = $csrfToken; } $verify = new Verify($map); if ($type == TokenGrantType::REFRESH_TOKEN) { $accessUrl = ApiURLs::REFRESH_ACCESS_TOKEN; } else { $accessUrl = ApiURLs::GET_ACCESS_TOKEN; } $request = static::postRequest($accessUrl, true, $verify->getMap()); $accessTokenRequest = new static($request, $csrfToken); try { $result = $accessTokenRequest->execute(); } catch (Exception $exc) { $errorCode = ErrorCode::getTranslation(ApiURLs::GET_ACCESS_TOKEN, $exc->getCode()); if (empty($errorCode) || is_null($errorCode)) { $errorCode = $exc->getCode(); } $clazz = get_class(); PlenigoManager::error($clazz, self::ERR_MSG_TOKEN, $exc); throw new PlenigoException(self::ERR_MSG_TOKEN, $errorCode, $exc); } return $result; }