Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getFeasibility(ExpeditionRequest $expeditionRequest, $filter = null)
 {
     $this->ensureParameters($expeditionRequest, array('shippingDate', 'accountNumber', 'sender', 'receiver'));
     try {
         $result = $this->client->feasibility(array('parameters' => $expeditionRequest->toArray()));
     } catch (\SoapFault $e) {
         $this->manager->handle($e);
     }
     if (!isset($result->Service)) {
         throw new NoServiceAvailableException();
     }
     $services = $result->Service;
     if (!is_array($services)) {
         $services = array($services);
     }
     foreach ($services as $service) {
         $service->init();
     }
     if (is_callable($filter)) {
         $services = array_values(array_filter($services, $filter));
     }
     if (0 === count($services)) {
         throw new NoServiceAvailableException();
     }
     return $services;
 }
Example #2
0
    protected function ws_tnt_communication($fonction, $parametres)
    {
        $url = $this->getConfigData('gateway_url');
        $username = $this->getConfigData('identifiant');
        $password = $this->getConfigData('mdp');
        $authheader = sprintf('
			<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
			  <wsse:UsernameToken>
				<wsse:Username>%s</wsse:Username>
				<wsse:Password>%s</wsse:Password>
			 </wsse:UsernameToken>
			</wsse:Security>', htmlspecialchars($username), htmlspecialchars($password));
        $authvars = new SoapVar($authheader, XSD_ANYXML);
        $header = new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", $authvars);
        //$soap = new SoapClient($url, array('trace'=>1));
        $soap = new SoapClient($url, array('trace' => 1, 'stream_context' => stream_context_create(array('http' => array('user_agent' => 'PHP/SOAP', 'accept' => 'application/xml')))));
        $soap->__setSOAPHeaders(array($header));
        try {
            if ($fonction == 'feasibility') {
                $result = $soap->feasibility(array('parameters' => $parametres));
            }
            if ($fonction == 'dropOffPoints') {
                $result = $soap->dropOffPoints($parametres);
            }
            if ($fonction == 'citiesGuide') {
                $result = $soap->citiesGuide($parametres);
            }
            if ($fonction == 'expeditionCreation') {
                $result = $soap->expeditionCreation($parametres);
            }
        } catch (Exception $e) {
            $result = $e->getMessage();
        }
        return $result;
    }