/**
  * @param string $body
  * @return string
  */
 public function format($body)
 {
     try {
         $dom = $this->xmlLoader->loadXml($body);
         $dom->formatOutput = TRUE;
         return $dom->saveXML();
     } catch (XmlException $e) {
         return $body;
     }
 }
예제 #2
0
 /**
  * Find company by identification given
  *
  * @param string $identification (8 digit string)
  * @return null|Company NULL if not found
  * @throws LookupFailedException
  */
 public function find($identification)
 {
     if (!preg_match('~^[0-9]{8}$~', $identification)) {
         return NULL;
     }
     try {
         $request = new Request(Request::GET, self::ENDPOINT . $identification);
         $response = $this->httpClient->process($request);
         if ($response->getCode() !== Response::S200_OK) {
             throw new LookupFailedException('Unexpected HTTP code from ARES API.');
         }
         $xmlDom = $this->xmlLoader->loadXml($response->getBody());
         $xml = simplexml_import_dom($xmlDom);
     } catch (XmlException $e) {
         throw new LookupFailedException('Invalid XML from ARES', NULL, $e);
     } catch (BadResponseException $e) {
         throw new LookupFailedException('HTTP request to ARES failed', NULL, $e);
     }
     $ns = $xml->getDocNamespaces();
     $data = $xml->children($ns['are'])->Odpoved->children($ns['dtt']);
     if (!$data->Pocet_zaznamu || (int) $data->Pocet_zaznamu === 0) {
         return NULL;
     }
     $companyData = $data->Vypis_basic;
     $address = $companyData->Adresa_ARES;
     $companyname = (string) $companyData->Obchodni_firma;
     $vatNumber = (string) $companyData->DIC;
     $postalCode = (string) $address->PSC;
     $city = (string) $address->Nazev_obce;
     $cityPart = (string) $address->Nazev_casti_obce;
     $cityDistrict = (string) $address->Nazev_mestske_casti;
     $street = (string) $address->Nazev_ulice;
     $houseNum = (string) $address->Cislo_domovni;
     $orientNum = (string) $address->Cislo_orientacni;
     $addrNum = (string) $address->Cislo_do_adresy;
     if (!empty($houseNum)) {
         $houseNumber = $houseNum;
         if (!empty($orientNum)) {
             $houseNumber .= '/' . $orientNum;
         }
     } elseif (!empty($addrNum)) {
         $houseNumber = $addrNum;
     } else {
         $houseNumber = '';
     }
     if ($vatNumber === 'Skupinove_DPH') {
         $vatNumber = '';
     }
     return new Company($identification, $companyname, $vatNumber, $city, $cityPart, $cityDistrict, $street, $houseNumber, $postalCode);
 }
예제 #3
0
파일: PayU.php 프로젝트: lightools/payu
 /**
  * This is expected to be called when push notification from PayU is received on URL they call UrlOnline
  *
  * @param array $post POST data in HTTP request from PayU
  * @return PaymentStatus
  * @throws InvalidRequestException
  * @throws InvalidSignatureException
  * @throws RequestFailedException
  */
 public function getPaymentStatus(array $post)
 {
     $this->checkReceivedPostData($post);
     $request = $this->buildStatusRequest($post);
     try {
         $response = $this->httpClient->process($request);
         if ($response->getCode() !== Response::S200_OK) {
             throw new RequestFailedException('Unexpected HTTP code from PayU');
         }
         $xmlData = $response->getBody();
         $xmlDom = $this->xmlLoader->loadXml($xmlData);
         $xml = simplexml_import_dom($xmlDom);
         if ((string) $xml->status !== 'OK') {
             throw new RequestFailedException('Unexpected response from PayU');
         }
         $xmlSignature = md5($this->posId . $xml->trans->session_id . $xml->trans->order_id . $xml->trans->status . $xml->trans->amount . $xml->trans->desc . $xml->trans->ts . $this->key2);
         if ($xmlSignature !== (string) $xml->trans->sig) {
             throw new InvalidSignatureException('Signature in XML from PayU is corrupted');
         }
         return new PaymentStatus((string) $xml->trans->order_id, (int) $xml->trans->status, (string) $xml->trans->create ? new DateTime($xml->trans->create) : NULL, (string) $xml->trans->init ? new DateTime($xml->trans->init) : NULL, (string) $xml->trans->sent ? new DateTime($xml->trans->sent) : NULL, (string) $xml->trans->recv ? new DateTime($xml->trans->recv) : NULL, (string) $xml->trans->cancel ? new DateTime($xml->trans->cancel) : NULL);
     } catch (BadResponseException $ex) {
         throw new RequestFailedException('HTTP Request to PayU failed', NULL, $ex);
     } catch (XmlException $ex) {
         throw new RequestFailedException('Invalid XML recieved from PayU', NULL, $ex);
     }
 }
예제 #4
0
파일: FioClient.php 프로젝트: lightools/fio
 /**
  * @param string $response XML response
  * @throws FioFailureException
  * @throws FioWarningException
  */
 private function checkUploadResponse($response)
 {
     try {
         $xml = $this->xmlLoader->loadXml($response);
     } catch (XmlException $e) {
         throw new FioFailureException('Invalid XML received from Fio API!', NULL, $e);
     }
     $status = $xml->getElementsByTagName('status')->item(0)->nodeValue;
     if ($status === self::STATUS_WARNING) {
         throw new FioWarningException('Sending Fio orders succeded with warning!');
     } elseif ($status !== self::STATUS_OK) {
         throw new FioFailureException('Sending Fio orders failed!');
     }
 }