Skip to content

joni-jones/yii2-novaposhta

Repository files navigation

Yii2 extension for Nova Poshta API

IMPORTANT! Extension is already under development

Extension to work with Nova Poshta API

Latest Stable Version Scrutinizer Code Quality Total Downloads Build Status License Code Coverage

Usage

All models methods and properties has the same as in official documentation.

  1. Setup configuration:
'components' => [
    'novaposhta' => [
        'class' => 'jones\novaposhta\Api',
        'api_key' => 'specify your api key',
        'format' => 'json' \\supported json and xml formats
    ]
]

The json format more appreciated, because response formatting faster.

  1. Set alias for extension in bootstrap.php file:
Yii::setAlias('novaposhta', '@vendor/joni-jones/yii2-novaposhta');
  1. Configure extension translations:
'components' => [
    'api' => [
        'class' => 'yii\i18n\PhpMessageSource',
        'basePath' => '@novaposhta/messages',
        'sourceLanguage' => 'en',
    ],
]
  1. Create new api model:
$model = new \jones\novaposhta\Address(new \jones\novaposhta\request\Factory());

or

$model = Yii::createObject(\jones\novaposhta\Address::class);

in the second case request factory will be created by Yii DI manager.

  1. Process request:
$areas = $model->getAreas();

Each model has list of rules where described attributes per each scenario. If some api call will be processed without required attributes you will get false instead normal response. To get list of errors just call:

$model->getErrors();

List of available models

  • Address
  • InternetDocument (under development)
  • Common (under development)
  • ContactPerson (under development)
  • Counterparty (under development)
  • ScanSheet (under development)

List of implemented methods

Address model

  • getAreas

    $areas = $addressModel->getAreas();
  • getCities

    $cities = $addressModel->getCities('Бровари'); // filter not empty add it to `FindByString` request param
  • delete

    $addressModel->Ref = 'fs1d2vbv12'; // if Ref is not specified you will get validation error
    $addressModel->delete();
  • getWarehouses

    $addressModel->CityRef = 'df1j2cmf5d';  // CityRef is required parameter
    $warehouses = $addressModel->getWarehouses('Броварський'); // Street name is additional parameter
  • getStreet

    $streets = $addressModel->getStreet('city ref', 'street name');
  • getWarehouseTypes

    $types = $addressModel->getWarehouseTypes();
  • save

    $addressModel->StreetRef = 'd8364179-4149-11dd-9198-001d60451983';
    $addressModel->CounterpartyRef = '56300fb9-cbd3-11e4-bdb5-005056801329';
    $response = $addressModel->save('10', 12, 'Comment');   // building should be in string type
  • update

    $addressModel->Ref = '503702df-cd4c-11e4-bdb5-005056801329';
    $addressModel->CounterpartyRef = '56300fb9-cbd3-11e4-bdb5-005056801329';
    $response = $addressModel->save('10', 12, 'Comment');   // building should be in string type

Counterparty model

  • getAreas

    $counterparties = $counterpartyModel->getCounterparties();
  • getCounterpartyAddresses

    $addresses = $counterpartyModel->getCounterpartyAddresses('6e9acced-d072-11e3-95eb-0050568046cd', 'Sender');
  • getCounterpartyContactPersons

    $persons = $counterpartyModel->getCounterpartyContactPersons('6e9acced-d072-11e3-95eb-0050568046cd');
  • save

    // set model attributes
    $counterpartyModel->cityRef = '0050568046cd';
    .
    .
    .
    $counterpartyModel->Phone = '0567894512';
    $response = $counterpartyModel->save();
  • update

    // set model attributes
    $counterpartyModel->Ref = '005056801329';
    .
    .
    .
    $counterpartyModel->Email = '[email protected]';
    $response = $counterpartyModel->update();
  • delete

    $counterparty->Ref = '0050568002cf'; // if Ref is not specified you will get validation error
    $counterparty->delete();

About

Yii2 extension for Nova Poshta API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages