This commit is contained in:
2025-10-28 21:24:50 +05:00
parent cd5570f431
commit 0d3dd8cca2
2 changed files with 82 additions and 15 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Modules\CardTransaction\Repositories;
use App\Modules\CardTransaction\Types\CardTransactionResponse;
use App\Modules\Card\Models\Card;
use App\Modules\Makeable;
use Illuminate\Support\Carbon;
@@ -25,7 +26,7 @@ class CardTransactionRepository
$start_date = Carbon::create($data['start_date']);
$end_date = Carbon::create($data['end_date']);
$response = $this->fetchApi(
$apiResponse = $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),
@@ -35,19 +36,17 @@ class CardTransactionRepository
);
/** @var \App\Modules\CardTransaction\Types\CardTransactionResponse */
$safeResponse = Str::isJson($response)
? json_decode($response)
$response = Str::isJson($apiResponse)
? json_decode($apiResponse)
: emptyClass(errCode: 1, message: 'Connection issue to VP');
if ($safeResponse->errCode != 0) {
return view('module.card-transaction::error-response', ['data' => $safeResponse]);
if ($response->errCode != 0) {
return view('module.card-transaction::error-response', ['data' => $response]);
}
$url = $this->handleFiles($record, $safeResponse);
$url = $this->handleFiles($record, $response);
info($url);
// return ActionResponse::openInNewTab($url);
return response()->download($url);
}
/**
@@ -90,8 +89,11 @@ class CardTransactionRepository
/**
* Handles all file stuff
*
* @param Card $model
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $response
*/
public function handleFiles($model, $data): string
public function handleFiles(Card $model, object $response): string
{
$unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString()));
$dir = public_path("files/{$unique_folder_name}");
@@ -100,7 +102,7 @@ class CardTransactionRepository
$fileDest = $dir."/{$model->id}.pdf";
$this->generateFile($data, $fileDest);
$this->generateFile($response, $fileDest);
return url("files/{$unique_folder_name}/{$model->id}.pdf");
}
@@ -111,14 +113,14 @@ class CardTransactionRepository
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data
* @param string $fileDest
*/
public function generateFile($data, $fileDest): void
public function generateFile(object $response, string $fileDest): void
{
$mpdf = new Mpdf;
// Write HTML content...
$html = Blade::render('orders.cards.card-transaction.download-card-transaction', [
'data' => $data,
'extra' => $this->getExtraVariables($data),
$html = Blade::render('module.card-transaction::card-transaction-table', [
'data' => $response,
'extra' => $this->getExtraVariables($response),
]);
$mpdf->WriteHTML($html);