Skip to content

Commit 811ed16

Browse files
committed
Added bank's methods
1 parent a024b9b commit 811ed16

File tree

10 files changed

+893
-8
lines changed

10 files changed

+893
-8
lines changed

README.md

Lines changed: 572 additions & 5 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function prompt(string $company,
9090
'query' => $company,
9191
'count' => $count,
9292
'status' => array_values($status),
93-
'type' => CompanyStatus::$map[$type] ?? null,
93+
'type' => CompanyType::$map[$type] ?? null,
9494
'locations' => $locations_array,
9595
'locations_boost' => $locations_boost_array,
9696
]);

src/DaDataServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ public function register()
3333
$this->app->singleton('da_data_company', function () {
3434
return new DaDataCompany();
3535
});
36+
$this->app->singleton('da_data_bank', function () {
37+
return new DaDataBank();
38+
});
3639

3740
$this->app->alias('da_data_address', DaDataAddress::class);
3841
$this->app->alias('da_data_name', DaDataName::class);
3942
$this->app->alias('da_data_email', DaDataEmail::class);
4043
$this->app->alias('da_data_phone', DaDataPhone::class);
4144
$this->app->alias('da_data_company', DaDataCompany::class);
45+
$this->app->alias('da_data_bank', DaDataCompany::class);
4246
}
4347

4448
/**

src/Enums/BankStatus.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace MoveMoveIo\DaData\Enums;
4+
5+
/**
6+
* Class BankStatus
7+
* @package MoveMoveIo\DaData\Enums
8+
*/
9+
class BankStatus extends CompanyStatus
10+
{
11+
12+
}

src/Enums/BankType.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace MoveMoveIo\DaData\Enums;
4+
5+
/**
6+
* Class BankType
7+
* @package MoveMoveIo\DaData\Enums
8+
*/
9+
class BankType
10+
{
11+
12+
const BANK = 0;
13+
const NKO = 1;
14+
const BANK_BRANCH = 2;
15+
const NKO_BRANCH = 3;
16+
const RKC = 4;
17+
const OTHER = 5;
18+
19+
/**
20+
* @var string[]
21+
*/
22+
public static $map = [
23+
self::BANK => 'BANK',
24+
self::NKO => 'NKO',
25+
self::BANK_BRANCH => 'BANK_BRANCH',
26+
self::NKO_BRANCH => 'NKO_BRANCH',
27+
self::RKC => 'RKC',
28+
self::OTHER => 'OTHER',
29+
];
30+
31+
}

src/Facades/DaDataBank.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DaDataBank extends Facade
1818
*/
1919
protected static function getFacadeAccessor() : string
2020
{
21-
return 'dadata_bank';
21+
return 'da_data_bank';
2222
}
2323

2424
}

