mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
0878decf18
* Ensure payments, invoice and credit amount balance in the validator prior to saving * additional payment validation rules and tests for processing payments * Factories for credits * Tests for payments * Working on updating a payment * Working on updating a payment * fixes for updating a payment * Working on Payment Tests * More tests for payments, formrequests * remove product_key as required from products
66 lines
1.4 KiB
PHP
66 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Http\ValidationRules;
|
|
|
|
use App\Libraries\MultiDB;
|
|
use App\Models\Credit;
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
/**
|
|
* Class ValidCreditsPresentRule
|
|
* @package App\Http\ValidationRules
|
|
*/
|
|
class ValidCreditsPresentRule implements Rule
|
|
{
|
|
|
|
/**
|
|
* @param string $attribute
|
|
* @param mixed $value
|
|
* @return bool
|
|
*/
|
|
public function passes($attribute, $value)
|
|
{
|
|
return $this->validCreditsPresent();
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function message()
|
|
{
|
|
return 'Attempting to use one or more invalid credits';
|
|
}
|
|
|
|
|
|
|
|
private function validCreditsPresent() :bool
|
|
{
|
|
$data = [];
|
|
//todo need to ensure the clients credits are here not random ones!
|
|
|
|
if(request()->input('credits') && is_array(request()->input('credits')))
|
|
{
|
|
foreach(request()->input('credits') as $credit)
|
|
{
|
|
$cred = Credit::find($credit['id']);
|
|
|
|
if($cred->balance >= $credit['amount'])
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
}
|