/** * Class constructor * * @param \Apigee\Exceptions\ResponseException $e * @return boolean * @throws \Apigee\Exceptions\ParameterException if the exception has no Mint * registered code */ public function __construct($e) { parent::__construct($e); if (!self::isInsufficientFundsException($e)) { throw new ParameterException('Improper response exception message passed into InsufficientFundsException class constructor.', $e); } $errorInfo = json_decode($e->getResponse()); if (empty($errorInfo->contexts)) { // If contexts are empty, then we do not have the cost breakdown data. $this->hasCostDetails = false; // Get the total cost $amtStartsAt = strpos($this->mintMessage, '[') + 1; $substring = substr($this->mintMessage, $amtStartsAt, strlen($this->mintMessage) - $amtStartsAt - 1); $required = str_replace(',', '', $substring); $this->totalRatePlan = $required; } else { // We have the cost details, collect them into proper attributes. $this->hasCostDetails = true; foreach ($errorInfo->contexts as $context) { switch ($context->name) { case self::CONTEXT_COST_TOTAL: $this->totalRatePlan = $context->value; break; case self::CONTEXT_COST_TAX: $this->tax = $context->value; break; case self::CONTEXT_COST_RATE_PLAN: $this->ratePlan = $context->value; break; } } } }
/** * Factory method to create the proper exception class depending on the error. * * @param ResponseException $re The response exception from the Edge API * * @return MintApiException MintApiException or a subclass of MintApiException */ public static function factory(ResponseException $re) { if (InsufficientFundsException::isInsufficientFundsException($re)) { return new InsufficientFundsException($re); } elseif (MintApiException::isMintExceptionCode($re)) { return new MintApiException($re); } else { throw new ParameterException('Not a registered mint exception.', $re); } }
public function save($save_method = 'update') { $url = '/mint/organizations/' . rawurlencode($this->config->orgName) . '/developers/' . rawurlencode($this->developer_or_company_id) . '/developer-rateplans'; $obj = array('developer' => array('id' => $this->developer_or_company_id), 'startDate' => $this->startDate, 'endDate' => $this->endDate, 'ratePlan' => array('id' => $this->ratePlan->getId())); try { $this->setBaseUrl($url); if ($save_method == 'create') { $this->post(null, $obj); } elseif ($save_method == 'update') { $obj['id'] = $this->id; $this->put($this->getId(), $obj); } else { throw new ParameterException('Unsupported save method argument: ' . $save_method); } $this->restoreBaseUrl(); } catch (ResponseException $re) { $e = MintApiException::factory($re); throw $e; } }
public function getPrepaidBalanceReport($month, $year, $developer_id, $currency_id) { try { $data = array('showTxDetail' => true, 'devCriteria' => array(array('id' => $developer_id, 'orgId' => $this->config->orgName)), 'currCriteria' => array(array('id' => strtolower($currency_id), 'orgId' => $this->config->orgName)), 'billingMonth' => strtoupper($month), 'billingYear' => $year); $url = '/mint/organizations/' . rawurlencode($this->config->orgName) . '/prepaid-balance-reports'; $content_type = 'application/json; charset=utf-8'; $accept_type = 'application/octet-stream; charset=utf-8'; $this->setBaseUrl($url); $this->post(null, $data, $content_type, $accept_type); $this->restoreBaseUrl(); $response = $this->responseText; } catch (ResponseException $re) { if (MintApiException::isMintExceptionCode($re)) { throw new MintApiException($re); } throw $re; } return $response; }
/** * Get eligible Mint products for this developer. * * This function calls the /eligible-products API to find * out what products this developer is able to purchase. If the product * is associated to one or more packages, then the product is not displayed * unless the developer has purchased a plan that has that product * associated to it. * * @return array of * @throws \Apigee\Exceptions\ParameterException * @throws \Apigee\Mint\Exceptions\MintApiException * @throws \Exception */ public function getEligibleProducts() { if (!empty($this->email)) { $developer_id = $this->email; } else { throw new ParameterException("Developer id not specified"); } $products = array(); try { $url = rawurlencode($developer_id) . '/eligible-products'; $this->get($url); $data = $this->responseObj; foreach ($data['product'] as $product) { unset($product['organization']); $products[$product['name']] = $product; } } catch (\Exception $e) { if (MintApiException::isMintExceptionCode($e)) { throw new MintApiException($e); } else { throw $e; } } return $products; }
/** * @param $bill_doc_number * @param $developer_id * @return array * * @throws MintApiException */ public function searchBillingDoc($bill_doc_number, $developer_id) { $docs = array(); try { $url = '/mint/organizations/' . rawurlencode($this->config->orgName) . '/search-billing-documents'; $devCriteria = new \stdClass(); $devCriteria->id = $developer_id; $devCriteria->orgId = $this->config->orgName; $mintCriteria = array('devCriteria' => array($devCriteria), 'documentNumber' => $bill_doc_number); $this->setBaseUrl($url); $this->post(null, $mintCriteria); $this->restoreBaseUrl(); $response = $this->responseObj; foreach ($response[$this->wrapper_tag] as $doc) { $bill_doc = new BillingDocument($this->config); $bill_doc->loadFromRawData($doc); $docs[] = $bill_doc; } //return $this->responseObj; } catch (ResponseException $re) { if (MintApiException::isMintExceptionCode($re)) { throw new MintApiException($re); } } return $docs; }