tests/DaDataBankTest.php

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<?php
2+
3+
namespace MoveMoveIo\DaData\Tests;
4+
5+
use MoveMoveIo\DaData\Enums\BankStatus;
6+
use MoveMoveIo\DaData\Enums\BankType;
7+
use MoveMoveIo\DaData\Facades\DaDataBank;
8+
9+
/**
10+
* Class DaDataBankTest
11+
* @package MoveMoveIo\DaData\Tests
12+
*/
13+
class DaDataBankTest extends TestCase
14+
{
15+
16+
/**
17+
* @test
18+
*/
19+
public function testFindBankByID()
20+
{
21+
$this->assertSame(
22+
DaDataBank::id('044525225'),
23+
$this->BankProvider()
24+
);
25+
}
26+
27+
/**
28+
* @test
29+
*/
30+
public function testPromptFromString()
31+
{
32+
$this->assertSame(
33+
DaDataBank::prompt('сбербанк', 1, [BankStatus::ACTIVE], [BankType::BANK]),
34+
$this->BankProvider()
35+
);
36+
}
37+
38+
/**
39+
* @return array|array[]
40+
*/
41+
public function BankProvider() : array
42+
{
43+
return [
44+
"suggestions" => [
45+
[
46+
"value" => "ПАО Сбербанк",
47+
"unrestricted_value" => "ПАО Сбербанк",
48+
"data" => [
49+
"opf" => [
50+
"type" => "BANK",
51+
"full" => null,
52+
"short" => null,
53+
],
54+
"name" => [
55+
"payment" => "ПАО СБЕРБАНК",
56+
"full" => null,
57+
"short" => "ПАО Сбербанк",
58+
],
59+
"bic" => "044525225",
60+
"swift" => "SABRRUMM",
61+
"inn" => "7707083893",
62+
"kpp" => "773601001",
63+
"okpo" => null,
64+
"correspondent_account" => "30101810400000000225",
65+
"registration_number" => "1481",
66+
"payment_city" => "г Москва",
67+
"state" => [
68+
"status" => "ACTIVE",
69+
"actuality_date" => 1602547200000,
70+
"registration_date" => 677376000000,
71+
"liquidation_date" => null,
72+
],
73+
"rkc" => null,
74+
"address" => [
75+
"value" => "г Москва, ул Вавилова, д 19",
76+
"unrestricted_value" => "117312, г Москва, Академический р-н, ул Вавилова, д 19",
77+
"data" => [
78+
"postal_code" => "117312",
79+
"country" => "Россия",
80+
"country_iso_code" => "RU",
81+
"federal_district" => "Центральный",
82+
"region_fias_id" => "0c5b2444-70a0-4932-980c-b4dc0d3f02b5",
83+
"region_kladr_id" => "7700000000000",
84+
"region_iso_code" => "RU-MOW",
85+
"region_with_type" => "г Москва",
86+
"region_type" => "г",
87+
"region_type_full" => "город",
88+
"region" => "Москва",
89+
"area_fias_id" => null,
90+
"area_kladr_id" => null,
91+
"area_with_type" => null,
92+
"area_type" => null,
93+
"area_type_full" => null,
94+
"area" => null,
95+
"city_fias_id" => "0c5b2444-70a0-4932-980c-b4dc0d3f02b5",
96+
"city_kladr_id" => "7700000000000",
97+
"city_with_type" => "г Москва",
98+
"city_type" => "г",
99+
"city_type_full" => "город",
100+
"city" => "Москва",
101+
"city_area" => "Юго-западный",
102+
"city_district_fias_id" => null,
103+
"city_district_kladr_id" => null,
104+
"city_district_with_type" => "Академический р-н",
105+
"city_district_type" => "р-н",
106+
"city_district_type_full" => "район",
107+
"city_district" => "Академический",
108+
"settlement_fias_id" => null,
109+
"settlement_kladr_id" => null,
110+
"settlement_with_type" => null,
111+
"settlement_type" => null,
112+
"settlement_type_full" => null,
113+
"settlement" => null,
114+
"street_fias_id" => "25f8f29b-b110-40ab-a48e-9c72f5fb4331",
115+
"street_kladr_id" => "77000000000092400",
116+
"street_with_type" => "ул Вавилова",
117+
"street_type" => "ул",
118+
"street_type_full" => "улица",
119+
"street" => "Вавилова",
120+
"house_fias_id" => "93409d8c-d8d4-4491-838f-f9aa1678b5e6",
121+
"house_kladr_id" => "7700000000009240170",
122+
"house_type" => "д",
123+
"house_type_full" => "дом",
124+
"house" => "19",
125+
"block_type" => null,
126+
"block_type_full" => null,
127+
"block" => null,
128+
"flat_type" => null,
129+
"flat_type_full" => null,
130+
"flat" => null,
131+
"flat_area" => null,
132+
"square_meter_price" => null,
133+
"flat_price" => null,
134+
"postal_box" => null,
135+
"fias_id" => "93409d8c-d8d4-4491-838f-f9aa1678b5e6",
136+
"fias_code" => "77000000000000009240170",
137+
"fias_level" => "8",
138+
"fias_actuality_state" => "0",
139+
"kladr_id" => "7700000000009240170",
140+
"geoname_id" => "524901",
141+
"capital_marker" => "0",
142+
"okato" => "45293554000",
143+
"oktmo" => "45397000",
144+
"tax_office" => "7736",
145+
"tax_office_legal" => "7736",
146+
"timezone" => "UTC+3",
147+
"geo_lat" => "55.7001865",
148+
"geo_lon" => "37.5802234",
149+
"beltway_hit" => "IN_MKAD",
150+
"beltway_distance" => null,
151+
"metro" => [
152+
[
153+
"name" => "Ленинский проспект",
154+
"line" => "Калужско-Рижская",
155+
"distance" => 0.8,
156+
], [
157+
"name" => "Площадь Гагарина",
158+
"line" => "МЦК",
159+
"distance" => 0.8,
160+
], [
161+
"name" => "Академическая",
162+
"line" => "Калужско-Рижская",
163+
"distance" => 1.5,
164+
],
165+
],
166+
"qc_geo" => "0",
167+
"qc_complete" => "5",
168+
"qc_house" => "2",
169+
"history_values" => null,
170+
"unparsed_parts" => null,
171+
"source" => "117997, г Москва, ул Вавилова, 19",
172+
"qc" => "0",
173+
]
174+
],
175+
"phones" => null,
176+
]
177+
]
178+
]
179+
];
180+
}
181+
182+
}

tests/DaDataCompanyTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use MoveMoveIo\DaData\Enums\CompanyStatus;
77
use MoveMoveIo\DaData\Enums\CompanyType;
88
use MoveMoveIo\DaData\Facades\DaDataCompany;
9-
use MoveMoveIo\DaData\Facades\DaDataName;
109

1110
/**
1211
* Class DaDataCompanyTest

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protected function getPackageAliases($app)
2020
'DaDataEmail' => 'MoveMoveIo\DaData\Facades\DaDataEmail',
2121
'DaDataPhone' => 'MoveMoveIo\DaData\Facades\DaDataPhone',
2222
'DaDataCompany' => 'MoveMoveIo\DaData\Facades\DaDataCompany',
23+
'DaDataBank' => 'MoveMoveIo\DaData\Facades\DaDataBank',
2324
];
2425
}
2526

0 commit comments

Comments
 (0)