diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 44785f06c522..3fbef6812658 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -16,18 +16,6 @@ class VerifyCsrfToken extends BaseVerifier 'complete/*', 'signup/register', 'api/v1/*', - 'api/v1/login', - 'api/v1/clients/*', - 'api/v1/clients', - 'api/v1/invoices/*', - 'api/v1/invoices', - 'api/v1/quotes', - 'api/v1/payments', - 'api/v1/tasks', - 'api/v1/email_invoice', - 'api/v1/hooks', - 'api/v1/users', - 'api/v1/users/*', 'hook/email_opened', 'hook/email_bounced', 'reseller_stats', diff --git a/app/Http/Requests/CreatePaymentAPIRequest.php b/app/Http/Requests/CreatePaymentAPIRequest.php index 115dc11f822c..5c58050e3e38 100644 --- a/app/Http/Requests/CreatePaymentAPIRequest.php +++ b/app/Http/Requests/CreatePaymentAPIRequest.php @@ -1,6 +1,10 @@ req = $req; + } + public function authorize() { return $this->user()->can('create', ENTITY_PAYMENT); @@ -48,4 +58,24 @@ class CreatePaymentAPIRequest extends PaymentRequest return $rules; } + + + public function response(array $errors) + { + /* If the user is not validating from a mobile app - pass through parent::response */ + if(!isset($this->req->api_secret)) + return parent::response($errors); + + /* If the user is validating from a mobile app - pass through first error string and return error */ + foreach($errors as $error) { + foreach ($error as $key => $value) { + + $message['error'] = ['message'=>$value]; + $message = json_encode($message, JSON_PRETTY_PRINT); + $headers = Utils::getApiHeaders(); + + return Response::make($message, 400, $headers); + } + } + } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 53c45252504a..07f89d4ff20a 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -306,7 +306,6 @@ Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function() Route::get('invoices', 'InvoiceApiController@index'); Route::get('download/{invoice_id}', 'InvoiceApiController@download'); Route::resource('invoices', 'InvoiceApiController'); - Route::get('payments', 'PaymentApiController@index'); Route::resource('payments', 'PaymentApiController'); Route::get('tasks', 'TaskApiController@index'); Route::resource('tasks', 'TaskApiController');