88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\CardTransaction\Repositories;
|
|
|
|
use App\Modules\Card\Models\Card;
|
|
use App\Modules\Makeable;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Str;
|
|
|
|
class CardTransactionRepository
|
|
{
|
|
use Makeable;
|
|
|
|
/**
|
|
* Download card transaction
|
|
*
|
|
* @param array{start_date: string, end_date: string} $data
|
|
*/
|
|
public function downloadCardTransaction(array $data, Card $record)
|
|
{
|
|
$start_date = Carbon::create($data['start_date']);
|
|
$end_date = Carbon::create($data['end_date']);
|
|
|
|
$response = $this->fetchApi(
|
|
passport_serie: user()->getOption('passport_serie') ?? 'I',
|
|
passport_id: user()->getOption('passport_id') ?? '909090',
|
|
card_number_masked: Str::mask($record->number, '*', 6, 6),
|
|
card_expire_date: $record->month.'/'.substr($record->year, 2),
|
|
start_date: $start_date->format('d.m.Y'),
|
|
end_date: $end_date->format('d.m.Y'),
|
|
);
|
|
|
|
info([
|
|
'response' => $response,
|
|
'type' => gettype($response),
|
|
]);
|
|
|
|
// /** @var ResponseTypes\AzatApiClientInfoAllResponse */
|
|
// $data = Str::isJson($response)
|
|
// ? json_decode($response)
|
|
// : emptyClass(errCode: 1, message: 'Connection issue to VP');
|
|
|
|
// if ($data->errCode != 0) {
|
|
// return ActionResponse::danger($data->message);
|
|
// }
|
|
|
|
// $url = $this->doFiles($model, $data);
|
|
}
|
|
|
|
/**
|
|
* Fetch from internal API
|
|
*
|
|
*
|
|
* @return string
|
|
*/
|
|
public function fetchApi(
|
|
string $passport_serie,
|
|
string $passport_id,
|
|
string $card_number_masked,
|
|
string $card_expire_date,
|
|
string $start_date,
|
|
string $end_date
|
|
) {
|
|
$curl = curl_init();
|
|
curl_setopt_array($curl, [
|
|
CURLOPT_URL => 'http://10.3.158.102:9999/api/clientinfo/all',
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_ENCODING => '',
|
|
CURLOPT_MAXREDIRS => 10,
|
|
CURLOPT_TIMEOUT => 0,
|
|
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", "fromDate" : "%s", "toDate" : "%s" }', $passport_serie, $passport_id, $card_number_masked, $card_expire_date, $start_date, $end_date),
|
|
CURLOPT_HTTPHEADER => [
|
|
'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==',
|
|
'Content-Type: application/json',
|
|
],
|
|
]);
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $response;
|
|
}
|
|
}
|