Files
online.tbbank.gov.tm-larave…/app/Http/Controllers/FetchCardHistoryController.php
2025-06-03 13:43:57 +05:00

177 lines
7.0 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Repos\System\Settings\Legal\PassportRepo;
use Dedoc\Scramble\Attributes\ExcludeRouteFromDocs;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
class FetchCardHistoryController extends Controller
{
/**
* Fetch card history
*
* @param Request $request
*/
#[ExcludeRouteFromDocs]
public function index(Request $request): JsonResponse
{
$request->validate([
'passport_serie' => ['required', 'string', Rule::in(array_keys(PassportRepo::values()))],
'passport_id' => ['required', 'numeric', 'digits:6'],
'card_number' => ['required', 'string', 'max:255'],
'card_expiry_date' => ['required', 'string', 'max:255'],
]);
if (app()->isLocal()) {
return $this->sampleResponse();
}
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'http://10.3.158.102:9999/api/clientinfo',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 15,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => sprintf('{
"idSeria": "%s",
"idNo": "%s",
"clientType": "recipient",
"cardMaskNumber": "%s",
"expDate": "%s"
}',
$request->passport_serie,
$request->passport_id,
$request->card_number,
$request->card_expiry_date,
),
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==',
],
]);
$response = curl_exec($curl);
curl_close($curl);
return response()->json($response);
}
/**
* Sample request
*/
public function sampleResponse(): JsonResponse
{
return response()->json([
'idSeria' => 'I-AS',
'idNo' => '298119',
'cardMaskNumber' => '993403******6836',
'expDate' => '01/34',
'clientType' => 'recipient',
'clientName' => 'Penjiýew Mahtymguly Meretgulowiç',
'depName' => 'Türkmenistanyň "Türkmenbaşy" paýdarlar täjirçilik banky',
'cardPan' => '993403******6836',
'cardAccountNumber' => '1304602071667',
'errCode' => 0,
'message' => 'YETIRILDI',
'messageRu' => 'SUCCESS',
'messageEn' => 'SUCCESS',
'transactions' => [
[
'trandate' => '2024-05-15',
'currency' => 'TMT',
'opersum' => 2220,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-05-31',
'currency' => 'TMT',
'opersum' => 2689,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-06-14',
'currency' => 'TMT',
'opersum' => 2220,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-06-28',
'currency' => 'TMT',
'opersum' => 2689,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-07-15',
'currency' => 'TMT',
'opersum' => 2220,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-07-31',
'currency' => 'TMT',
'opersum' => 2689,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-08-15',
'currency' => 'TMT',
'opersum' => 2220,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-08-30',
'currency' => 'TMT',
'opersum' => 2689,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-09-16',
'currency' => 'TMT',
'opersum' => 2220,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-09-30',
'currency' => 'TMT',
'opersum' => 2689,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-10-15',
'currency' => 'TMT',
'opersum' => 2220,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
[
'trandate' => '2024-10-31',
'currency' => 'TMT',
'opersum' => 2689,
'actionName' => 'Зачисление заработной платы организаций',
'opername' => 'Дополнительный взнос',
],
],
]);
}
}