108 lines
3.2 KiB
PHP
108 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Nova\Resources\Order\Card\CardBalance\Actions;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\Str;
|
|
use Laravel\Nova\Actions\Action;
|
|
use Laravel\Nova\Actions\ActionResponse;
|
|
use Laravel\Nova\Fields\ActionFields;
|
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
|
|
|
class DownloadCardBalance extends Action
|
|
{
|
|
use InteractsWithQueue, Queueable;
|
|
|
|
/**
|
|
* Name.
|
|
*/
|
|
public function name(): string
|
|
{
|
|
return __('Download');
|
|
}
|
|
|
|
/**
|
|
* Perform the action on the given models.
|
|
*
|
|
* @param \Laravel\Nova\Fields\ActionFields $fields
|
|
* @param \Illuminate\Support\Collection<array-key, \Illuminate\Database\Eloquent\Model> $models
|
|
* @return mixed
|
|
*/
|
|
public function handle(ActionFields $fields, Collection $models)
|
|
{
|
|
/** @var \App\Models\Order\Card\CardBalance\CardBalance */
|
|
$model = $models->first();
|
|
|
|
/** @var \App\Nova\Resources\Order\Card\CardTransaction\Actions\ResponseTypes\AzatApiClientInfoAllResponse */
|
|
$data = $this->fetchApi(
|
|
passport_serie: $model->passport_serie,
|
|
passport_id: $model->passport_id,
|
|
card_masked: Str::mask($model->card_number, '*', 6, 6),
|
|
card_expire_date: $model->card_month.'/'.substr($model->card_year, 2),
|
|
);
|
|
|
|
if ($data->errCode != 0) {
|
|
return ActionResponse::danger($data->message);
|
|
}
|
|
|
|
return Action::modal('modal-response', [
|
|
'title' => __('Card balance'),
|
|
'html' => Blade::render(
|
|
file_get_contents(app_path('Nova/Resources/Order/Card/CardBalance/Views/card-balance.blade.php')),
|
|
['data' => $data]
|
|
),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the fields available on the action.
|
|
*
|
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
|
* @return array<int, \Laravel\Nova\Fields\Field>
|
|
*/
|
|
public function fields(NovaRequest $request)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Fetch api
|
|
*/
|
|
public function fetchApi($passport_serie, $passport_id, $card_masked, $card_expire_date): object
|
|
{
|
|
$curl = curl_init();
|
|
|
|
curl_setopt_array($curl, array(
|
|
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 => array(
|
|
'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');
|
|
}
|
|
}
|