composer require wearesho-team/pvbki
Recommended to use container for dependency injections
Use one of implemented configurations:
- Custom Config:
<?php
use Wearesho\Pvbki;
$config = new Pvbki\Config(
$username = 'username',
$password = 'password',
$accessPoint = 'access-point',
$key = 'key',
$mode = Pvbki\Interrelations\ConfigInterface::PRODUCTION_MODE, // or TEST_MODE
$url = Pvbki\Interrelations\ConfigInterface::PRODUCTION_URL // or TEST_URL
);
<?php
use Wearesho\Pvbki;
$config = new Pvbki\EnvironmentConfig($prefix = 'PVBKI_');
Environment variables:
variable | required | default value | description |
---|---|---|---|
PVBKI_USERNAME | yes | Your service login | |
PVBKI_PASSWORD | yes | Your service password | |
PVBKI_ACCESS_POINT | yes | The name of the client's access point to the service | |
PVBKI_KEY | yes | Client access key to the service | |
PVBKI_URL | no | Production url | Url for service requests |
PVBKI_MODE | no | 1 | Test or production mode (0...1) |
Example environment file content:
PVBKI_USERNAME=
PVBKI_PASSWORD=
PVBKI_ACCESS_POINT=
PVBKI_KEY=
PVBKI_URL=
PVBKI_MODE=
- Or use ConfigInterface to implement your own config.
To instantiate service you need config, that implement ConfigInterface, client, that implement GuzzleHttp/ClientInterface.
<?php
use Psr\Log;
use GuzzleHttp;
use Wearesho\Pvbki;
$config = new Pvbki\EnvironmentConfig('PVBKI_');
$client = new GuzzleHttp\Client();
$service = new Pvbki\Service($config, $client);
Use ServiceInterface to customize it;
Use one of implemented subject's identifications:
<?php
use Wearesho\Pvbki;
// Subject's passport series and number
// series must be in 2 chars length, uppercase and UTF-8 format
// number must be in 6 digits length
$passport = new Pvbki\Identifications\Passport('АБ', '123456');
// Subject's DRFO number
// contains 10 digits
$drfo = new Pvbki\Identifications\Drfo('1234567890');
// Subject's OKPO number
// contains 8 digits
$okpo = new Pvbki\Identifications\Okpo('12345678');
// Subject's name, surname and birthdate of subject
// in request body will have format: NameSurnameDDMMYYY
$complex = new Pvbki\Identifications\Complex('Name', 'Surname', new DateTime('2018-03-12'));
All identifications implement SubjectInterface. Use it if you want to customize identification object.
Use one of two statement types:
<?php
use Wearesho\Pvbki\Enums\StatementType;
// Use constructor
$type = new StatementType(StatementType::BASE);
$type = new StatementType(StatementType::SCORING);
// Use MyCLabs\Enum\Enum implementation
$type = StatementType::BASE();
$type = StatementType::SCORING();
Combine SubjectInterface
and StatementType
into StatementRequest
and run import(...)
method.
You will get RequestResponsePair object,
that contains bodies of request and response in string
format.
<?php
use Wearesho\Pvbki;
/** @var Pvbki\Interrelations\SubjectInterface $identification*/
/** @var Pvbki\Enums\StatementType $type */
/** @var Pvbki\Interrelations\ServiceInterface $service */
$request = new Pvbki\StatementRequest($identification, $type);
$requestResponsePair = $service->import($request);
$requestBody = $requestResponsePair->getRequestBody();
$responseBody = $requestResponsePair->getResponseBody();
You can parse existed report to get beautiful objects.
<?php
use Wearesho\Pvbki;
/** @var string $report */
$reportObj = (new Pvbki\Parser())->parse($report);
// It is jsonSerializable
$serialized = json_encode($reportObj);
You can see example of generated json.