/**
  * Preparing data and parsing result received
  * 
  * @param array $data
  * @return void
  */
 public function handle($data)
 {
     $this->_request = ArrayToXml::render($data);
     $this->_rawRequest = $this->_request;
     $xmlResponse = self::sendMessage($this->_request);
     if (!in_array($this->getConnection()->getHttpStatusCode(), array('200', '301', '302'))) {
         $this->_response = array('errors' => array('error' => array('code' => array('@data' => $this->getConnection()->getHttpStatusCode()), 'message' => array('@data' => $this->getConnection()->error))));
     } else {
         try {
             $this->_response = XmlToArray::render($xmlResponse);
         } catch (Exception $e) {
             $this->_response = array('errors' => array('error' => array('code' => array('@data' => '0999'), 'message' => array('@data' => $e->getMessage()))));
         }
     }
     $this->_rawResponse = $xmlResponse;
 }
Exemplo n.º 2
0
 /**
  * send this message and get response
  * save all warnings - errors are only saved if no payment-url is send from pnag
  *
  * @return SofortLib_TransactionData $this
  */
 public function sendRequest()
 {
     $requestData[$this->_xmlRootTag] = $this->_parameters;
     $requestData = $this->_prepareRootTag($requestData);
     $xmlRequest = ArrayToXml::render($requestData);
     $this->_log($xmlRequest, ' XmlRequest -> ');
     $xmlResponse = $this->_sendMessage($xmlRequest);
     try {
         $this->_response = XmlToArray::render($xmlResponse);
     } catch (Exception $e) {
         $this->_response = array('errors' => array('error' => array('code' => array('@data' => '0999'), 'message' => array('@data' => $e->getMessage()))));
     }
     $this->_log($xmlResponse, ' XmlResponse <- ');
     $this->_handleErrors();
     $this->_parseXml();
     return $this;
 }
 public function testRender()
 {
     $ArrayToXml = new ArrayToXml(array(array(1)));
     $this->assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<test>1</test>", $ArrayToXml->render(array('test' => 1)));
 }