Exemplo n.º 1
0
 public function __call($function_name, $arguments)
 {
     self::$errors = array();
     self::$notices = array();
     if (!$this->client) {
         self::$errors[] = $this->l('Wrong WebServices URL');
         return false;
     }
     $result = null;
     $this->last_called_function_name = $function_name;
     if (isset($arguments[0]) && !is_array($arguments[0]) && isset($arguments[1]) && is_array($arguments[1])) {
         $this->params[$arguments[0]] = $arguments[1];
         if (isset($arguments[2]) && is_array($arguments[2])) {
             foreach ($arguments[2] as $key => $argument) {
                 $this->params[$key] = $argument;
             }
         }
         $this->last_called_function_args = $this->params;
         try {
             if (!($result = $this->client->{$function_name}($this->params))) {
                 self::$errors[] = $this->l('Could not connect to webservice server. Please check webservice URL');
             }
         } catch (Exception $e) {
             self::$errors[] = $e->getMessage();
         }
         if (isset($result->return)) {
             $result = $result->return;
         }
         if (isset($result->faultstring)) {
             self::$errors[] = $result->faultstring;
         }
         if (isset($result->result)) {
             $this->getError($result->result);
         }
         if (isset($result->error)) {
             $result_response = $this->objectToArray($result);
             $error_code = '';
             $error_text = '';
             $transaction_id = isset($result_response['transactionId']) ? '; ' . $this->l('Transaction Id:') . ' ' . $result_response['transactionId'] : '';
             if ($result_response['error']['text']) {
                 $error_text = $result_response['error']['text'];
                 if (isset($result_response['error']['code'])) {
                     $error_code = $result_response['error']['code'];
                 }
             }
             $message = $this->getTranslatableMessage($error_code);
             if ($error_text) {
                 self::$errors[] = $error_text . $transaction_id;
             }
             if ($message) {
                 self::$errors[] = $message;
             }
         }
         if ($this->config->debug_mode) {
             $this->debug($result);
         }
         return $this->objectToArray($result);
     }
     return false;
 }