diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index e0e52c7b25b3..48d8fe7daa3f 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -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', diff --git a/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php b/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php index b9a80815faeb..64df6d3abfa6 100644 --- a/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php +++ b/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php @@ -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); } diff --git a/routes/api.php b/routes/api.php index 4c4b07fab02e..74d277181c70 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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'); diff --git a/tests/Feature/Payments/StorePaymentValidationTest.php b/tests/Feature/Payments/StorePaymentValidationTest.php index 08e713da470e..9263283f3aad 100644 --- a/tests/Feature/Payments/StorePaymentValidationTest.php +++ b/tests/Feature/Payments/StorePaymentValidationTest.php @@ -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() {