diff --git a/app/Factory/BankIntegrationFactory.php b/app/Factory/BankIntegrationFactory.php new file mode 100644 index 0000000000..df0b1734c0 --- /dev/null +++ b/app/Factory/BankIntegrationFactory.php @@ -0,0 +1,37 @@ +account_id = $account_id; + $bank_integration->user_id = $user_id; + $bank_integration->company_id = $company_id; + + $bank_integration->provider_bank_name = ''; + $bank_integration->bank_account_id = ''; + $bank_integration->bank_account_name = ''; + $bank_integration->bank_account_number = ''; + $bank_integration->bank_account_status = ''; + $bank_integration->bank_account_type = ''; + $bank_integration->balance = 0; + $bank_integration->currency = ''; + + return $bank_integration; + } +} diff --git a/app/Http/Controllers/BankIntegrationController.php b/app/Http/Controllers/BankIntegrationController.php index 108bf98f5b..7c5adfadd4 100644 --- a/app/Http/Controllers/BankIntegrationController.php +++ b/app/Http/Controllers/BankIntegrationController.php @@ -11,20 +11,18 @@ namespace App\Http\Controllers; -use App\Http\Requests\Activity\DownloadHistoricalEntityRequest; -use App\Models\Activity; -use App\Transformers\ActivityTransformer; -use App\Utils\HostedPDF\NinjaPdf; -use App\Utils\Ninja; -use App\Utils\PhantomJS\Phantom; -use App\Utils\Traits\Pdf\PageNumbering; -use App\Utils\Traits\Pdf\PdfMaker; -use Illuminate\Http\JsonResponse; +use App\Factory\BankIntegrationFactory; +use App\Http\Requests\BankIntegration\CreateBankIntegrationRequest; +use App\Http\Requests\BankIntegration\DestroyBankIntegrationRequest; +use App\Http\Requests\BankIntegration\EditBankIntegrationRequest; +use App\Http\Requests\BankIntegration\ShowBankIntegrationRequest; +use App\Http\Requests\BankIntegration\StoreBankIntegrationRequest; +use App\Http\Requests\BankIntegration\UpdateBankIntegrationRequest; +use App\Models\BankIntegration; +use App\Repositories\BankIntegrationRepository; +use App\Transformers\BankIntegrationTransformer; use Illuminate\Http\Request; -use Illuminate\Http\Response; -use Illuminate\Support\Facades\Storage; -use stdClass; -use Symfony\Component\HttpFoundation\StreamedResponse; + class BankIntegrationController extends BaseController { @@ -33,10 +31,387 @@ class BankIntegrationController extends BaseController protected $entity_transformer = BankIntegrationTransformer::class; - public function __construct() + protected $bank_integration_repo; + + public function __construct(BankIntegrationRepository $bank_integration_repo) { parent::__construct(); + + $this->bank_integration_repo = $bank_integration_repo; + } + + /** + * @OA\Get( + * path="/api/v1/bank_integrations", + * operationId="getBankIntegrations", + * tags={"bank_integrations"}, + * summary="Gets a list of bank_integrations", + * description="Lists all bank integrations", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter(ref="#/components/parameters/index"), + * @OA\Parameter( + * name="rows", + * in="query", + * description="The number of bank integrations to return", + * example="50", + * required=false, + * @OA\Schema( + * type="number", + * format="integer", + * ), + * ), + * @OA\Response( + * response=200, + * description="A list of bank integrations", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/BankIntegration"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * @param Request $request + * @return Response|mixed + */ + public function index(Request $request) + { + + $bank_integrations = BankIntegration::query()->company(); + + return $this->listResponse($bank_integrations); + + } + + /** + * Display the specified resource. + * + * @param ShowBankIntegrationRequest $request + * @param BankIntegration $bank_integration + * @return Response + * + * + * @OA\Get( + * path="/api/v1/bank_integrations/{id}", + * operationId="showBankIntegration", + * tags={"bank_integrations"}, + * summary="Shows a bank_integration", + * description="Displays a bank_integration by id", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The BankIntegration Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns the bank_integration object", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/BankIntegration"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + public function show(ShowBankIntegrationRequest $request, BankIntegration $bank_integration) + { + return $this->itemResponse($bank_integration); } + /** + * Show the form for editing the specified resource. + * + * @param EditBankIntegrationRequest $request + * @param BankIntegration $bank_integration + * @return Response + * + * + * @OA\Get( + * path="/api/v1/bank_integrations/{id}/edit", + * operationId="editBankIntegration", + * tags={"bank_integrations"}, + * summary="Shows a bank_integration for editing", + * description="Displays a bank_integration by id", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The BankIntegration Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns the bank_integration object", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/BankIntegration"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + public function edit(EditBankIntegrationRequest $request, BankIntegration $bank_integration) + { + return $this->itemResponse($bank_integration); + } + + /** + * Update the specified resource in storage. + * + * @param UpdateBankIntegrationRequest $request + * @param BankIntegration $bank_integration + * @return Response + * + * + * + * @OA\Put( + * path="/api/v1/bank_integrations/{id}", + * operationId="updateBankIntegration", + * tags={"bank_integrations"}, + * summary="Updates a bank_integration", + * description="Handles the updating of a bank_integration by id", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The BankIntegration Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns the bank_integration object", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/BankIntegration"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + public function update(UpdateBankIntegrationRequest $request, BankIntegration $bank_integration) + { + + //stubs for updating the model + $bank_integration = $this->bank_integration_repo->save($request->all(), $bank_integration); + + return $this->itemResponse($bank_integration->fresh()); + } + + /** + * Show the form for creating a new resource. + * + * @param CreateBankIntegrationRequest $request + * @return Response + * + * + * + * @OA\Get( + * path="/api/v1/bank_integrations/create", + * operationId="getBankIntegrationsCreate", + * tags={"bank_integrations"}, + * summary="Gets a new blank bank_integration object", + * description="Returns a blank object with default values", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Response( + * response=200, + * description="A blank bank_integration object", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/BankIntegration"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + public function create(CreateBankIntegrationRequest $request) + { + $bank_integration = BankIntegrationFactory::create(auth()->user()->company()->id, auth()->user()->id, auth()->user()->account_id); + + return $this->itemResponse($bank_integration); + } + + /** + * Store a newly created resource in storage. + * + * @param StoreBankIntegrationRequest $request + * @return Response + * + * + * + * @OA\Post( + * path="/api/v1/bank_integrations", + * operationId="storeBankIntegration", + * tags={"bank_integrations"}, + * summary="Adds a bank_integration", + * description="Adds an bank_integration to a company", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Response( + * response=200, + * description="Returns the saved bank_integration object", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/BankIntegration"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + public function store(StoreBankIntegrationRequest $request) + { + //stub to store the model + $bank_integration = $this->bank_integration_repo->save($request->all(), BankIntegrationFactory::create(auth()->user()->company()->id, auth()->user()->id, auth()->user()->account_id)); + + return $this->itemResponse($bank_integration); + } + + /** + * Remove the specified resource from storage. + * + * @param DestroyBankIntegrationRequest $request + * @param BankIntegration $bank_integration + * @return Response + * + * + * @throws \Exception + * @OA\Delete( + * path="/api/v1/bank_integrations/{id}", + * operationId="deleteBankIntegration", + * tags={"bank_integrations"}, + * summary="Deletes a bank_integration", + * description="Handles the deletion of a bank_integration by id", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The BankIntegration Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns a HTTP status", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + public function destroy(DestroyBankIntegrationRequest $request, BankIntegration $bank_integration) + { + $this->bank_integration_repo->delete($bank_integration); + + return $this->itemResponse($bank_integration->fresh()); + } } \ No newline at end of file diff --git a/app/Http/Controllers/OpenAPI/BankIntegration.php b/app/Http/Controllers/OpenAPI/BankIntegration.php new file mode 100644 index 0000000000..4731d13e19 --- /dev/null +++ b/app/Http/Controllers/OpenAPI/BankIntegration.php @@ -0,0 +1,18 @@ +user()->can('create', BankIntegration::class); + } +} diff --git a/app/Http/Requests/BankIntegration/DestroyBankIntegrationRequest.php b/app/Http/Requests/BankIntegration/DestroyBankIntegrationRequest.php new file mode 100644 index 0000000000..b2550cd7da --- /dev/null +++ b/app/Http/Requests/BankIntegration/DestroyBankIntegrationRequest.php @@ -0,0 +1,27 @@ +user()->can('edit', $this->bank_integration); + } +} diff --git a/app/Http/Requests/BankIntegration/EditBankIntegrationRequest.php b/app/Http/Requests/BankIntegration/EditBankIntegrationRequest.php new file mode 100644 index 0000000000..6c5b668e4e --- /dev/null +++ b/app/Http/Requests/BankIntegration/EditBankIntegrationRequest.php @@ -0,0 +1,27 @@ +user()->can('edit', $this->bank_integration); + } +} diff --git a/app/Http/Requests/BankIntegration/ShowBankIntegrationRequest.php b/app/Http/Requests/BankIntegration/ShowBankIntegrationRequest.php new file mode 100644 index 0000000000..9d08c25f1f --- /dev/null +++ b/app/Http/Requests/BankIntegration/ShowBankIntegrationRequest.php @@ -0,0 +1,27 @@ +user()->can('view', $this->bank_integration); + } +} diff --git a/app/Http/Requests/BankIntegration/StoreBankIntegrationRequest.php b/app/Http/Requests/BankIntegration/StoreBankIntegrationRequest.php new file mode 100644 index 0000000000..2f1902f43a --- /dev/null +++ b/app/Http/Requests/BankIntegration/StoreBankIntegrationRequest.php @@ -0,0 +1,52 @@ +user()->can('create', BankIntegration::class); + } + + public function rules() + { + + $rules = []; + + return $rules; + } + + public function prepareForValidation() + { + $input = $this->all(); + + $this->replace($input); + } + + public function messages() + { + return []; + } + +} diff --git a/app/Http/Requests/BankIntegration/UpdateBankIntegrationRequest.php b/app/Http/Requests/BankIntegration/UpdateBankIntegrationRequest.php new file mode 100644 index 0000000000..5bb712be11 --- /dev/null +++ b/app/Http/Requests/BankIntegration/UpdateBankIntegrationRequest.php @@ -0,0 +1,51 @@ +user()->can('edit', $this->bank_integration); + } + + public function rules() + { + /* Ensure we have a client name, and that all emails are unique*/ + $rules = []; + + return $rules; + } + + public function messages() + { + return [ ]; + } + + public function prepareForValidation() + { + $input = $this->all(); + + $this->replace($input); + } + +} diff --git a/app/Http/Requests/BankIntegration/UploadBankIntegrationRequest.php b/app/Http/Requests/BankIntegration/UploadBankIntegrationRequest.php new file mode 100644 index 0000000000..b9354432c4 --- /dev/null +++ b/app/Http/Requests/BankIntegration/UploadBankIntegrationRequest.php @@ -0,0 +1,38 @@ +user()->can('edit', $this->bank_integration); + } + + public function rules() + { + $rules = []; + + if ($this->input('documents')) { + $rules['documents'] = 'file|mimes:csv,png,ai,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:2000000'; + } + + return $rules; + } +} diff --git a/app/Policies/BankIntegrationPolicy.php b/app/Policies/BankIntegrationPolicy.php new file mode 100644 index 0000000000..c2dfb135c0 --- /dev/null +++ b/app/Policies/BankIntegrationPolicy.php @@ -0,0 +1,31 @@ +isAdmin(); + } +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 670d21b75d..9f996a513d 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -12,6 +12,7 @@ namespace App\Providers; use App\Models\Activity; +use App\Models\Bank; use App\Models\Client; use App\Models\Company; use App\Models\CompanyGateway; @@ -40,6 +41,7 @@ use App\Models\User; use App\Models\Vendor; use App\Models\Webhook; use App\Policies\ActivityPolicy; +use App\Policies\BankIntegrationPolicy; use App\Policies\ClientPolicy; use App\Policies\CompanyGatewayPolicy; use App\Policies\CompanyPolicy; @@ -79,7 +81,7 @@ class AuthServiceProvider extends ServiceProvider */ protected $policies = [ Activity::class => ActivityPolicy::class, - Subscription::class => SubscriptionPolicy::class, + Bank::class => BankIntegrationPolicy::class, Client::class => ClientPolicy::class, Company::class => CompanyPolicy::class, CompanyToken::class => CompanyTokenPolicy::class, @@ -95,17 +97,18 @@ class AuthServiceProvider extends ServiceProvider PaymentTerm::class => PaymentTermPolicy::class, Product::class => ProductPolicy::class, Project::class => ProjectPolicy::class, + PurchaseOrder::class => PurchaseOrderPolicy::class, Quote::class => QuotePolicy::class, RecurringExpense::class => RecurringExpensePolicy::class, RecurringInvoice::class => RecurringInvoicePolicy::class, RecurringQuote::class => RecurringQuotePolicy::class, - Webhook::class => WebhookPolicy::class, + Subscription::class => SubscriptionPolicy::class, Task::class => TaskPolicy::class, TaskStatus::class => TaskStatusPolicy::class, TaxRate::class => TaxRatePolicy::class, User::class => UserPolicy::class, Vendor::class => VendorPolicy::class, - PurchaseOrder::class => PurchaseOrderPolicy::class, + Webhook::class => WebhookPolicy::class, ]; /** diff --git a/app/Repositories/BankIntegrationRepository.php b/app/Repositories/BankIntegrationRepository.php new file mode 100644 index 0000000000..f3fd21b2ce --- /dev/null +++ b/app/Repositories/BankIntegrationRepository.php @@ -0,0 +1,33 @@ +save(); + + } + +} diff --git a/routes/api.php b/routes/api.php index f5150ec200..423b8934ab 100644 --- a/routes/api.php +++ b/routes/api.php @@ -15,6 +15,7 @@ use App\Http\Controllers\AccountController; use App\Http\Controllers\ActivityController; use App\Http\Controllers\Auth\ForgotPasswordController; use App\Http\Controllers\Auth\LoginController; +use App\Http\Controllers\BankIntegrationController; use App\Http\Controllers\BaseController; use App\Http\Controllers\ChartController; use App\Http\Controllers\ClientController; @@ -106,6 +107,8 @@ Route::group(['middleware' => ['throttle:10,1','api_secret_check','email_db']], Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale'], 'prefix' => 'api/v1', 'as' => 'api.'], function () { Route::put('accounts/{account}', [AccountController::class, 'update'])->name('account.update'); + Route::resource('bank_integrations', BankIntegrationController::class); // name = (clients. index / create / show / update / destroy / edit + Route::post('check_subdomain', [SubdomainController::class, 'index'])->name('check_subdomain'); Route::get('ping', [PingController::class, 'index'])->name('ping'); Route::get('health_check', [PingController::class, 'health'])->name('health_check');