-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNovaPoshta.php
More file actions
76 lines (62 loc) · 2.35 KB
/
NovaPoshta.php
File metadata and controls
76 lines (62 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Riddman\NovaPoshtaApi;
class NovaPoshta
{
protected static $url = 'https://api.novaposhta.ua/v2.0/json/';
protected static function query($url, $data)
{
$post = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
return (empty($result)) ? false : $result;
}
public function getStreet($novaPoshtaApiKey, $streetName, $cityRef)
{
$streetData = array(
'modelName' => 'Address',
'calledMethod' => 'getStreet',
'methodProperties' => array(
'FindByString' => $streetName,
'CityRef' => $cityRef,
),
'apiKey' => $novaPoshtaApiKey
);
return self::query(self::$url, $departmentsData);
}
public static function getCities($novaPoshtaApiKey)
{
// https://devcenter.novaposhta.ua/docs/services/556d7ccaa0fe4f08e8f7ce43/operations/556d885da0fe4f08e8f7ce46
$citiesData = array(
'modelName' => 'Address',
'calledMethod' => 'getCities',
//'methodProperties' => array(),
'apiKey' => $novaPoshtaApiKey
);
return self::query(self::$url, $citiesData);
}
public static function getDepartments($novaPoshtaApiKey, $limit = null, $page = null)
{
// https://devcenter.novaposhta.ua/docs/services/556d7ccaa0fe4f08e8f7ce43/operations/556d8211a0fe4f08e8f7ce45
$departmentsData = array(
'modelName' => 'AddressGeneral',
'calledMethod' => 'getWarehouses',
//'methodProperties' => array(),
'apiKey' => $novaPoshtaApiKey
);
if ($limit && $page) {
$departmentsData['methodProperties'] = [
'Page' => $page,
'Limit' => $limit
];
}
return self::query(self::$url, $departmentsData);
}
}