Files
online.tbbank.gov.tm-larave…/app/Nova/Actions/CheckOnlinePaymentStatus.php
2025-04-23 11:46:52 +05:00

94 lines
2.8 KiB
PHP

<?php
namespace App\Nova\Actions;
use App\Models\Payment\OnlinePaymentHistory;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
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\Http\Requests\NovaRequest;
class CheckOnlinePaymentStatus extends Action
{
use InteractsWithQueue, Queueable;
/**
* @property string $paymantable_type Payment Related Class
*/
public function __construct(
protected string $paymantable_type,
) {
// ...
}
/**
* 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)
{
$item = $models->first();
$onlinePaymentResource = OnlinePaymentHistory::query()
->where('online_paymantable_type', $this->paymantable_type)
->where('online_paymantable_id', $item->id)
->latest()
->first();
if (! $onlinePaymentResource) {
return Action::modal('modal-response', [
'title' => 'Onlaýn töleg taryhy ýok',
'body' => 'Onlaýn töleg taryhy ýok',
]);
}
if (! $item->branch) {
return Action::modal('modal-response', [
'title' => 'Şahamça bilen birikdirilmedik',
'body' => 'Şahamça bilen birikdirilmedik',
]);
}
$username = $item->branch->billing_username;
$password = $item->branch->billing_password;
if (($username == '' || $password == '') || (is_null($username) || is_null($password))) {
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),
]);
}
/**
* Get the fields available on the action.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [];
}
}