diskigor001/pvbki-main

PVBKI API integration

dev-main 2023-04-10 14:53 UTC

This package is not auto-updated.

Last update: 2024-04-23 18:32:04 UTC


README

Installation

composer require diskigor001/pvbki-main

Usage

Recommended to use container for dependency injections

Configuration

Use one of implemented configurations:

<?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=

Service instance

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;

Import method

Identification subject

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.

Statement request type

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();

Run import method

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();

Parser

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.

License

MIT