Skip to content

Commit a3c489f

Browse files
authored
Merge pull request #3 from movemove-io/Feature/Support_for_all_DaData_methods
Feature/support for all da data methods
2 parents 1e003b8 + b03dc2d commit a3c489f

28 files changed

+3393
-25
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
language: php
22

33
php:
4-
- 7.3
5-
- 7.4
4+
- 7.*
65

76
env:
8-
- LARAVEL_VERSION=7.*
97
- LARAVEL_VERSION=8.*
8+
- LARAVEL_VERSION=7.*
109

1110
matrix:
1211
fast_finish: true

README.md

Lines changed: 2197 additions & 15 deletions
Large diffs are not rendered by default.

src/DaDataBank.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace MoveMoveIo\DaData;
4+
5+
use MoveMoveIo\DaData\Enums\BankStatus;
6+
use MoveMoveIo\DaData\Enums\BankType;
7+
use MoveMoveIo\DaData\Enums\CompanyType;
8+
9+
/**
10+
* Class DaDataBank
11+
* @package MoveMoveIo\DaData
12+
*/
13+
class DaDataBank extends DaDataService
14+
{
15+
16+
/**
17+
* Find bank by BIC, SWIFT, TIN or registration number
18+
*
19+
* @param string $bank
20+
* @return array
21+
* @throws \Exception
22+
*/
23+
public function id(string $bank) : array
24+
{
25+
return $this->suggestApi()->post('rs/findById/bank', ['query' => $bank]);
26+
}
27+
28+
/**
29+
* Prompt bank by part of the ID
30+
*
31+
* @param string $company
32+
* @param int $count
33+
* @param array $status
34+
* @param array $type
35+
* @param string|null $locations
36+
* @param string|null $locations_boost
37+
* @return array
38+
* @throws \Exception
39+
*/
40+
public function prompt(string $company,
41+
int $count = 10,
42+
array $status = [BankStatus::ACTIVE],
43+
array $type = [BankType::BANK, BankType::BANK_BRANCH],
44+
string $locations = null,
45+
string $locations_boost = null
46+
47+
) : array
48+
{
49+
for ($i = 0; $i < count($status); $i++) {
50+
if (BankStatus::$map[$status[$i]]) {
51+
$status[$i] = BankStatus::$map[$status[$i]];
52+
} else {
53+
unset($status[$i]);
54+
}
55+
}
56+
57+
for ($i = 0; $i < count($type); $i++) {
58+
if (BankType::$map[$type[$i]]) {
59+
$type[$i] = BankType::$map[$type[$i]];
60+
} else {
61+
unset($type[$i]);
62+
}
63+
}
64+
65+
$locations_array = [];
66+
if (! is_null($locations)) {
67+
for ($i = 0; $i < count(explode(',', $locations)); $i++) {
68+
array_push($locations_array, ['kladr_id' => trim($locations[$i])]);
69+
}
70+
}
71+
72+
$locations_boost_array = [];
73+
if (! is_null($locations_boost)) {
74+
for ($i = 0; $i < count(explode(',', $locations_boost)); $i++) {
75+
array_push($locations_boost_array, ['kladr_id' => trim($locations_boost[$i])]);
76+
}
77+
}
78+
79+
return $this->suggestApi()->post('rs/suggest/bank', [
80+
'query' => $company,
81+
'count' => $count,
82+
'status' => array_values($status),
83+
'type' => array_values($type),
84+
'locations' => $locations_array,
85+
'locations_boost' => $locations_boost_array,
86+
]);
87+
}
88+
89+
}

