|
| 1 | +# Laravel-Ubki |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <a href="https://github.styleci.io/repos/000000000"><img src="https://github.styleci.io/repos/000000000/shield?style=flat" alt="StyleCI Status"></a> |
| 5 | + <a href="https://packagist.org/packages/arttiger/laravel-ubki"><img src="https://img.shields.io/packagist/dt/arttiger/laravel-ubki?style=flat" alt="Total Downloads"></a> |
| 6 | + <a href="https://packagist.org/packages/arttiger/laravel-ubki"><img src="https://img.shields.io/packagist/v/arttiger/laravel-ubki?style=flat" alt="Latest Stable Version"></a> |
| 7 | + <a href="https://packagist.org/packages/arttiger/laravel-ubki"><img src="https://img.shields.io/packagist/l/arttiger/laravel-ubki?style=flat" alt="License"></a> |
| 8 | +</p> |
| 9 | + |
| 10 | +[Украинское бюро кредитных историй (УБКИ)][link-ubki] занимается сбором, хранением, обработкой и предоставлением кредитных историй. УБКИ получает информацию о заемщиках от банков, страховых компаний, лизинговых компаний, кредитных союзов и других финансовых институтов. Информация передается на добровольной основе и только при наличии письменного согласия заемщика. |
| 11 | + |
| 12 | +Для автоматизации взаимодействия с УБКИ существует [web-сервис][link-ubki-api], который принимает запросы, обрабатывает и выдает ответ в зависимости от типа запроса. |
| 13 | + |
| 14 | +This package allows you to simply and easily work with the web-service UBKI. |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Install the package via composer: |
| 19 | + |
| 20 | +``` bash |
| 21 | +$ composer require arttiger/laravel-ubki |
| 22 | +``` |
| 23 | + |
| 24 | +Next, you need to run migrations: |
| 25 | +```bash |
| 26 | +$ php artisan migrate |
| 27 | +``` |
| 28 | + |
| 29 | +### Configuration |
| 30 | + |
| 31 | +In order to edit the default configuration you may execute: |
| 32 | +``` |
| 33 | +php artisan vendor:publish --provider="Arttiger\Ubki\UbkiServiceProvider" |
| 34 | +``` |
| 35 | + |
| 36 | +After that, `config/ubki.php` will be created. |
| 37 | + |
| 38 | +### Environment |
| 39 | + |
| 40 | +Set environment variable (`.env`) |
| 41 | +``` |
| 42 | +UBKI_TEST_MODE=true |
| 43 | +UBKI_ACCOUNT_LOGIN= |
| 44 | +UBKI_ACCOUNT_PASSWORD= |
| 45 | +UBKI_AUTH_URL=https://secure.ubki.ua/b2_api_xml/ubki/auth |
| 46 | +UBKI_REQUEST_URL=https://secure.ubki.ua/b2_api_xml/ubki/xml |
| 47 | +UBKI_UPLOAD_URL=https://secure.ubki.ua/upload/data/xml |
| 48 | +UBKI_TEST_AUTH_URL=https://secure.ubki.ua:4040/b2_api_xml/ubki/auth |
| 49 | +UBKI_TEST_REQUEST_URL=https://secure.ubki.ua:4040/b2_api_xml/ubki/xml |
| 50 | +UBKI_TEST_UPLOAD_URL=https://secure.ubki.ua:4040/upload/data/xml |
| 51 | +``` |
| 52 | + |
| 53 | +## Usage |
| 54 | +Add `IntegratorUbki`-trait to the model with client data: |
| 55 | +``` |
| 56 | + use Arttiger\Ubki\Traits\IntegratorUbki; |
| 57 | +
|
| 58 | + class Loan extends Model |
| 59 | + { |
| 60 | + use IntegratorUbki; |
| 61 | + ... |
| 62 | + } |
| 63 | +``` |
| 64 | + |
| 65 | +Set the necessary the mapping variables in `config/ubki.php`: |
| 66 | + |
| 67 | +``` |
| 68 | +'model_data' => [ |
| 69 | + 'okpo' => 'inn', // ИНН |
| 70 | + 'lname' => 'lastName', // Фамилия |
| 71 | + 'fname' => 'firstName', // Имя |
| 72 | + 'mname' => 'middleName', // Отчество |
| 73 | + 'bdate' => 'birth_date', // Дата рождения (гггг-мм-дд) |
| 74 | + 'dtype' => 'passport_type', // Тип паспорта (см. справочник "Тип документа") |
| 75 | + 'dser' => 'passport_ser', // Серия паспорта или номер записи ID-карты |
| 76 | + 'dnom' => 'passport_num', // Номер паспорта или номер ID-карты |
| 77 | + 'ctype' => 'contact_type', // Тип контакта (см. справочник "Тип контакта") |
| 78 | + 'cval' => 'contact_val', // Значение контакта (например - "+380951111111") |
| 79 | + 'foto' => 'foto', // <base64(Фото)> |
| 80 | +], |
| 81 | +``` |
| 82 | +This map establishes the correspondence between the attributes of your model and the required query fields in UBKI. |
| 83 | + |
| 84 | +Add a new method `ubkiAttributes()` to the class to add the necessary attributes and fill them with data: |
| 85 | + |
| 86 | +``` |
| 87 | + use Arttiger\Ubki\Traits\IntegratorUbki; |
| 88 | +
|
| 89 | + class Loan extends Model |
| 90 | + { |
| 91 | + use IntegratorUbki; |
| 92 | + ... |
| 93 | + |
| 94 | + public function ubkiAttributes($params = []) |
| 95 | + { |
| 96 | + $client_data = json_decode($this->attributes['client_data']); |
| 97 | + $this->attributes['inn'] = trim($client_data->code); |
| 98 | + $this->attributes['lastName'] = trim($client_data->lastName); |
| 99 | + ... |
| 100 | + } |
| 101 | + } |
| 102 | +``` |
| 103 | +You can use other ways to create custom attributes that you specified in `'model_data'` (`config/ubki.php`). |
| 104 | + |
| 105 | +Now, you can get data from UBKI: |
| 106 | +```php |
| 107 | +$loan = Loan::find(1); |
| 108 | +$result = $loan->ubki(); |
| 109 | +``` |
| 110 | +`$result['response']` - xml response from UBKI (standard report). |
| 111 | + |
| 112 | +You can also pass parameters: |
| 113 | +```php |
| 114 | +$result = $loan->ubki($params); |
| 115 | +``` |
| 116 | +- `$params['report']` - report alias, if you need other reports; |
| 117 | +- `$params['request_id']` - your request ID (if necessary); |
| 118 | +- `$params['lang']` - search language; |
| 119 | +- `$params['delete_all_history']` - set true if you want delete all history; |
| 120 | + |
| 121 | +You can send the loan data to UBKI: |
| 122 | +```php |
| 123 | +$result = $loan->ubki_upload($params); |
| 124 | +``` |
| 125 | +`$params` - will be passed to the ubkiAttributes() method in the model. |
| 126 | + |
| 127 | +For switching between accounts you should add to params: |
| 128 | +- to select second account |
| 129 | +```php |
| 130 | +$params = [ |
| 131 | + 'test' => false, |
| 132 | + 'use_second_account_login' => true |
| 133 | +]; |
| 134 | +``` |
| 135 | + |
| 136 | +- to select main account |
| 137 | +```php |
| 138 | +$params = [ |
| 139 | + 'test' => false, |
| 140 | + 'use_second_account_login' => false |
| 141 | +]; |
| 142 | +``` |
| 143 | + |
| 144 | +if you not select what account to use, last used account will be executed. |
| 145 | + |
| 146 | +## Change log |
| 147 | + |
| 148 | +Please see the [changelog](CHANGELOG.md) for more information on what has changed recently. |
| 149 | + |
| 150 | +## Security |
| 151 | + |
| 152 | +If you discover any security related issues, please email author email instead of using the issue tracker. |
| 153 | + |
| 154 | +## Credits |
| 155 | + |
| 156 | +[Volodymyr Farylevych](https://github.com/arttiger) |
| 157 | + |
| 158 | +## License |
| 159 | + |
| 160 | +Please see the [license file](LICENSE.md) for more information. |
| 161 | + |
| 162 | +[link-ubki]: https://www.ubki.ua/ |
| 163 | +[link-ubki-api]: https://sites.google.com/ubki.ua/doc/%D0%BE%D0%B1%D1%89%D0%B8%D0%B5-%D0%BF%D1%80%D0%B8%D0%BD%D1%86%D0%B8%D0%BF%D1%8B-%D0%B2%D0%B7%D0%B0%D0%B8%D0%BC%D0%BE%D0%B4%D0%B5%D0%B9%D1%81%D1%82%D0%B2%D0%B8%D1%8F |
| 164 | + |
0 commit comments