1. Go to this page and download the library: Download dou-xx/nova-poshta library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dou-xx / nova-poshta example snippets
use Dou\NovaPoshta\Requests\Counterparty\GetSenderRequest;
....
$apiKey = '78f19724b0......9b1541c0a';
$senderRequest = new GetSenderRequest($apiKey);
$response = $senderRequest->send();
dump($response->isSuccess()); // true or false
dump($response->getItem('FirstName')); // Приватна особа or null
dump($response->getItem('Ref')); // 55d96953-528d-0000-0000-005056881c6b or null
dump($response->getData()); // Весь массив ответа Новой Почты, или []
use Dou\NovaPoshta\Requests\Counterparty\GetCounterPartyContactsRequest;
.....
// это идентификатор отправителя из прошлого примера
$ref = $response->getItem('Ref');
$senderContactRequest = new GetCounterPartyContactsRequest($apiKey);
$response = $senderContactRequest->setRef($ref)->send();
dump($response->isSuccess());
dump($response->getItem('Ref'));
dump($response->getItem('LastName'));
dump($response->getItem('FirstName'));
dump($response->getItem('MiddleName'));
dump($response->getItem('Phones'));
dump($response->getItem('Description'));
use Dou\NovaPoshta\Requests\Address\CreateAddressRequest;
.....
$ref = $response->getCounterPartyRef();
$cityRef = '4a579385-413e-11dd-9198-001d60451983';
$recipient = new CreateAddressRequest($apiKey);
// тут передается $ref - Ref получателя, $cityRef - Ref улицы из справочника новой почты, Номер дома, номер квартиры
$recipient->setFields($ref, $cityRef, 14, 2);
$response = $recipient->send();
dump($response->getItem('Ref')); // Ref созданного адреса
dump($response->getItem('Description')); // Адрес текстом (строкой)
public function tracking() {
$apiKey = '78f19724b096.....c19b1541c0a';
$trackingRequest = new TrackingRequest($apiKey);
$trackingRequest->setSenderPhone('380979998877');
$trackingRequest->setTTNs([
'20450910916240',
'20450910817793',
'20450910815791'
]);
$response = $trackingRequest->send();
dump($response->getData());
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.