Files
online.tbbank.gov.tm-larave…/app/Nova/Actions/CheckOnlinePayment.php
2024-11-23 00:37:55 +05:00

116 lines
3.8 KiB
PHP

<?php
namespace App\Nova\Actions;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;
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 CheckOnlinePayment 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)
{
if ($models->count() > 1) {
return ActionResponse::danger('Diňä bir resursa barlap bolýar');
}
$onlinePaymentResource = $models->first();
$relatedResource = (new $onlinePaymentResource->online_paymantable_type)->find(id: $onlinePaymentResource->online_paymantable_id);
if (! $relatedResource) {
return ActionResponse::danger('Bu resource tapylmady');
}
$relatedResource->load('branch');
$username = '';
$password = '';
if ($onlinePaymentResource->api_client == 'billing_visa_master_username') {
$username = $relatedResource->branch->billing_visa_master_username;
$password = $relatedResource->branch->billing_visa_master_password;
}
if ($onlinePaymentResource->api_client == 'billing_username') {
$username = $relatedResource->branch->billing_username;
$password = $relatedResource->branch->billing_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/getOrderStatus.do', [
'language' => 'ru',
'orderId' => $onlinePaymentResource->orderId,
'userName' => $username,
'password' => $password,
]);
return Action::modal('modal-response', [
'title' => 'HALKBANK API',
'html' => self::resultHTML($response),
]);
}
/**
* Get the fields available on the action.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [];
}
/**
* Result html
*
* @param $response
*/
public static function resultHTML($response)
{
$errorMessage = $response['ErrorMessage'];
$keyValueListHTML = '';
$response->collect()->each(function ($item, $key) use (&$keyValueListHTML) {
$keyValueListHTML .= "<li><span>{$key}:</span> <strong>{$item}</strong></li>";
});
return Blade::render(<<<HTML
<span class="mb-2">HALKBANK-dan gelen netije:</span>
<hr>
<div class="w-full border text-left appearance-none rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 relative inline-flex items-center shadow h-9 px-3 bg-primary-500 border-primary-500 text-white dark:text-gray-900">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current shrink-0 w-6 h-6 mr-2">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span>$errorMessage</span>
</div>
<ul class="p-2">
$keyValueListHTML
</ul>
HTML);
}
}