type = $type; return $this; } /** * @return mixed */ public function getType() { return $this->type; } /** * @param mixed $taxCloudCallback * @throws \Exception * @return $this */ public function setTaxCloudCallback($taxCloudCallback) { if (!is_callable($taxCloudCallback)) { throw new Exception('Invalid TaxCloud callback'); } $this->taxCloudCallback = $taxCloudCallback; return $this; } /** * @return mixed */ public function getTaxCloudCallback() { return $this->taxCloudCallback; } public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('FormElements') ->addDecorator('HtmlTag', array('tag' => 'dl')) ->addDecorator('Errors') ->addDecorator('Fieldset') ->addDecorator('DtDdWrapper'); } } public function isValid($data) { $isValid = parent::isValid($data); return $isValid && $this->isValidTaxCloudDestinationAddress(); } public function isValidAjax($data = null) { $isValid = parent::isValidAjax($data); return $isValid && $this->isValidTaxCloudDestinationAddress(); } protected function isDestinationAddress() { return $this->getType() == Model::getDestinationAddressType(Qs_Request::getPost()); } protected function isValidTaxCloudDestinationAddress() { if (!$this->isDestinationAddress()) { return true; } $address = $this->getValues(); if ($this->getType() == key($address)) { $address = current($address); } if (!is_callable($this->getTaxCloudCallback())) { throw new Exception('Invalid TaxCloud callback'); } if (true !== ($errors = call_user_func($this->getTaxCloudCallback(), $address))) { $this->setErrors($errors); return false; } return true; } }