示例#1
0
 /**
  * @param $service
  * @param $data
  *
  * @return mixed
  * @throws Exception
  */
 public function call($service, $data)
 {
     $envelope = array($service => array_merge(array('Security' => array('Password' => $this->taxify->getApiKey())), $data));
     $json = json_encode($envelope);
     $this->taxify->printDebugInfo('Envelope', $envelope);
     $this->taxify->printDebugInfo('JSON', $json);
     $ch = curl_init();
     curl_setopt_array($ch, array(CURLOPT_URL => $this->taxify->getUrl() . $service, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => FALSE, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $json, CURLOPT_HTTPHEADER => array('Content-Type: application/json', 'Content-Length: ' . strlen($json))));
     $result = curl_exec($ch);
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     $this->taxify->printDebugInfo('Result', $result);
     if ($http_code != 200) {
         throw new Exception(self::ERROR_COMMUNICATION . ' (' . $this->taxify->getUrl() . $service . ')');
     }
     $array = json_decode($result, TRUE);
     if (!array_key_exists('d', $array)) {
         throw new Exception(self::ERROR_CALL);
     }
     $array = $array['d'];
     if (!isset($array['ResponseStatus']) || $array['ResponseStatus'] != 1) {
         if (isset($array['Errors']) && count($array['Errors']) > 0) {
             throw new Exception($array['Errors'][0]['Message'], $array['Errors'][0]['Code']);
         }
         throw new Exception('Unknown Error');
     }
     return $array;
 }
示例#2
0
 /**
  * @return array
  */
 public function toArray()
 {
     $data = array('Street1' => Taxify::toString($this->street1), 'Street2' => Taxify::toString($this->street2), 'City' => Taxify::toString($this->city), 'Region' => Taxify::toString($this->region), 'PostalCode' => Taxify::toString($this->postal_code), 'Options' => array());
     if ($this->tax_request_options) {
         foreach ($this->tax_request_options as $tax_request_option) {
             $data['Request']['Options'][] = $tax_request_option->toArray();
         }
     }
     return $data;
 }
示例#3
0
 /**
  * @return array
  */
 public function toArray()
 {
     $data = array('LineNumber' => Taxify::toString($this->line_number), 'ItemKey' => Taxify::toString($this->item_key), 'ActualExtendedPrice' => empty($this->actual_extended_price) ? 0 : $this->actual_extended_price, 'TaxIncludedInPrice' => $this->tax_included_in_price, 'Quantity' => empty($this->quantity) ? 0 : $this->quantity, 'ItemDescription' => Taxify::toString($this->item_description), 'ItemTaxabilityCode' => Taxify::toString($this->item_taxability_code), 'ItemCategories' => Taxify::toString($this->item_categories), 'ItemTags' => Taxify::toString($this->item_tags), 'Options' => array());
     if ($this->tax_request_options) {
         foreach ($this->tax_request_options as $tax_request_option) {
             $data['Request']['Options'][] = $tax_request_option->toArray();
         }
     }
     return $data;
 }
示例#4
0
 /**
  * @return array
  */
 public function toArray()
 {
     return array('Discount' => array('Order' => is_numeric($this->order) ? $this->order : 0, 'Code' => Taxify::toString($this->code), 'Amount' => is_numeric($this->amount) ? $this->amount : 0, 'DiscountType' => Taxify::toString($this->discount_type)));
 }
示例#5
0
 /**
  * @return array
  */
 public function toArray()
 {
     return array('TaxRequestOption' => array('Key' => Taxify::toString($this->key), 'Value' => Taxify::toString($this->value)));
 }
示例#6
0
 public function commitTax()
 {
     if (empty($this->document_key)) {
         throw new Exception(self::ERROR_NO_DOCUMENT_KEY);
     }
     $data = array('DocumentKey' => Taxify::toString($this->document_key), 'CommitedDocumentKey' => Taxify::toString($this->committed_document_key));
     $communicator = new Communicator($this->taxify);
     $return = $communicator->call(self::CALL_COMMIT_TAX, $data);
     $tax_response = new TaxResponse();
     $tax_response->setResponseStatus(1);
     $tax_response->setExtendedProperties($return['ExtendedProperties']);
     return $tax_response;
 }
示例#7
0
 /**
  * @return array
  */
 public function toArray()
 {
     return array('string' => Taxify::toString($this->string));
 }