public function timeandconsumptionAction() { $sim = $this->_getSim(); if ($this->getRequest()->isGet()) { // Sync request $this->_helper->allowed('read_time_and_consumption', $sim); $this->_simSrv->getTimeAndConsumptionVoucher($sim); $this->view->timeAndConsumptionVoucher = $sim->getTimeAndConsumption() ? $sim->getTimeAndConsumption()->exportData() : null; if (empty($this->view->timeAndConsumptionVoucher)) { unset($this->view->timeAndConsumptionVoucher); } } else { if ($this->getRequest()->isPut()) { // Async request $this->_helper->allowed('update_time_and_consumption', $sim); $data = $this->_helper->requestData(true, false); if (!empty($data)) { $sim->setTimeAndConsumption($data); $this->_simSrv->updateTimeAndConsumptionVoucher($sim, $sim->getTimeAndConsumption()); } } else { throw new UnexpectedException("Resquest must be GET or PUT"); } } }
public function timeandconsumptionAction() { $sim = $this->_getSim(); if ($this->getRequest()->isGet()) { // Sync request $this->_helper->allowed('read_time_and_consumption', $sim); $this->_simSrv->getTimeAndConsumptionVoucher($sim); $this->view->timeAndConsumptionVoucher = $sim->getTimeAndConsumption() ? $sim->getTimeAndConsumption()->exportData() : null; if (empty($this->view->timeAndConsumptionVoucher)) { unset($this->view->timeAndConsumptionVoucher); } } else { if ($this->getRequest()->isPut()) { // Async request try { $this->_helper->allowed('update_time_and_consumption', $sim); } catch (\Application\Exceptions\PermissionException $ex) { throw new \Application\Exceptions\NotAllowedException('Update time and consumption Operation is not allowed: ' . $ex->getMessage()); } $data = $this->_helper->requestData(true, false); if (!in_array($sim->lifeCycleStatus, array(LifeCycleModel::STATUS_ACTIVE, LifeCycleModel::STATUS_ACTIVATION_READY))) { throw new InvalidArgumentException("Invalid parameter value: {$this->_getType()}. Supported values are sim with active or Activation Ready lifecycle state"); } // chached sim status check because https://jira.tid.es/browse/GLOBALPORTAL-184652 if (!empty($data)) { $sim->setTimeAndConsumption($data); $this->_simSrv->updateTimeAndConsumptionVoucher($sim, $sim->getTimeAndConsumption()); } } else { throw new UnexpectedException("Resquest must be GET or PUT"); } } }
/** * @expectedException \Application\Exceptions\InvalidArgumentException */ public function testGetInvalidSimTimeAndConsumptionVoucher() { $sim = $this->_service->load("0"); $this->_service->getTimeAndConsumptionVoucher($sim); }