src/DaDataCompany.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
namespace MoveMoveIo\DaData;
4+
5+
use MoveMoveIo\DaData\Enums\BranchType;
6+
use MoveMoveIo\DaData\Enums\CompanyScope;
7+
use MoveMoveIo\DaData\Enums\CompanyStatus;
8+
use MoveMoveIo\DaData\Enums\CompanyType;
9+
10+
/**
11+
* Class DaDataPhone
12+
* @package MoveMoveIo\DaData
13+
*/
14+
class DaDataCompany extends DaDataService
15+
{
16+
17+
/**
18+
* Find organization by INN or OGRN ID
19+
*
20+
* @param string $id
21+
* @param int $count
22+
* @param string|null $kpp
23+
* @param int $branch_type
24+
* @param int $type
25+
* @return array
26+
* @throws \Exception
27+
*/
28+
public function id(string $id,
29+
int $count = 10,
30+
string $kpp = null,
31+
int $branch_type = BranchType::MAIN,
32+
int $type = CompanyType::LEGAL
33+
) : array
34+
{
35+
return $this->suggestApi()->post('rs/findById/party', [
36+
'query' => $id,
37+
'count' => $count,
38+
'kpp' => $kpp,
39+
'branch_type' => BranchType::$map[$branch_type] ?? BranchType::$map[BranchType::MAIN],
40+
'type' => CompanyStatus::$map[$type] ?? null,
41+
]);
42+
}
43+
44+
/**
45+
* Prompt company by part of company name
46+
*
47+
* Helps a person quickly enter company details on a web form or app.
48+
*
49+
* @param string $company
50+
* @param int $count
51+
* @param array $status
52+
* @param int $type
53+
* @param string|null $locations
54+
* @param string|null $locations_boost
55+
* @return array
56+
* @throws \Exception
57+
*/
58+
public function prompt(string $company,
59+
int $count = 10,
60+
array $status = [CompanyStatus::ACTIVE],
61+
int $type = CompanyType::INDIVIDUAL,
62+
string $locations = null,
63+
string $locations_boost = null
64+
65+
) : array
66+
{
67+
for ($i = 0; $i < count($status); $i++) {
68+
if (CompanyStatus::$map[$status[$i]]) {
69+
$status[$i] = CompanyStatus::$map[$status[$i]];
70+
} else {
71+
unset($status[$i]);
72+
}
73+
}
74+
75+
$locations_array = [];
76+
if (! is_null($locations)) {
77+
for ($i = 0; $i < count(explode(',', $locations)); $i++) {
78+
array_push($locations_array, ['kladr_id' => trim($locations[$i])]);
79+
}
80+
}
81+
82+
$locations_boost_array = [];
83+
if (! is_null($locations_boost)) {
84+
for ($i = 0; $i < count(explode(',', $locations_boost)); $i++) {
85+
array_push($locations_boost_array, ['kladr_id' => trim($locations_boost[$i])]);
86+
}
87+
}
88+
89+
return $this->suggestApi()->post('rs/suggest/party', [
90+
'query' => $company,
91+
'count' => $count,
92+
'status' => array_values($status),
93+
'type' => CompanyType::$map[$type] ?? null,
94+
'locations' => $locations_array,
95+
'locations_boost' => $locations_boost_array,
96+
]);
97+
}
98+
99+
/**
100+
* Find affiliated companies
101+
*
102+
* @param string $id
103+
* @param int $count
104+
* @param array $scope
105+
* @return array
106+
* @throws \Exception
107+
*/
108+
public function affiliated(string $id, int $count = 10, array $scope = [CompanyScope::FOUNDERS]) : array
109+
{
110+
for ($i = 0; $i < count($scope); $i++) {
111+
if (CompanyScope::$map[$scope[$i]]) {
112+
$scope[$i] = CompanyScope::$map[$scope[$i]];
113+
} else {
114+
unset($scope[$i]);
115+
}
116+
}
117+
118+
return $this->suggestApi()->post('rs/findAffiliated/party', [
119+
'query' => $id,
120+
'count' => $count,
121+
'scope' => array_values($scope),
122+
]);
123+
124+
}
125+
126+
}

src/DaDataEmail.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace MoveMoveIo\DaData;
4+
5+
/**
6+
* Class DaDataEmail
7+
* @package MoveMoveIo\DaData
8+
*/
9+
class DaDataEmail extends DaDataService
10+
{
11+
12+
/**
13+
* Standardization email
14+
*
15+
* Corrects typos and checks for a disposable address. Classifies addresses
16+
* into personal, corporate and role-based.
17+
*
18+
* @param string $email
19+
* @return array
20+
* @throws \Exception
21+
*/
22+
public function standardization(string $email) : array
23+
{
24+
return $this->cleanerApi()->post('clean/email', [$email]);
25+
}
26+
27+
/**
28+
* Auto detection by part of email
29+
*
30+
* @param string $email
31+
* @param int $count
32+
* @return array
33+
* @throws \Exception
34+
*/
35+
public function prompt(string $email, int $count = 10) : array
36+
{
37+
return $this->suggestApi()->post('rs/suggest/email', [
38+
'query' => $email,
39+
'count' => $count,
40+
]);
41+
}
42+
43+
}

