Files
online.tbbank.gov.tm-larave…/app/Modules/CardOrder/Nova/Actions/RetryNovaCardOrderPayment.php
2025-04-21 16:59:26 +05:00

73 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Modules\CardOrder\Nova\Actions;
use App\Nova\Resources\Order\Card\CardOrder;
use App\Repos\Order\OrderRepo;
use App\Repos\Payment\OnlinePaymentRepo;
use Closure;
use Illuminate\Bus\Queueable;
use Illuminate\Http\Request;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionResponse;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Http\Requests\NovaRequest;
class RetryNovaCardOrderPayment extends Action
{
use InteractsWithQueue, Queueable;
/**
* Name.
*/
public function name(): string
{
return __('Retry payment');
}
/**
* Determine if the action is executable for the given request.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Model $model
* @return bool
*/
public function authorizedToRun(Request $request, $model)
{
$this->authorizedToRunAction = ! $model->paid && $model->status === OrderRepo::PENDING;
return $this->authorizedToRunAction;
}
/**
* Perform the action on the given models.
*
* @param ActionFields $fields
* @param Collection<array-key, \Illuminate\Database\Eloquent\Model> $models
* @return mixed
*/
public function handle(ActionFields $fields, Collection $models): mixed
{
$resource = $models->first();
$payment = (new OnlinePaymentRepo)->payCardOrder($resource);
return $payment['status'] === 'success'
? ActionResponse::openInNewTab($payment['url'])
: ActionResponse::danger('Тöleg sistemada registrasiýa bolmady!');
}
/**
* Get the fields available on the action.
*
* @return array<int, \Laravel\Nova\Fields\Field>
*/
public function fields(NovaRequest $request): array
{
return [];
}
}