some progress on card balance
This commit is contained in:
@@ -6,7 +6,9 @@ use App\Filament\Clusters\Cards\Cards\Pages\ManageCards;
|
|||||||
use App\Filament\Clusters\Cards\CardsCluster;
|
use App\Filament\Clusters\Cards\CardsCluster;
|
||||||
use App\Modules\AppHelpers\Repositories\DateHelper;
|
use App\Modules\AppHelpers\Repositories\DateHelper;
|
||||||
use App\Modules\Card\Models\Card;
|
use App\Modules\Card\Models\Card;
|
||||||
|
use App\Modules\CardBalance\Repositories\CardBalanceRepository;
|
||||||
use BackedEnum;
|
use BackedEnum;
|
||||||
|
use Filament\Actions\Action;
|
||||||
use Filament\Actions\BulkActionGroup;
|
use Filament\Actions\BulkActionGroup;
|
||||||
use Filament\Actions\DeleteAction;
|
use Filament\Actions\DeleteAction;
|
||||||
use Filament\Actions\DeleteBulkAction;
|
use Filament\Actions\DeleteBulkAction;
|
||||||
@@ -19,6 +21,7 @@ use Filament\Schemas\Schema;
|
|||||||
use Filament\Support\Icons\Heroicon;
|
use Filament\Support\Icons\Heroicon;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class CardResource extends Resource
|
class CardResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -114,8 +117,29 @@ class CardResource extends Resource
|
|||||||
//
|
//
|
||||||
])
|
])
|
||||||
->recordActions([
|
->recordActions([
|
||||||
EditAction::make(),
|
Action::make('card_balance')
|
||||||
DeleteAction::make(),
|
->label(__('Card balance'))
|
||||||
|
->icon('heroicon-m-credit-card')
|
||||||
|
->modalContent(function (Card $record) {
|
||||||
|
/** @var \App\Modules\CardBalance\Type\CardBalanceResponse */
|
||||||
|
$data = CardBalanceRepository::make()->fetchCardBalance(
|
||||||
|
passport_serie: user()->getOption('passport_serie'),
|
||||||
|
passport_id: user()->getOption('passport_id'),
|
||||||
|
card_masked: Str::mask($record->number, '*', 6, 6),
|
||||||
|
card_expire_date: $record->month.'/'.substr($record->year, 2),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($data->errCode != 0) {
|
||||||
|
return $data->message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('module.card-balance::card-balance-modal', compact('data'));
|
||||||
|
}),
|
||||||
|
|
||||||
|
EditAction::make()
|
||||||
|
->label(''),
|
||||||
|
DeleteAction::make()
|
||||||
|
->label(''),
|
||||||
])
|
])
|
||||||
->toolbarActions([
|
->toolbarActions([
|
||||||
BulkActionGroup::make([
|
BulkActionGroup::make([
|
||||||
|
|||||||
64
app/Modules/CardBalance/CardBalanceModule.php
Normal file
64
app/Modules/CardBalance/CardBalanceModule.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\CardBalance;
|
||||||
|
|
||||||
|
use App\Modules\Makeable;
|
||||||
|
use App\Modules\ModuleContract;
|
||||||
|
|
||||||
|
class CardBalanceModule implements ModuleContract
|
||||||
|
{
|
||||||
|
use Makeable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module is enabled
|
||||||
|
*/
|
||||||
|
protected bool $enabled = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if is module enabled
|
||||||
|
*/
|
||||||
|
public function isEnabled(): bool
|
||||||
|
{
|
||||||
|
return $this->enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable module
|
||||||
|
*/
|
||||||
|
public function disable(): void
|
||||||
|
{
|
||||||
|
$this->enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable module
|
||||||
|
*/
|
||||||
|
public function enable(): void
|
||||||
|
{
|
||||||
|
$this->enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if module has a filament resource
|
||||||
|
*/
|
||||||
|
public function hasFilamentResource(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get module composer requirements
|
||||||
|
*/
|
||||||
|
public function getComposerRequirements(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get module composer suggestions
|
||||||
|
*/
|
||||||
|
public function getComposerSuggestions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\CardBalance\Repositories;
|
||||||
|
|
||||||
|
use App\Modules\Card\Models\Card;
|
||||||
|
use App\Modules\Makeable;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class CardBalanceRepository
|
||||||
|
{
|
||||||
|
use Makeable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show card balance
|
||||||
|
* @param Card $record
|
||||||
|
*/
|
||||||
|
public function showCardBalance(Card $record)
|
||||||
|
{
|
||||||
|
/** @var \App\Modules\CardBalance\Type\CardBalanceResponse */
|
||||||
|
$data = $this->fetchCardBalance(
|
||||||
|
passport_serie: user()->getOption('passport_serie'),
|
||||||
|
passport_id: user()->getOption('passport_id'),
|
||||||
|
card_masked: Str::mask($record->number, '*', 6, 6),
|
||||||
|
card_expire_date: $record->month.'/'.substr($record->year, 2),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($data->errCode != 0) {
|
||||||
|
return $data->message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('module.card-balance::card-balance-modal', compact('data'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch card balance
|
||||||
|
*
|
||||||
|
* @param string|int $passport_serie
|
||||||
|
* @param string|int $passport_id
|
||||||
|
* @param string $card_masked
|
||||||
|
* @param string $card_expire_date
|
||||||
|
*/
|
||||||
|
public function fetchCardBalance($passport_serie, $passport_id, $card_masked, $card_expire_date): object
|
||||||
|
{
|
||||||
|
$curl = curl_init();
|
||||||
|
|
||||||
|
curl_setopt_array($curl, [
|
||||||
|
CURLOPT_URL => 'http://10.3.158.102:9999/api/clientcardinfo',
|
||||||
|
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",
|
||||||
|
"cardMaskNumber": "%s",
|
||||||
|
"expDate": "%s"
|
||||||
|
}', $passport_serie, $passport_id, $card_masked, $card_expire_date),
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==',
|
||||||
|
'Content-Type: application/json',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = curl_exec($curl);
|
||||||
|
|
||||||
|
curl_close($curl);
|
||||||
|
|
||||||
|
return Str::isJson($response)
|
||||||
|
? json_decode($response)
|
||||||
|
: emptyClass(errCode: 1, message: 'Connection issue to VP');
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
57
app/Modules/CardBalance/Type/CardBalanceResponse.php
Normal file
57
app/Modules/CardBalance/Type/CardBalanceResponse.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\CardBalance\Type;
|
||||||
|
|
||||||
|
class CardBalanceResponse
|
||||||
|
{
|
||||||
|
public string $idSeria;
|
||||||
|
|
||||||
|
public string $idNo;
|
||||||
|
|
||||||
|
public string $cardMaskNumber;
|
||||||
|
|
||||||
|
public string $expDate;
|
||||||
|
|
||||||
|
public string $clientType;
|
||||||
|
|
||||||
|
public string $fromDate;
|
||||||
|
|
||||||
|
public string $toDate;
|
||||||
|
|
||||||
|
public string $clientName;
|
||||||
|
|
||||||
|
public string $depName;
|
||||||
|
|
||||||
|
public string $cardName;
|
||||||
|
|
||||||
|
public string $cardPan;
|
||||||
|
|
||||||
|
public string $cardAccountNumber;
|
||||||
|
|
||||||
|
public string $birthDate;
|
||||||
|
|
||||||
|
public string $mfo;
|
||||||
|
|
||||||
|
public string $inn;
|
||||||
|
|
||||||
|
public string $passOrg;
|
||||||
|
|
||||||
|
public string $passDate;
|
||||||
|
|
||||||
|
public string $address;
|
||||||
|
|
||||||
|
public string $phone;
|
||||||
|
|
||||||
|
public string $accountNumber;
|
||||||
|
|
||||||
|
public int $errCode;
|
||||||
|
|
||||||
|
public string $message;
|
||||||
|
|
||||||
|
public string $messageRu;
|
||||||
|
|
||||||
|
public string $messageEn;
|
||||||
|
|
||||||
|
/** @var array<int, object> */
|
||||||
|
public array $transactions;
|
||||||
|
}
|
||||||
@@ -45,3 +45,63 @@ function emptyModule(): ModuleContract
|
|||||||
{
|
{
|
||||||
return modular()->emptyModule();
|
return modular()->emptyModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an anonymous class that acts as a dynamic object.
|
||||||
|
*
|
||||||
|
* @param mixed ...$arguments Key-value pairs passed as an associative array.
|
||||||
|
* @return object Anonymous class instance with dynamic properties.
|
||||||
|
*/
|
||||||
|
function emptyClass(...$arguments): object
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array<string, mixed> $arguments
|
||||||
|
*/
|
||||||
|
return new class($arguments)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Internal data storage.
|
||||||
|
*
|
||||||
|
* @var array<string, mixed>
|
||||||
|
*/
|
||||||
|
private array $data = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that sets properties.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $props
|
||||||
|
*/
|
||||||
|
public function __construct(array $props)
|
||||||
|
{
|
||||||
|
foreach ($props as $key => $value) {
|
||||||
|
$this->data[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic getter.
|
||||||
|
*
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
|
public function __get(string $key): mixed
|
||||||
|
{
|
||||||
|
return $this->data[$key] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic setter.
|
||||||
|
*/
|
||||||
|
public function __set(string $key, mixed $value): void
|
||||||
|
{
|
||||||
|
$this->data[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic isset.
|
||||||
|
*/
|
||||||
|
public function __isset(string $key): bool
|
||||||
|
{
|
||||||
|
return isset($this->data[$key]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user