2021-06-29 12:42:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests\ClientPortal\PaymentMethod;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
|
|
|
use App\Models\Client;
|
2024-01-14 05:05:00 +01:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
2021-06-29 12:42:44 +02:00
|
|
|
use function auth;
|
|
|
|
use function collect;
|
|
|
|
|
|
|
|
class CreatePaymentMethodRequest extends FormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
|
|
|
/** @var Client $client */
|
2022-03-28 02:03:31 +02:00
|
|
|
$client = auth()->guard('contact')->user()->client;
|
2021-06-29 12:42:44 +02:00
|
|
|
|
|
|
|
$available_methods = [];
|
|
|
|
|
2022-05-18 00:47:54 +02:00
|
|
|
collect($client->service()->getPaymentMethods(-1))
|
2021-06-29 12:42:44 +02:00
|
|
|
->filter(function ($method) use (&$available_methods) {
|
|
|
|
$available_methods[] = $method['gateway_type_id'];
|
|
|
|
});
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (in_array($this->query('method'), $available_methods)) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-06-29 12:42:44 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|