121 lines
4.2 KiB
PHP
121 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Nova\Actions;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Http\Client\Response;
|
|
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<array-key, \App\Models\Payment\OnlinePaymentHistory> $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 ($onlinePaymentResource->api_client == 'billing_sber_username') {
|
|
$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 = 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' => self::resultHTML($response),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the fields available on the action.
|
|
*
|
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
|
* @return array<int, \Laravel\Nova\Fields\Field>
|
|
*/
|
|
public function fields(NovaRequest $request)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Result html
|
|
*
|
|
* @param $response
|
|
*/
|
|
public static function resultHTML(Response $response): string
|
|
{
|
|
$errorMessage = $response->offsetExists('actionCodeDescription') ? $response['actionCodeDescription'] : '';
|
|
|
|
$keyValueListHTML = json_encode($response->json(), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
|
|
|
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">
|
|
<pre>
|
|
$keyValueListHTML
|
|
</pre>
|
|
</ul>
|
|
HTML);
|
|
}
|
|
}
|