Files
online.tbbank.gov.tm-larave…/app/Nova/Actions/Sber/SyncWithSystem.php
2025-09-09 11:07:35 +05:00

88 lines
2.5 KiB
PHP

<?php
namespace App\Nova\Actions\Sber;
use App\Models\Payment\OnlinePaymentHistory;
use App\Nova\Actions\CheckOnlinePayment;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionResponse;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Http\Requests\NovaRequest;
class SyncWithSystem extends Action
{
use InteractsWithQueue, Queueable;
/**
* Name.
*/
public function name(): string
{
return __('Sync with system');
}
/**
* 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\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $item */
$item = $models->first();
/** @var \App\Models\Payment\OnlinePaymentHistory $onlinePaymentResource */
$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');
}
if (! $relatedResource->branch) {
return ActionResponse::danger('Şahamça bilen birikdirilmedik');
}
$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 = checkOnlinePayment($onlinePaymentResource->orderId, $username, $password);
// syncWithBankSystem();
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 [];
}
}