Files
online.tbbank.gov.tm-larave…/app/Nova/Actions/CheckOnlinePaymentStatus.php
2025-04-22 20:05:40 +05:00

85 lines
2.7 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;
/**
* 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\CardOrder $item */
$item = $models->first();
$onlinePaymentResource = OnlinePaymentHistory::query()
->where('online_paymantable_type', 'App\Models\Order\Card\CardOrder')
->where('online_paymantable_id', $item->id)
->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 [];
}
}