src/DaDataName.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace MoveMoveIo\DaData;
4+
5+
use MoveMoveIo\DaData\Enums\Gender;
6+
use MoveMoveIo\DaData\Enums\Parts;
7+
8+
/**
9+
* Class DaDataName
10+
* @package MoveMoveIo\DaData
11+
*/
12+
class DaDataName extends DaDataService
13+
{
14+
15+
/**
16+
* Standardization full name
17+
*
18+
* Splits the full name from the line into separate fields (last name, first name, patronymic).
19+
* Determines gender and declines by case.
20+
*
21+
* @param string $name
22+
* @return array
23+
* @throws \Exception
24+
*/
25+
public function standardization(string $name) : array
26+
{
27+
return $this->cleanerApi()->post('clean/name', [$name]);
28+
}
29+
30+
/**
31+
* Auto detection by part of name
32+
*
33+
*
34+
*
35+
* @param string $name
36+
* @param int $count
37+
* @param int $gender
38+
* @param array $parts
39+
* @return array
40+
* @throws \Exception
41+
*/
42+
public function prompt(string $name, int $count = 10, int $gender = Gender::UNKNOWN, array $parts = []) : array
43+
{
44+
for ($i = 0; $i < count($parts); $i++) {
45+
if (Parts::$map[$parts[$i]]) {
46+
$parts[$i] = Parts::$map[$parts[$i]];
47+
} else {
48+
unset($parts[$i]);
49+
}
50+
}
51+
52+
return $this->suggestApi()->post('rs/suggest/fio', [
53+
'query' => $name,
54+
'count' => $count,
55+
'gender' => Gender::$map[$gender] ?? Gender::$map[Gender::UNKNOWN],
56+
'parts' => array_values($parts),
57+
]);
58+
}
59+
60+
}

src/DaDataPhone.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace MoveMoveIo\DaData;
4+
5+
/**
6+
* Class DaDataPhone
7+
* @package MoveMoveIo\DaData
8+
*/
9+
class DaDataPhone extends DaDataService
10+
{
11+
12+
/**
13+
* Standardization phone
14+
*
15+
* Checks the phone according to the Rossvyaz directory, determines the operator,
16+
* taking into account the portability of numbers, fills in the country, city and time zone.
17+
*
18+
* @param string $phone
19+
* @return array
20+
* @throws \Exception
21+
*/
22+
public function standardization(string $phone) : array
23+
{
24+
return $this->cleanerApi()->post('clean/phone', [$phone]);
25+
}
26+
27+
28+
}

src/DaDataServiceProvider.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,28 @@ public function register()
2121
$this->app->singleton('da_data_address', function () {
2222
return new DaDataAddress();
2323
});
24+
$this->app->singleton('da_data_name', function () {
25+
return new DaDataName();
26+
});
27+
$this->app->singleton('da_data_email', function () {
28+
return new DaDataEmail();
29+
});
30+
$this->app->singleton('da_data_phone', function () {
31+
return new DaDataPhone();
32+
});
33+
$this->app->singleton('da_data_company', function () {
34+
return new DaDataCompany();
35+
});
36+
$this->app->singleton('da_data_bank', function () {
37+
return new DaDataBank();
38+
});
2439

2540
$this->app->alias('da_data_address', DaDataAddress::class);
41+
$this->app->alias('da_data_name', DaDataName::class);
42+
$this->app->alias('da_data_email', DaDataEmail::class);
43+
$this->app->alias('da_data_phone', DaDataPhone::class);
44+
$this->app->alias('da_data_company', DaDataCompany::class);
45+
$this->app->alias('da_data_bank', DaDataCompany::class);
2646
}
2747

2848
/**

0 commit comments

Comments
 (0)