src/Web/Communicator.php
protected function sendApiMessage($uri, array $message, Result $result)
    {
        // Convert message to XML. XML requires 1 top level tag, so add one.
        // The tagname is ignored by the Acumulus WebAPI.
        $message = $this->convertArrayToXml(array('myxml' => $message));
        // Keep track of communication for debugging/logging at higher levels.
        $result->setRawRequest($message);

        $rawResponse = $this->sendHttpPost($uri, array('xmlstring' => $message), $result);
        $result->setRawResponse($rawResponse);

        if (empty($rawResponse)) {
            // CURL may get a time-out and return an empty response without
            // further error messages: Add an error to tell the user to check if
            // the invoice was sent or not.
            $result->addError(701, 'Empty response', '');
        } elseif ($this->isHtmlResponse($result->getRawResponse())) {
            // When the API is gone we might receive an html error message page.
            $this->raiseHtmlReceivedError($result->getRawResponse());
        } else {
            // Decode the response as either json or xml.
            $response = array();
            $pluginSettings = $this->config->getPluginSettings();

            if ($pluginSettings['outputFormat'] === 'json') {
                $response = json_decode($result->getRawResponse(), true);
            }
            // Even if we pass <format>json</format> we might receive an XML
            // response in case the XML was rejected before or during parsing.
            // So if the response is null we also try to decode the response as
            // XML.
            if ($pluginSettings['outputFormat'] === 'xml' || $response === null) {
                try {
                    $response = $this->convertXmlToArray($result->getRawResponse());
                } catch (RuntimeException $e) {
                    // Not an XML response. Treat it as an json error if we were
                    // expecting a json response.
                    if ($pluginSettings['outputFormat'] === 'json') {
                        $this->raiseJsonError();
                    }
                    // Otherwise treat it as the XML exception that was raised.
                    throw $e;
                }
            }
            $result->setResponse($response);
        }

        return $result;
    }
protected function sendApiMessage($uri, array $message, Result $result)
    {
        // Convert message to XML. XML requires 1 top level tag, so add one.
        // The tagname is ignored by the Acumulus WebAPI.
        $message = $this->convertArrayToXml(array('myxml' => $message));
        // Keep track of communication for debugging/logging at higher levels.
        $result->setRawRequest($message);

        $rawResponse = $this->sendHttpPost($uri, array('xmlstring' => $message), $result);
        $result->setRawResponse($rawResponse);

        if (empty($rawResponse)) {
            // CURL may get a time-out and return an empty response without
            // further error messages: Add an error to tell the user to check if
            // the invoice was sent or not.
            $result->addError(701, 'Empty response', '');
        } elseif ($this->isHtmlResponse($result->getRawResponse())) {
            // When the API is gone we might receive an html error message page.
            $this->raiseHtmlReceivedError($result->getRawResponse());
        } else {
            // Decode the response as either json or xml.
            $response = array();
            $pluginSettings = $this->config->getPluginSettings();

            if ($pluginSettings['outputFormat'] === 'json') {
                $response = json_decode($result->getRawResponse(), true);
            }
            // Even if we pass <format>json</format> we might receive an XML
            // response in case the XML was rejected before or during parsing.
            // So if the response is null we also try to decode the response as
            // XML.
            if ($pluginSettings['outputFormat'] === 'xml' || $response === null) {
                try {
                    $response = $this->convertXmlToArray($result->getRawResponse());
                } catch (RuntimeException $e) {
                    // Not an XML response. Treat it as an json error if we were
                    // expecting a json response.
                    if ($pluginSettings['outputFormat'] === 'json') {
                        $this->raiseJsonError();
                    }
                    // Otherwise treat it as the XML exception that was raised.
                    throw $e;
                }
            }
            $result->setResponse($response);
        }

        return $result;
    }
protected function sendApiMessage ( $ uri , array $ message , Result $ result ) { // Convert message to XML. XML requires 1 top level tag, so add one. // The tagname is ignored by the Acumulus WebAPI. $ message = $ this -> convertArrayToXml ( array ( 'myxml' => $ message ) ) ; // Keep track of communication for debugging/logging at higher levels. $ result -> setRawRequest ( $ message ) ; $ rawResponse = $ this -> sendHttpPost ( $ uri , array ( 'xmlstring' => $ message ) , $ result ) ; $ result -> setRawResponse ( $ rawResponse ) ; if ( empty ( $ rawResponse ) ) { // CURL may get a time-out and return an empty response without // further error messages: Add an error to tell the user to check if // the invoice was sent or not. $ result -> addError ( 701 , 'Empty response' , '' ) ; } elseif ( $ this -> isHtmlResponse ( $ result -> getRawResponse ( ) ) ) { // When the API is gone we might receive an html error message page. $ this -> raiseHtmlReceivedError ( $ result -> getRawResponse ( ) ) ; } else { // Decode the response as either json or xml. $ response = array ( ) ; $ pluginSettings = $ this -> config -> getPluginSettings ( ) ; if ( $ pluginSettings [ 'outputFormat' ] === 'json' ) { $ response = json_decode ( $ result -> getRawResponse ( ) , true ) ; } // Even if we pass <format>json</format> we might receive an XML // response in case the XML was rejected before or during parsing. // So if the response is null we also try to decode the response as // XML. if ( $ pluginSettings [ 'outputFormat' ] === 'xml' || $ response === null ) { try { $ response = $ this -> convertXmlToArray ( $ result -> getRawResponse ( ) ) ; } catch ( RuntimeException $ e ) { // Not an XML response. Treat it as an json error if we were // expecting a json response. if ( $ pluginSettings [ 'outputFormat' ] === 'json' ) { $ this -> raiseJsonError ( ) ; } // Otherwise treat it as the XML exception that was raised. throw $ e ; } } $ result -> setResponse ( $ response ) ; } return $ result ; }
Sends a message to the Acumulus API and returns the answer.

Any errors during:
- conversion of the message to xml,
- communication with the Acumulus web service
- converting the answer to an array
are returned as an Exception.

Any errors (or warnings) returned in the response structure of the web
service are returned via the result value and should be handled at a
higher level.

@param string $uri
The URI of the Acumulus WebAPI call to send the message to.
@param array $message
The message to send to the Acumulus WebAPI.
@param \Siel\Acumulus\Web\Result $result
The result structure to add the results to.

@return \Siel\Acumulus\Web\Result
The result of the web service call.

@see https://www.siel.nl/acumulus/API/Basic_Response/ For the
structure of a response.
Sends a message to the Acumulus API and returns the answer .