public static function initConfig() { Config::setApiKey('Ваш ключ'); Config::setFormat(Config::FORMAT_JSONRPC2); Config::setLanguage(Config::LANGUAGE_UA); Config::setClassLogger(new Logger_example()); }
public static function setDataLogger(DataLogger $dataLogger) { $classLogger = Config::getClassLogger(); if ($classLogger) { $classLogger->setOriginalData($dataLogger->toOriginalData, $dataLogger->fromOriginalData); $classLogger->setData($dataLogger->toData, $dataLogger->fromData); } }
/** * @return SerializerInterface|SerializerFactory|SerializerBatchInterface * @throws NovaPoshtaException */ public static function getSerializer() { $format = strtoupper(Config::getFormat()); $dataSerializer = 'NovaPoshta\\Core\\Serializer\\DataSerializer' . $format; if (!class_exists($dataSerializer)) { throw new NovaPoshtaException('NovaPoshta\\Core\\Serializer\\SerializerFactory_NO_SERIALIZER'); } if (!self::$serializer) { self::$serializer = new $dataSerializer(); } return self::$serializer; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function npSync() { Config::setApiKey(Setting::get('integration.np')); $unitArr = Address::getWarehouses(); $adrArr = Address::getCities(); NPCity::truncate(); NPUnit::truncate(); foreach ($adrArr->data as $value) { NPCity::create(['name' => $value->DescriptionRu, 'ref' => $value->Ref]); } foreach ($unitArr->data as $value) { NPUnit::create(['name' => $value->DescriptionRu, 'ref' => $value->CityRef]); } }
public static function setDataLogger(DataLogger $dataLogger) { $classLogger = Config::getClassLogger(); if ($classLogger) { $classLogger->setOriginalData($dataLogger->toOriginalData, $dataLogger->fromOriginalData); if (!empty($dataLogger->toBatchData)) { for ($i = count($dataLogger->toBatchData); $i > 0; --$i) { $toData = array_shift($dataLogger->toBatchData); $fromData = array_shift($dataLogger->fromBatchData); $classLogger->setData($toData, $fromData); } } else { $classLogger->setData($dataLogger->toData, $dataLogger->fromData); } } }
/** * Execute the console command. * * @return mixed */ public function handle() { // Config::setApiKey(Setting::get('integration.np')); NPCity::truncate(); $this->info('NP City table cleared'); NPUnit::truncate(); $this->info('NP Unit table cleared'); $unitArr = Address::getWarehouses(); $this->info('NP unit fetched'); $adrArr = Address::getCities(); $this->info('NP city fethed'); foreach ($adrArr->data as $value) { NPCity::create(['name' => $value->DescriptionRu, 'ref' => $value->Ref]); } $this->info('City table filled.'); foreach ($unitArr->data as $value) { NPUnit::create(['name' => $value->DescriptionRu, 'ref' => $value->CityRef]); } $this->info('Units table filled'); $this->info('NP SYNC SUCCESSFULL!'); }
private static function getPrintLink($typePrint, MethodParameters $data = null) { $refs = isset($data->DocumentRefs) ? $data->DocumentRefs : null; if (empty($refs)) { return ''; } $link = ''; $link .= Config::getUrlMyNovaPoshta() . '/orders/' . $typePrint; foreach ($refs as $ref) { if (isset($data->Copies) && $data->Copies == self::PRINT_COPIES_FOURFOLD) { $link .= '/orders[]/' . $ref; } $link .= '/orders[]/' . $ref; } if (isset($data->Type)) { $link .= '/type/' . $data->Type; } $link .= '/apiKey/' . Config::getApiKey(); return $link; }
/** * Вызвать метод printScanSheet() - загрузка печатной формы реестра * * @param MethodParameters $data * @return string */ public static function printScanSheet(MethodParameters $data = null) { $refs = isset($data->DocumentRefs) ? $data->DocumentRefs : null; if (empty($refs)) { return ''; } $link = ''; $link .= Config::getUrlMyNovaPoshta() . '/scanSheet/printScanSheet'; foreach ($refs as $ref) { $link .= '/refs[]/' . $ref; } if (isset($data->Type)) { $link .= '/type/' . $data->Type; } $link .= '/apiKey/' . Config::getApiKey(); return $link; }
/** * @param $data * @return bool|mixed */ protected function query($data) { try { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, Config::getUrlApi()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/plain")); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $response = curl_exec($ch); curl_close($ch); return $response; } catch (\Exception $e) { return false; } }