mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-30 21:44:34 -04:00
CreatePaymentMethodRequest.php allow only enabled methods to pass
This commit is contained in:
parent
2e0d9e170f
commit
31e138c41e
@ -14,7 +14,7 @@ namespace App\Http\Controllers\ClientPortal;
|
|||||||
|
|
||||||
use App\Events\Payment\Methods\MethodDeleted;
|
use App\Events\Payment\Methods\MethodDeleted;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\ClientPortal\CreatePaymentMethodRequest;
|
use App\Http\Requests\ClientPortal\PaymentMethod\CreatePaymentMethodRequest;
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
@ -52,7 +52,7 @@ class PaymentMethodController extends Controller
|
|||||||
|
|
||||||
$data['gateway'] = $gateway;
|
$data['gateway'] = $gateway;
|
||||||
$data['client'] = auth()->user()->client;
|
$data['client'] = auth()->user()->client;
|
||||||
|
|
||||||
return $gateway
|
return $gateway
|
||||||
->driver(auth()->user()->client)
|
->driver(auth()->user()->client)
|
||||||
->setPaymentMethod($request->query('method'))
|
->setPaymentMethod($request->query('method'))
|
||||||
@ -93,7 +93,7 @@ class PaymentMethodController extends Controller
|
|||||||
public function verify(ClientGatewayToken $payment_method)
|
public function verify(ClientGatewayToken $payment_method)
|
||||||
{
|
{
|
||||||
// $gateway = $this->getClientGateway();
|
// $gateway = $this->getClientGateway();
|
||||||
|
|
||||||
return $payment_method->gateway
|
return $payment_method->gateway
|
||||||
->driver(auth()->user()->client)
|
->driver(auth()->user()->client)
|
||||||
->setPaymentMethod(request()->query('method'))
|
->setPaymentMethod(request()->query('method'))
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests\ClientPortal;
|
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class CreatePaymentMethodRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function authorize()
|
|
||||||
{
|
|
||||||
return auth()->user()->client->getCreditCardGateway() ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\ClientPortal\PaymentMethod;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use App\Models\Client;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/** @var Client $client */
|
||||||
|
$client = auth()->user()->client;
|
||||||
|
|
||||||
|
$available_methods = [];
|
||||||
|
|
||||||
|
collect($client->service()->getPaymentMethods(1))
|
||||||
|
->filter(function ($method) use (&$available_methods) {
|
||||||
|
$available_methods[] = $method['gateway_type_id'];
|
||||||
|
});
|
||||||
|
|
||||||
|
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 [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user