Files
online.tbbank.gov.tm-larave…/app/Modules/SberPaymentOrder/Nova/Resources/NovaSberPaymentOrderItem.php
2025-09-09 10:43:57 +05:00

184 lines
5.6 KiB
PHP

<?php
namespace App\Modules\SberPaymentOrder\Nova\Resources;
use App\Models\Branch\Branch;
use App\Models\Payment\OnlinePaymentHistory;
use App\Modules\SberPaymentOrder\Nova\Resources\Item\NovaSberPaymentOrderItemAuth;
use App\Nova\Actions\CheckOnlinePayment;
use App\Nova\Actions\Sber\SyncWithSystem;
use App\Nova\Resource;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionResponse;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
/**
* @template TModel of \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem
*/
class NovaSberPaymentOrderItem extends Resource
{
use NovaSberPaymentOrderItemAuth;
/**
* The model the resource corresponds to.
*
* @var class-string<\App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem>
*/
public static $model = \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
/**
* The columns that should be searched.
*
* @var array<int, string>
*/
public static $search = [
'id',
];
/**
* The relationships that should be eager loaded on index queries.
*
* @var array
*/
// public static $with = ['branch'];
/**
* Indicates whether the resource should automatically poll for new resources.
*
* @var bool
*/
public static $polling = true;
/**
* The interval at which Nova should poll for new resources.
*
* @var int
*/
public static $pollingInterval = 30;
/**
* Indicates whether to show the polling toggle button inside Nova.
*
* @var bool
*/
public static $showPollingToggle = true;
/**
* Get the displayable label of the resource.
*/
public static function label(): string
{
return __('Payments');
}
/**
* Get the displayable singular label of the resource.
*/
public static function singularLabel(): string
{
return __('Payment');
}
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array<int, \Laravel\Nova\Fields\FieldElement|\Laravel\Nova\Panel>
*/
public function fields(NovaRequest $request): array
{
return [
ID::make(),
Text::make('Amaly geçiren raýatyň F.A.A.', 'payer_name'),
Text::make('Amaly geçiren raýatyň kart belgisi (mask)', 'payer_card'),
Text::make('Töleg ýyly', fn ($model) => $model->created_at->format('Y')),
Text::make('Töleg aýy', fn ($model) => $model->created_at->translatedFormat('F')),
Text::make('Amalyň geçirilen wagty', fn ($model) => $model->created_at->format('H:i, d.m.Y')),
Text::make('Amalyň möçberi', fn ($model) => $model->usd_payment_amount.' USD'),
Text::make('Amalyň manat möçberi', fn ($model) => $model->tmt_payment_amount.' TMT'),
Text::make('Amalyň referensi', fn ($model) => $model->payment_order_number),
Boolean::make(__('Paid'), 'paid'),
];
}
/**
* Actions
*
* @param NovaRequest $request
* @return array<int, \Laravel\Nova\Actions\Action>
*/
public function actions(NovaRequest $request): array
{
return [
Action::using('HALKBANK töleg barla', function (ActionFields $fields, Collection $models) {
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $item */
$item = $models->first();
$onlinePaymentResource = OnlinePaymentHistory::find($item->online_payment_history_id);
if (! $onlinePaymentResource) {
return ActionResponse::danger('Online payment resource tapylmady');
}
$relatedResource = (new $onlinePaymentResource->online_paymantable_type)
->find(id: $onlinePaymentResource->online_paymantable_id);
if (! $relatedResource) {
return ActionResponse::danger('Bu resource tapylmady');
}
$username = $relatedResource->branch->billing_sber_username;
$password = $relatedResource->branch->billing_sber_password;
if ($username == '') {
return Action::modal('modal-response', [
'title' => 'HALKBANK API',
'body' => 'Ulanyjy ady bilen açar sözi gabat gelmedi',
]);
}
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatusExtended.do', [
'language' => 'ru',
'orderId' => $onlinePaymentResource->orderId,
'userName' => $username,
'password' => $password,
]);
return Action::modal('modal-response', [
'title' => 'HALKBANK API',
'html' => CheckOnlinePayment::resultHTML($response),
]);
})->icon('server')
->sole()
->withoutConfirmation(),
SyncWithSystem::make()
->icon('cloud')
->sole()
->withoutConfirmation(),
];
}
}