/** * load eWAY response data as XML string * * @param string $response eWAY response as a string (hopefully of XML data) */ public function loadResponseXML($response) { GFEwayPlugin::log_debug(sprintf('%s: eWAY says "%s"', __METHOD__, $response)); // make sure we actually got something from eWAY if (strlen($response) === 0) { throw new GFEwayException('eWAY payment request returned nothing; please check your card details'); } // prevent XML injection attacks, and handle errors without warnings $oldDisableEntityLoader = libxml_disable_entity_loader(true); $oldUseInternalErrors = libxml_use_internal_errors(true); try { $xml = simplexml_load_string($response); if ($xml === false) { $errmsg = ''; foreach (libxml_get_errors() as $error) { $errmsg .= $error->message; } throw new Exception($errmsg); } $this->status = strcasecmp((string) $xml->ewayTrxnStatus, 'true') === 0; $this->transactionNumber = (string) $xml->ewayTrxnNumber; $this->transactionReference = (string) $xml->ewayTrxnReference; $this->option1 = (string) $xml->ewayTrxnOption1; $this->option2 = (string) $xml->ewayTrxnOption2; $this->option3 = (string) $xml->ewayTrxnOption3; $this->authCode = (string) $xml->ewayAuthCode; $this->error = (string) $xml->ewayTrxnError; $this->beagleScore = (string) $xml->ewayBeagleScore; // if we got an amount, convert it back into dollars.cents from just cents if (!empty($xml->ewayReturnAmount)) { $this->amount = floatval($xml->ewayReturnAmount) / 100.0; } else { $this->amount = null; } // restore old libxml settings libxml_disable_entity_loader($oldDisableEntityLoader); libxml_use_internal_errors($oldUseInternalErrors); } catch (Exception $e) { // restore old libxml settings libxml_disable_entity_loader($oldDisableEntityLoader); libxml_use_internal_errors($oldUseInternalErrors); throw new GFEwayException('Error parsing eWAY response: ' . $e->getMessage()); } }
/** * load eWAY response data as XML string * * @param string $response eWAY response as a string (hopefully of XML data) */ public function loadResponseXML($response) { GFEwayPlugin::log_debug(sprintf('%s: eWAY says "%s"', __METHOD__, $response)); // make sure we actually got something from eWAY if (strlen($response) === 0) { throw new GFEwayException('eWAY payment request returned nothing; please check your card details'); } // prevent XML injection attacks, and handle errors without warnings $oldDisableEntityLoader = libxml_disable_entity_loader(true); $oldUseInternalErrors = libxml_use_internal_errors(true); try { $xml = simplexml_load_string($response); if ($xml === false) { $errmsg = ''; foreach (libxml_get_errors() as $error) { $errmsg .= $error->message; } throw new Exception($errmsg); } $this->status = strcasecmp((string) $xml->Result, 'success') === 0; $this->errorType = (string) $xml->ErrorSeverity; $this->error = (string) $xml->ErrorDetails; // restore old libxml settings libxml_disable_entity_loader($oldDisableEntityLoader); libxml_use_internal_errors($oldUseInternalErrors); } catch (Exception $e) { // restore old libxml settings libxml_disable_entity_loader($oldDisableEntityLoader); libxml_use_internal_errors($oldUseInternalErrors); throw new GFEwayException('Error parsing eWAY recurring payments response: ' . $e->getMessage()); } }