Esempio n. 1
0
 /**
  * Implements Base\BaseObject::loadFromRawData().
  *
  * @param array $data
  * @param bool $reset
  */
 public function loadFromRawData($data, $reset = false)
 {
     if ($reset) {
         $this->initValues();
     }
     $excluded_properties = array('ratePlan', 'developer');
     foreach (array_keys($data) as $property) {
         if (in_array($property, $excluded_properties)) {
             continue;
         }
         // form the setter method name to invoke setXxxx
         $setter_method = 'set' . ucfirst($property);
         if (method_exists($this, $setter_method)) {
             $this->{$setter_method}($data[$property]);
         } else {
             self::$logger->notice('No setter method was found for property "' . $property . '"');
         }
     }
     if (isset($data['ratePlan']) && is_array($data['ratePlan']) && count($data['ratePlan']) > 0) {
         if (isset($data['ratePlan']['monetizationPackage']['id'])) {
             $m_package_id = $data['ratePlan']['monetizationPackage']['id'];
             $this->ratePlan = new RatePlan($m_package_id, $this->config);
             $this->ratePlan->loadFromRawData($data['ratePlan']);
         }
     }
 }
Esempio n. 2
0
 public function loadFromRawData($data, $reset = false)
 {
     if ($reset) {
         $this->initValues();
     }
     $excluded_properties = array('org', 'mPackageId', 'organization', 'monetizationPackage', 'currency', 'parentRatePlan', 'developer', 'developerCategory', 'developers', 'applicationCategory', 'exchangeOrganization', 'ratePlanDetails');
     foreach (array_keys($data) as $property) {
         if (in_array($property, $excluded_properties)) {
             continue;
         }
         // form the setter method name to invoke setXxxx
         $setter_method = 'set' . ucfirst($property);
         if (method_exists($this, $setter_method)) {
             $this->{$setter_method}($data[$property]);
         } else {
             self::$logger->notice('No setter method was found for property "' . $property . '"');
         }
     }
     // Set objects
     if (isset($data['organization'])) {
         $organization = new Organization($this->config);
         $organization->loadFromRawData($data['organization']);
         $this->organization = $organization;
     }
     if (isset($data['monetizationPackage'])) {
         $monetizationPackage = new MonetizationPackage($this->config);
         $monetizationPackage->loadFromRawData($data['monetizationPackage']);
         $this->monetizationPackage = $monetizationPackage;
     }
     if (isset($data['currency'])) {
         $this->currency = new DataStructures\SupportedCurrency($data['currency']);
     }
     if (isset($data['parentRatePlan'])) {
         $rate_plan = new RatePlan($this->mPackageId, $this->config);
         $rate_plan->loadFromRawData($data['parentRatePlan']);
         $this->setParentRatePlan($rate_plan);
     }
     if (isset($data['developer'])) {
         $dev = new Developer($this->config);
         $dev->loadFromRawData($data['developer']);
         $this->developerId = $dev->getEmail();
     }
     //@TODO Implement load of developerCategory
     //@TODO Implement load of developers
     //@TODO Implement load of applicationCategory
     if (isset($data['exchangeOrganization'])) {
         $organization = new Organization($this->config);
         $organization->loadFromRawData($data['exchangeOrganization']);
         $this->exchangeOrganization = $organization;
     }
     if (isset($data['ratePlanDetails'])) {
         foreach ($data['ratePlanDetails'] as $ratePlanDetail) {
             $this->ratePlanDetails[] = new DataStructures\RatePlanDetail($ratePlanDetail, $this->config);
         }
     }
 }
Esempio n. 3
0
 /**
  * Retrieve the ratePlan associated with a given product
  * @param string $product_id
  *   Product Id
  * @param string $developer_id
  *   Developer email
  * @throws ParameterException
  *   Throw if no developer id is provided or email property is null
  * @throws MintApiException
  *   Throw if Exception is related to Mint API
  * @throws \Exception
  *   Throw if any other exception
  * @return \Apigee\Mint\RatePlan
  *   The RatePlan associated to this Product
  */
 public function getRatePlanByProduct($product_id, $developer_id = null)
 {
     if (empty($developer_id)) {
         if (!empty($this->email)) {
             $developer_id = $this->email;
         } else {
             throw new ParameterException("Developer id not specified");
         }
     }
     try {
         $url = rawurlencode($developer_id) . '/products/' . rawurlencode($product_id) . '/rate-plan-by-developer-product/';
         $this->get($url);
         $ratePlan = new RatePlan(null, $this->config);
         $ratePlan->loadFromRawData($this->responseObj);
         return $ratePlan;
     } catch (\Exception $e) {
         if (MintApiException::isMintExceptionCode($e)) {
             throw new MintApiException($e);
         } else {
             throw $e;
         }
     }
     return $products;
 }