1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00
invoiceninja/app/Http/Requests/Payment/StorePaymentRequest.php
David Bomba fe5a97e174
Activity API fixes + Payments API (#3076)
* Fixes for Store Payment Validation

* Tests for Payments

* Use custom validator to ensure payments are made ONLY to payable invoices

* Working on custom payment validators

* Update Client balance

* fixes for client balance

* Fixes for activity API
2019-11-18 21:46:01 +11:00

74 lines
1.5 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Payment;
use App\Http\Requests\Request;
use App\Http\ValidationRules\ValidPayableInvoicesRule;
use App\Models\Payment;
use App\Utils\Traits\MakesHash;
class StorePaymentRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('create', Payment::class);
}
public function rules()
{
$this->sanitize();
$rules = [
'amount' => 'numeric|required',
'payment_date' => 'required',
'client_id' => 'required',
'invoices' => 'required',
'invoices' => new ValidPayableInvoicesRule(),
];
return $rules;
}
public function sanitize()
{
$input = $this->all();
if(isset($input['client_id']))
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
if(isset($input['invoices']))
$input['invoices'] = $this->transformKeys(explode(",", $input['invoices']));
if(is_array($input['invoices']) === false)
$input['invoices'] = null;
$this->replace($input);
return $this->all();
}
}