Ejemplo n.º 1
0
 /**
  * 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;
             }
         }
     }
 }