wip
This commit is contained in:
@@ -4,10 +4,12 @@ namespace App\Modules\CardTransaction\Repositories;
|
|||||||
|
|
||||||
use App\Modules\Card\Models\Card;
|
use App\Modules\Card\Models\Card;
|
||||||
use App\Modules\Makeable;
|
use App\Modules\Makeable;
|
||||||
|
use Exception;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Blade;
|
use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Mpdf\Mpdf;
|
use Mpdf\Mpdf;
|
||||||
@@ -60,9 +62,6 @@ class CardTransactionRepository
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch from internal API
|
* Fetch from internal API
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function fetchApi(
|
public function fetchApi(
|
||||||
string $passport_serie,
|
string $passport_serie,
|
||||||
@@ -71,29 +70,37 @@ class CardTransactionRepository
|
|||||||
string $card_expire_date,
|
string $card_expire_date,
|
||||||
string $start_date,
|
string $start_date,
|
||||||
string $end_date
|
string $end_date
|
||||||
) {
|
): string {
|
||||||
$curl = curl_init();
|
try {
|
||||||
curl_setopt_array($curl, [
|
$curl = curl_init();
|
||||||
CURLOPT_URL => 'http://10.3.158.102:9999/api/clientinfo/all',
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_URL => 'http://10.3.158.102:9999/api/clientinfo/all',
|
||||||
CURLOPT_ENCODING => '',
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_MAXREDIRS => 10,
|
CURLOPT_ENCODING => '',
|
||||||
CURLOPT_TIMEOUT => 0,
|
CURLOPT_MAXREDIRS => 10,
|
||||||
CURLOPT_FOLLOWLOCATION => true,
|
CURLOPT_TIMEOUT => 0,
|
||||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||||
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_CUSTOMREQUEST => 'POST',
|
||||||
CURLOPT_HTTPHEADER => [
|
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),
|
||||||
'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==',
|
CURLOPT_HTTPHEADER => [
|
||||||
'Content-Type: application/json',
|
'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==',
|
||||||
],
|
'Content-Type: application/json',
|
||||||
]);
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
|
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
return $response;
|
return (string) $response;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error('AZAT API ERROR: '.$e->getMessage(), [
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return 'CURL Error';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +110,7 @@ class CardTransactionRepository
|
|||||||
*/
|
*/
|
||||||
public function generateFileUrl(Card $model, object $response): string
|
public function generateFileUrl(Card $model, object $response): string
|
||||||
{
|
{
|
||||||
$unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString()));
|
$unique_folder_name = Str::snake(str_replace(':', '-', now()->toDateTimeString()));
|
||||||
$dir = public_path("files/{$unique_folder_name}");
|
$dir = public_path("files/{$unique_folder_name}");
|
||||||
|
|
||||||
File::makeDirectory($dir, 0777, true, true);
|
File::makeDirectory($dir, 0777, true, true);
|
||||||
@@ -118,7 +125,7 @@ class CardTransactionRepository
|
|||||||
/**
|
/**
|
||||||
* Generate file
|
* Generate file
|
||||||
*
|
*
|
||||||
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data
|
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $response
|
||||||
*/
|
*/
|
||||||
public function generateFile(object $response, string $fileDest): void
|
public function generateFile(object $response, string $fileDest): void
|
||||||
{
|
{
|
||||||
@@ -137,25 +144,26 @@ class CardTransactionRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data
|
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $response
|
||||||
*/
|
*/
|
||||||
public function getExtraVariables($data): object
|
public function getExtraVariables(object $response): object
|
||||||
{
|
{
|
||||||
if (count($data->transactions) < 1) {
|
info([$response]);
|
||||||
|
if (count($response->transactions) < 1) {
|
||||||
return emptyClass(basdakyGalyndy: 0, ahyrkyGalyndy: 0, girdeji: 0, cykdajy: 0);
|
return emptyClass(basdakyGalyndy: 0, ahyrkyGalyndy: 0, girdeji: 0, cykdajy: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$basdakyGalyndy = $data->transactions[0]->rest;
|
$basdakyGalyndy = $response->transactions[0]->rest;
|
||||||
$basdakyTransaksiya = $data->transactions[0]->currOperSum;
|
$basdakyTransaksiya = $response->transactions[0]->currOperSum;
|
||||||
$sonkyGalyndy = $data->transactions[count($data->transactions) - 1]->rest;
|
$sonkyGalyndy = $response->transactions[count($response->transactions) - 1]->rest;
|
||||||
|
|
||||||
$positive = 0;
|
$positive = 0;
|
||||||
$negative = 0;
|
$negative = 0;
|
||||||
for ($i = 0; $i < count($data->transactions); $i++) {
|
for ($i = 0; $i < count($response->transactions); $i++) {
|
||||||
if ($data->transactions[$i]->sign == '-') {
|
if ($response->transactions[$i]->sign == '-') {
|
||||||
$negative += $data->transactions[$i]->currOperSum;
|
$negative += $response->transactions[$i]->currOperSum;
|
||||||
} else {
|
} else {
|
||||||
$positive += $data->transactions[$i]->currOperSum;
|
$positive += $response->transactions[$i]->currOperSum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user