mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
commit
93cc575148
@ -74,6 +74,9 @@ class StorePaymentRequest extends Request
|
||||
}
|
||||
}
|
||||
|
||||
// if (array_key_exists('amount', $input))
|
||||
// $input['amount'] = 0;
|
||||
|
||||
if (isset($input['credits']) && is_array($input['credits']) === false) {
|
||||
$input['credits'] = null;
|
||||
}
|
||||
@ -94,8 +97,7 @@ class StorePaymentRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'amount' => 'sometimes|numeric',
|
||||
'amount' => [new PaymentAmountsBalanceRule(), new ValidCreditsPresentRule()],
|
||||
'amount' => ['numeric', 'bail', new PaymentAmountsBalanceRule(), new ValidCreditsPresentRule()],
|
||||
'client_id' => 'bail|required|exists:clients,id',
|
||||
'invoices.*.invoice_id' => 'bail|required|distinct|exists:invoices,id',
|
||||
'invoices.*.amount' => 'bail|required',
|
||||
|
@ -71,14 +71,14 @@ class ClientLedgerBalanceUpdate implements ShouldQueue
|
||||
|
||||
}
|
||||
|
||||
nlog("Updating Balance NOW");
|
||||
// nlog("Updating Balance NOW");
|
||||
|
||||
$company_ledger->balance = $last_record->balance + $company_ledger->adjustment;
|
||||
$company_ledger->save();
|
||||
|
||||
});
|
||||
|
||||
nlog("Updating company ledger for client ". $this->client->id);
|
||||
// nlog("Updating company ledger for client ". $this->client->id);
|
||||
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ Route::group(['middleware' => ['throttle:100,1', 'api_db', 'token_auth', 'locale
|
||||
Route::post('recurring_quotes/bulk', 'RecurringQuoteController@bulk')->name('recurring_quotes.bulk');
|
||||
Route::put('recurring_quotes/{recurring_quote}/upload', 'RecurringQuoteController@upload');
|
||||
|
||||
Route::post('refresh', 'Auth\LoginController@refresh')->middleware('throttle:50,1');
|
||||
Route::post('refresh', 'Auth\LoginController@refresh')->middleware('throttle:150,3');
|
||||
|
||||
Route::post('reports/clients', 'Reports\ClientReportController');
|
||||
Route::post('reports/contacts', 'Reports\ClientContactReportController');
|
||||
|
@ -61,6 +61,77 @@ class StorePaymentValidationTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testNumericParse()
|
||||
{
|
||||
$this->assertFalse(is_numeric("2760.0,139.14"));
|
||||
}
|
||||
|
||||
|
||||
public function testNoAmountGiven()
|
||||
{
|
||||
|
||||
$data = [
|
||||
// 'amount' => 0,
|
||||
'client_id' => $this->client->hashed_id,
|
||||
'invoices' => [
|
||||
[
|
||||
'invoice_id' => $this->invoice->hashed_id,
|
||||
'amount' => 10,
|
||||
],
|
||||
],
|
||||
'credits' => [
|
||||
[
|
||||
'credit_id' => $this->credit->hashed_id,
|
||||
'amount' => 5
|
||||
]
|
||||
],
|
||||
'date' => '2019/12/12',
|
||||
];
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($e->validator->getMessageBag());
|
||||
}
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testInValidPaymentAmount()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'amount' => "10,33",
|
||||
'client_id' => $this->client->hashed_id,
|
||||
'invoices' => [
|
||||
],
|
||||
'date' => '2019/12/12',
|
||||
];
|
||||
|
||||
$response = false;
|
||||
|
||||
try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/payments/', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($e->validator->getMessageBag());
|
||||
}
|
||||
|
||||
$response->assertStatus(302);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testValidPayment()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user