1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php

55 lines
1.3 KiB
PHP
Raw Normal View History

<?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;
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
{
2024-06-15 08:18:33 +02:00
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
}]);
/** @var Client $client */
2022-03-28 02:03:31 +02:00
$client = auth()->guard('contact')->user()->client;
$available_methods = [];
collect($client->service()->getPaymentMethods(-1))
->filter(function ($method) use (&$available_methods) {
$available_methods[] = $method['gateway_type_id'];
});
2024-02-13 05:25:18 +01:00
if (in_array($this->query('method'), $available_methods)) {
return true;
}
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}