128 lines
3.8 KiB
PHP
128 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Nova\Resources\Order\Card\CardTransaction\Actions;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Str;
|
|
use Laravel\Nova\Actions\Action;
|
|
use Laravel\Nova\Actions\ActionResponse;
|
|
use Laravel\Nova\Fields\ActionFields;
|
|
use Laravel\Nova\Fields\Date;
|
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
|
|
|
class DownloadCardTransaction 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 $models
|
|
* @return mixed
|
|
*/
|
|
public function handle(ActionFields $fields, Collection $models)
|
|
{
|
|
/** @var \App\Models\Order\Card\CardTransaction\CardTransaction */
|
|
$model = $models->first();
|
|
|
|
$start_date = Carbon::create($fields['start_date']);
|
|
$end_date = Carbon::create($fields['end_date']);
|
|
|
|
$response = $this->fetchApi(
|
|
passport_serie: $model->passport_serie,
|
|
passport_id: $model->passport_id,
|
|
card_number_masked: Str::mask($model->card_number, '*', 6, 6),
|
|
card_expire_date: $model->card_month.'/'.substr($model->card_year, 2),
|
|
start_date: $start_date->format('d.m.Y'),
|
|
end_date: $end_date->format('d.m.Y'),
|
|
);
|
|
|
|
$data = json_decode($response);
|
|
|
|
// if (! is_array($response)) {
|
|
// return ActionResponse::danger('Connection issue');
|
|
// }
|
|
|
|
// if ($response['errCode'] != 0) {
|
|
// return ActionResponse::danger($response['message']);
|
|
// }
|
|
|
|
info([
|
|
'type' => gettype($data),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the fields available on the action.
|
|
*
|
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
|
* @return array
|
|
*/
|
|
public function fields(NovaRequest $request): array
|
|
{
|
|
return [
|
|
Date::make(__('Start date'), 'start_date')
|
|
->default(date('Y-m-d', strtotime('-6 months')))
|
|
->rules('required'),
|
|
|
|
Date::make(__('End date'), 'end_date')
|
|
->default(date('Y-m-d'))
|
|
->rules('required'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Fetch from internal API
|
|
*
|
|
* @param string $passport_serie
|
|
* @param string $passport_id
|
|
* @param string $card_number_masked
|
|
* @param string $card_expire_date
|
|
* @param string $start_date
|
|
* @param string $end_date
|
|
*/
|
|
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;
|
|
}
|
|
}
|