bank info, types get without token in a separate class

This commit is contained in:
saparatayev 2022-05-25 17:49:03 +05:00
parent bec2b4a448
commit 8d4c1e72b8
5 changed files with 82 additions and 23 deletions

View File

@ -3,14 +3,32 @@
return [
'halkbank' => [
'bank_name' => 'Halkbank',
'class' => 'TPS\Birzha\Classes\Halkbank'
'class' => 'TPS\Birzha\Classes\Halkbank',
'trans' => [
'ru' => 'Карта Алтын Асыр',
'tm' => 'Altyn Asyr Karty',
'en' => 'Altyn Asyr Card',
],
'api_val' => 'halkbank'
],
'rysgal' => [
'bank_name' => 'Rysgal bank',
'class' => 'TPS\Birzha\Classes\Rysgal'
'class' => 'TPS\Birzha\Classes\Rysgal',
'trans' => [
'ru' => 'Rysgal Bank',
'tm' => 'Rysgal Bank',
'en' => 'Rysgal Bank',
],
'api_val' => 'rysgal'
],
'senagat' => [
'bank_name' => 'Senagat PTB',
'class' => 'TPS\Birzha\Classes\Senagat'
'class' => 'TPS\Birzha\Classes\Senagat',
'trans' => [
'ru' => 'Senagat Bank',
'tm' => 'Senagat Bank',
'en' => 'Senagat Bank',
],
'api_val' => 'senagat'
],
];

View File

@ -0,0 +1,52 @@
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
use Cms\Classes\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Validator;
use TPS\Birzha\Models\Settings;
class BanksApiController extends Controller
{
protected $localeRules;
protected $data;
protected $validator;
public function __construct(Request $request)
{
$this->localeRules = ['locale' => 'required|in:ru,tm,en'];
$this->data = $request->only(['locale']);
$this->validator = Validator::make($this->data, $this->localeRules);
}
public function getBankInfo()
{
if($this->validator->fails()) {
return response()->json($this->validator->errors(), 400);
}
return response()->json([
'tax_code' => Settings::getValue('tax_code'),
'bab' => Settings::getValue('bab'),
'manat_account' => Settings::getValue('manat_account'),
'correspondent_account' => Settings::getValue('correspondent_account'),
'bank_address' => trans("validation.api.bank_address_one", [], $this->data['locale'])
], 200);
}
public function getBankTypes()
{
if($this->validator->fails()) {
return response()->json($this->validator->errors(), 400);
}
$banks = [];
foreach (Config::get('bank') as $key => $bank) {
$banks[$key]['api_val'] = $bank['api_val'];
$banks[$key]['name'] = $bank['trans'][$this->data['locale']];
}
return response()->json($banks, 200);
}
}

View File

@ -1,6 +1,7 @@
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
@ -129,22 +130,4 @@ class TransactionsApiController extends KabinetAPIController
return $newPayment;
}
public function getBankInfo(Request $request) {
$data = $request->only(['locale']);
$validator = Validator::make($data, [
'locale' => 'required|in:ru,tm,en',
]);
if($validator->fails()) {
return response()->json($validator->errors(), 400);
}
return response()->json([
'tax_code' => Settings::getValue('tax_code'),
'bab' => Settings::getValue('bab'),
'manat_account' => Settings::getValue('manat_account'),
'correspondent_account' => Settings::getValue('correspondent_account'),
'bank_address' => trans("validation.api.bank_address_one", [], $data['locale'])
], 200);
}
}

View File

@ -69,8 +69,11 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro
Route::post('send-email-verification-link', 'EmailVerificationController@sendEmailVerificationLink');
Route::get('bank-info', 'TransactionsApiController@getBankInfo');
});
Route::get('bank-info', 'BanksApiController@getBankInfo');
Route::get('bank-types', 'BanksApiController@getBankTypes');
});

View File

@ -69,9 +69,12 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro
Route::post('send-email-verification-link', 'EmailVerificationController@sendEmailVerificationLink');
Route::get('bank-info', 'TransactionsApiController@getBankInfo');
});
Route::get('bank-info', 'BanksApiController@getBankInfo');
Route::get('bank-types', 'BanksApiController@getBankTypes');
});