Пример #1
0
 /**
  * Bind XML data 
  * 
  * @access  public
  * @param   string  $xml        XML data
  * @param   array   $options    Options as an associative array
  * @return  mixed               true on success, PEAR_Error on failure 
  */
 function bind($xml, $options = array())
 {
     if ($options) {
         $this->setOptions($options);
     }
     // Extract a subset from the XML data if an XPath is provided :
     if ($this->_options['xpath']) {
         include_once 'XML/XPath.php';
         $xpath = new XML_XPath($xml);
         $result =& $xpath->evaluate($this->_options['xpath']);
         if (PEAR::isError($result)) {
             return $result;
         }
         $xml = '';
         while ($result->next()) {
             $xml .= $result->toString(null, false, false);
         }
     }
     // Unserialize that up :
     $unserializer =& new XML_Unserializer();
     $test = $unserializer->unserialize($xml, false);
     if (PEAR::isError($test)) {
         return $test;
     }
     $data = $unserializer->getUnserializedData();
     list($junk, $data) = each($data);
     // Build a simple array  :
     $this->_ar = array();
     foreach ($data as $index => $row) {
         if (!is_array($row) or !is_numeric($index)) {
             return new PEAR_Error('Unable to bind the xml data. ' . 'You may want to set the \'xpath\' option.');
         }
         $this->_ar[] = $row;
     }
     if ($this->_ar and !$this->_options['fields']) {
         $this->setOptions(array('fields' => array_keys($this->_ar[0])));
     }
     return true;
 }
Пример #2
0
 function parse()
 {
     $doc = new XML_XPath();
     $e = $doc->load($this->_rawResponse, 'string');
     if (PEAR::isError($e)) {
         $this->_returnCode = PAYMENT_PROCESS_RESULT_OTHER;
         $this->message = 'Error parsing reply: ' . $e->getMessage() . "\n";
         return;
     }
     $e = $doc->evaluate('//reply/error/attribute::code');
     if (!PEAR::isError($e) && $e->next()) {
         $this->_returnCode = PAYMENT_PROCESS_RESULT_OTHER;
         $this->_errorCode = $e->getData();
         $e = $doc->evaluate('//reply/error/text()');
         $this->message = $e->getData();
         return;
     }
     $orderType = $this->_request->_data['x_action'];
     switch ($orderType) {
         case PAYMENT_PROCESS_ACTION_BIBIT_AUTH:
             $e = $doc->evaluate('//reply/orderStatus/payment/lastEvent/text()');
             if (!PEAR::isError($e) && $e->next()) {
                 $this->_lastEvent = $e->getData();
             }
             $amount = $doc->evaluate('//reply/orderStatus/payment/amount/attribute::value');
             if (!PEAR::isError($amount) && $amount->next()) {
                 if ($this->_lastEvent == 'AUTHORISED') {
                     $this->_returnCode = PAYMENT_PROCESS_RESULT_APPROVED;
                     $this->message = '';
                     return;
                 }
             }
             break;
         case PAYMENT_PROCESS_ACTION_BIBIT_CAPTURE:
             $amount = $doc->evaluate('//reply/ok/captureReceived/amount/attribute::value');
             if (!PEAR::isError($amount) && $amount->next()) {
                 $this->_returnCode = PAYMENT_PROCESS_RESULT_APPROVED;
                 return;
             }
             break;
         case PAYMENT_PROCESS_ACTION_BIBIT_REFUND:
             $amount = $doc->evaluate('//reply/ok/refundReceived/amount/attribute::value');
             if (!PEAR::isError($amount) && $amount->next()) {
                 $this->_returnCode = PAYMENT_PROCESS_RESULT_APPROVED;
                 return;
             }
             break;
     }
 }