public function postAction() { // Create data $data = $this->_getBillingAccountRawBody(); $data = $this->_mapToModel($data, true); // Check mandatory fields // $this->_preValidate($data, new \Application\Model\Validate\BillingAccountValidate(),'billingAccount.'); // Update customer $billingAccount = new BillingAccount($data); $this->_billings[] = $billingAccount; $this->_updateOrgBillingAccounts(); // Reload organization billing accounts $this->_org = $this->_getOrganization(); $this->_billings = $this->_org->getAllBillingAccounts(); // Search created one $billings = array_filter($this->_billings, function ($item) use($billingAccount) { return $item->billingAccountName == $billingAccount->billingAccountName; }); $ba = array_shift($billings); $baId = $ba ? $ba->getBillingAccountId() : null; $url = $this->getFrontController()->getRouter()->assemble(array('module' => $this->getRequest()->getModuleName(), 'controller' => $this->getRequest()->getControllerName(), 'action' => $this->getRequest()->getActionName(), 'id' => $this->_org->getId(), 'billingAccountId' => $baId), 'externalCustomerBillingAccounts'); $this->getResponse()->setHeader('Location', $url); $this->getResponse()->setHttpResponseCode(201); $this->view->billingAccount = $baId; }
public function testDelete() { $this->_org->setParentId($this->_createTree()); $this->_org->save(); $this->_mapper->delete($this->_org->getId()); $orgCustomer = $this->_mapper->findOneById($this->_org->getId()); $this->assertNull($orgCustomer); }
/** * @param Application\Model\SupplServicesModel $service * @return boolean */ public function removeCustomer(SupplServicesModel $service, OrgCustomerModel $org) { if (!strlen((string) $service->getId())) { throw new AppEx\InvalidArgumentException("Supplementary Services does not have an Id"); } if (!$org instanceof OrgCustomerModel) { throw new AppEx\InvalidArgumentException("Organization must be a customer."); } $orgId = $org->getId(); if (!isset($orgId) && !strlen($orgId)) { throw new AppEx\InvalidArgumentException("Organization customer does not have an Id"); } if ($service->getPublished() != \Application\Model\SupplServicesModel::STATUS_PUBLISHED) { throw new AppEx\InvalidArgumentException("Supplementary Services must be published to have customers"); } if ($service->subscriptionCount) { throw new AppEx\InvalidArgumentException("Customer sims are using supplementary services"); } $result = $this->getMapper()->removeCustomer($service->getId(), $org->getId()); \App::audit('Removed customer ' . $org->getId() . ' from supplementary services with Id ' . $service->getId(), $service); return $result; }