Beispiel #1
0
 protected static function _call(Loading $loading, $calc)
 {
     $data = ['system' => ['validate' => 0, 'response_type' => 'XML', 'only_calculate' => (int) (!!$calc)], 'loadings' => [$loading]];
     $econt = App::make('Econt');
     $waybill = $econt->request(RequestType::SHIPPING, $data, Endpoint::parcel());
     if (!isset($waybill['result']) || !isset($waybill['result']['e'])) {
         throw new EcontException('Invalid response from Econt parcel service.');
     }
     if (isset($waybill['result']['e']['error']) && $waybill['result']['e']['error']) {
         throw new EcontException(strip_tags(preg_replace('#<br[\\s\\t\\r\\n]*/?>#', "\n", $waybill['result']['e']['error'])));
     }
     return $waybill;
 }
Beispiel #2
0
 public final function request($type, array $data = [], $endpoint = null)
 {
     ini_set('memory_limit', '2G');
     ini_set('max_execution_time', '0');
     $request = array_merge($data, ['client' => ['username' => $this->username, 'password' => $this->password], 'request_type' => $type]);
     $tag = Endpoint::PARCEL ? 'parcels' : 'request';
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><' . $tag . '/>');
     $this->build($xml, $request);
     $response = $this->parse($this->call($endpoint ?: Endpoint::service(), $xml->asXML()));
     if (isset($response['error'])) {
         $message = isset($response['error']['message']) ? $response['error']['message'] : null;
         $code = isset($response['error']['code']) ? $response['error']['code'] : null;
         throw new EcontException($message, $code);
     }
     return $response;
 }