diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index cafec284f086..286a121fe394 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -177,36 +177,44 @@ class DemoMode extends Command $client = $company->clients->random(); $this->info('creating invoice for client #'.$client->id); - $this->createInvoice($client); + + for($y=0; $y<($this->count); $y++){ + $this->info("creating invoice #{$y} for client #".$client->id); + $this->createInvoice($client); + } $client = $company->clients->random(); - $this->info('creating credit for client #'.$client->id); - $this->createCredit($client); + for($y=0; $y<($this->count); $y++){ + $this->info("creating credit #{$y} for client #".$client->id); + $this->createCredit($client); + } $client = $company->clients->random(); - $this->info('creating quote for client #'.$client->id); - $this->createQuote($client); + for($y=0; $y<($this->count); $y++){ + $this->info("creating quote #{$y} for client #".$client->id); + $this->createQuote($client); + } $client = $company->clients->random(); - $this->info('creating expense for client #'.$client->id); + $this->info("creating expense for client #".$client->id); $this->createExpense($client); $client = $company->clients->random(); - $this->info('creating vendor for client #'.$client->id); + $this->info("creating vendor for client #".$client->id); $this->createVendor($client); $client = $company->clients->random(); - $this->info('creating task for client #'.$client->id); + $this->info("creating task for client #".$client->id); $this->createTask($client); $client = $company->clients->random(); - $this->info('creating project for client #'.$client->id); + $this->info("creating project for client #".$client->id); $this->createProject($client); } @@ -307,8 +315,12 @@ class DemoMode extends Command $invoice = InvoiceFactory::create($client->company->id, $client->user->id);//stub the company and user_id $invoice->client_id = $client->id; -// $invoice->date = $faker->date(); - $dateable = Carbon::now()->subDays(rand(0, 90)); + + if((bool)rand(0,1)) + $dateable = Carbon::now()->subDays(rand(0, 90)); + else + $dateable = Carbon::now()->addDays(rand(0, 90)); + $invoice->date = $dateable; $invoice->line_items = $this->buildLineItems(rand(1, 10)); @@ -411,7 +423,13 @@ class DemoMode extends Command //$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id $quote =factory(\App\Models\Quote::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); - $quote->date = $faker->date(); + + if((bool)rand(0,1)) + $dateable = Carbon::now()->subDays(rand(0, 90)); + else + $dateable = Carbon::now()->addDays(rand(0, 90)); + + $quote->date = $dateable; $quote->client_id = $client->id; $quote->setRelation('client', $client); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5327459eb90a..58342ac5c3ed 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -56,7 +56,6 @@ class Kernel extends ConsoleKernel if(Ninja::isHosted()) { $schedule->job(new AdjustEmailQuota())->daily(); $schedule->job(new SendFailedEmails())->daily(); - $schedule->job(new CheckDbStatus())->everyFiveMinutes(); } /* Run queue's in shared hosting with this*/ if (Ninja::isSelfHost()) { diff --git a/app/Factory/SubscriptionFactory.php b/app/Factory/WebhookFactory.php similarity index 51% rename from app/Factory/SubscriptionFactory.php rename to app/Factory/WebhookFactory.php index eb62417bc22c..45b1d1f71b92 100644 --- a/app/Factory/SubscriptionFactory.php +++ b/app/Factory/WebhookFactory.php @@ -11,19 +11,19 @@ namespace App\Factory; -use App\Models\Subscription; +use App\Models\Webhook; -class SubscriptionFactory +class WebhookFactory { - public static function create(int $company_id, int $user_id) :Subscription + public static function create(int $company_id, int $user_id) :Webhook { - $subscription = new Subscription; - $subscription->company_id = $company_id; - $subscription->user_id = $user_id; - $subscription->target_url = ''; - $subscription->event_id = 1; - $subscription->format = 'JSON'; + $webhook = new Webhook; + $webhook->company_id = $company_id; + $webhook->user_id = $user_id; + $webhook->target_url = ''; + $webhook->event_id = 1; + $webhook->format = 'JSON'; - return $subscription; + return $webhook; } } diff --git a/app/Filters/SubscriptionFilters.php b/app/Filters/WebhookFilters.php similarity index 78% rename from app/Filters/SubscriptionFilters.php rename to app/Filters/WebhookFilters.php index 17125707b0b2..8822e334f0a9 100644 --- a/app/Filters/SubscriptionFilters.php +++ b/app/Filters/WebhookFilters.php @@ -11,7 +11,7 @@ namespace App\Filters; -use App\Models\Subscription; +use App\Models\Webhook; use App\Models\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\DB; @@ -20,7 +20,7 @@ use Illuminate\Support\Facades\Gate; /** * TokenFilters */ -class SubscriptionFilters extends QueryFilters +class WebhookFilters extends QueryFilters { /** @@ -38,7 +38,7 @@ class SubscriptionFilters extends QueryFilters } return $this->builder->where(function ($query) use ($filter) { - $query->where('subscriptions.target_url', 'like', '%'.$filter.'%'); + $query->where('webhooks.target_url', 'like', '%'.$filter.'%'); }); } @@ -55,7 +55,7 @@ class SubscriptionFilters extends QueryFilters return $this->builder; } - $table = 'subscriptions'; + $table = 'webhooks'; $filters = explode(',', $filter); return $this->builder->where(function ($query) use ($filters, $table) { @@ -102,19 +102,19 @@ class SubscriptionFilters extends QueryFilters */ public function baseQuery(int $company_id, User $user) : Builder { - $query = DB::table('subscriptions') - ->join('companies', 'companies.id', '=', 'subscriptions.company_id') - ->where('subscriptions.company_id', '=', $company_id) + $query = DB::table('webhooks') + ->join('companies', 'companies.id', '=', 'webhooks.company_id') + ->where('webhooks.company_id', '=', $company_id) //->whereRaw('(designs.name != "" or contacts.first_name != "" or contacts.last_name != "" or contacts.email != "")') // filter out buy now invoices ->select( - 'subscriptions.id', - 'subscriptions.target_url', - 'subscriptions.event_id', - 'subscriptions.created_at', - 'subscriptions.created_at as token_created_at', - 'subscriptions.deleted_at', - 'subscriptions.format', - 'subscriptions.user_id', + 'webhooks.id', + 'webhooks.target_url', + 'webhooks.event_id', + 'webhooks.created_at', + 'webhooks.created_at as token_created_at', + 'webhooks.deleted_at', + 'webhooks.format', + 'webhooks.user_id', ); @@ -122,8 +122,8 @@ class SubscriptionFilters extends QueryFilters * If the user does not have permissions to view all invoices * limit the user to only the invoices they have created */ - if (Gate::denies('view-list', Subscription::class)) { - $query->where('subscriptions.user_id', '=', $user->id); + if (Gate::denies('view-list', Webhook::class)) { + $query->where('webhooks.user_id', '=', $user->id); } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index c2a3e946bef4..e93eda2846fc 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -215,6 +215,8 @@ class InvoiceController extends BaseController event(new InvoiceWasCreated($invoice, $invoice->company)); + $invoice = $invoice->service()->triggeredActions($request)->save(); + return $this->itemResponse($invoice); } diff --git a/app/Http/Controllers/SubscriptionController.php b/app/Http/Controllers/WebhookController.php similarity index 56% rename from app/Http/Controllers/SubscriptionController.php rename to app/Http/Controllers/WebhookController.php index e133d7e547d4..8ae5f6103e4a 100644 --- a/app/Http/Controllers/SubscriptionController.php +++ b/app/Http/Controllers/WebhookController.php @@ -12,27 +12,27 @@ namespace App\Http\Controllers; -use App\Factory\SubscriptionFactory; -use App\Filters\SubscriptionFilters; -use App\Http\Requests\Subscription\CreateSubscriptionRequest; -use App\Http\Requests\Subscription\DestroySubscriptionRequest; -use App\Http\Requests\Subscription\EditSubscriptionRequest; -use App\Http\Requests\Subscription\ShowSubscriptionRequest; -use App\Http\Requests\Subscription\StoreSubscriptionRequest; -use App\Http\Requests\Subscription\UpdateSubscriptionRequest; -use App\Models\Subscription; +use App\Factory\WebhookFactory; +use App\Filters\WebhookFilters; +use App\Http\Requests\Webhook\CreateWebhookRequest; +use App\Http\Requests\Webhook\DestroyWebhookRequest; +use App\Http\Requests\Webhook\EditWebhookRequest; +use App\Http\Requests\Webhook\ShowWebhookRequest; +use App\Http\Requests\Webhook\StoreWebhookRequest; +use App\Http\Requests\Webhook\UpdateWebhookRequest; +use App\Models\Webhook; use App\Repositories\BaseRepository; -use App\Transformers\SubscriptionTransformer; +use App\Transformers\WebhookTransformer; use App\Utils\Traits\MakesHash; use Illuminate\Http\Request; -class SubscriptionController extends BaseController +class WebhookController extends BaseController { use MakesHash; - protected $entity_type = Subscription::class; + protected $entity_type = Webhook::class; - protected $entity_transformer = SubscriptionTransformer::class; + protected $entity_transformer = WebhookTransformer::class; public $base_repo; @@ -45,13 +45,13 @@ class SubscriptionController extends BaseController /** * @OA\Get( - * path="/api/v1/subscriptions", - * operationId="getSubscriptions", - * tags={"subscriptions"}, - * summary="Gets a list of subscriptions", - * description="Lists subscriptions, search and filters allow fine grained lists to be generated. + * path="/api/v1/webhooks", + * operationId="getWebhooks", + * tags={"webhooks"}, + * summary="Gets a list of Webhooks", + * description="Lists Webhooks, search and filters allow fine grained lists to be generated. * - * Query parameters can be added to performed more fine grained filtering of the subscriptions, these are handled by the SubscriptionFilters class which defines the methods available", + * Query parameters can be added to performed more fine grained filtering of the Webhooks, these are handled by the WebhookFilters class which defines the methods available", * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), @@ -59,11 +59,11 @@ class SubscriptionController extends BaseController * @OA\Parameter(ref="#/components/parameters/index"), * @OA\Response( * response=200, - * description="A list of subscriptions", + * description="A list of Webhooks", * @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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -79,11 +79,11 @@ class SubscriptionController extends BaseController * ) * */ - public function index(SubscriptionFilters $filters) + public function index(WebhookFilters $filters) { - $subscriptions = Subscription::filter($filters); + $webhooks = Webhook::filter($filters); - return $this->listResponse($subscriptions); + return $this->listResponse($webhooks); } /** @@ -94,11 +94,11 @@ class SubscriptionController extends BaseController * * * @OA\Get( - * path="/api/v1/subscriptions/{id}", - * operationId="showSubscription", - * tags={"subscriptions"}, - * summary="Shows a subscription", - * description="Displays a subscription by id", + * path="/api/v1/webhooks/{id}", + * operationId="showWebhook", + * tags={"webhooks"}, + * summary="Shows a Webhook", + * description="Displays a Webhook 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"), @@ -106,7 +106,7 @@ class SubscriptionController extends BaseController * @OA\Parameter( * name="id", * in="path", - * description="The Subscription Hashed ID", + * description="The Webhook Hashed ID", * example="D2J234DFA", * required=true, * @OA\Schema( @@ -116,11 +116,11 @@ class SubscriptionController extends BaseController * ), * @OA\Response( * response=200, - * description="Returns the subscription object", + * description="Returns the Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -136,9 +136,9 @@ class SubscriptionController extends BaseController * ) * */ - public function show(ShowSubscriptionRequest $request, Subscription $subscription) + public function show(ShowWebhookRequest $request, Webhook $webhook) { - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** @@ -149,11 +149,11 @@ class SubscriptionController extends BaseController * * * @OA\Get( - * path="/api/v1/subscriptions/{id}/edit", - * operationId="editSubscription", - * tags={"subscriptions"}, - * summary="Shows a subscription for editting", - * description="Displays a subscription by id", + * path="/api/v1/webhooks/{id}/edit", + * operationId="editWebhook", + * tags={"webhooks"}, + * summary="Shows a Webhook for editting", + * description="Displays a Webhook 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"), @@ -161,7 +161,7 @@ class SubscriptionController extends BaseController * @OA\Parameter( * name="id", * in="path", - * description="The Subscription Hashed ID", + * description="The Webhook Hashed ID", * example="D2J234DFA", * required=true, * @OA\Schema( @@ -171,11 +171,11 @@ class SubscriptionController extends BaseController * ), * @OA\Response( * response=200, - * description="Returns the subscription object", + * description="Returns the Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -191,26 +191,26 @@ class SubscriptionController extends BaseController * ) * */ - public function edit(EditSubscriptionRequest $request, Subscription $subscription) + public function edit(EditWebhookRequest $request, Webhook $webhook) { - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param App\Models\Subscription $subscription + * @param App\Models\Webhook $Webhook * @return \Illuminate\Http\Response * * * * @OA\Put( - * path="/api/v1/subscriptions/{id}", - * operationId="updateSubscription", - * tags={"subscriptions"}, - * summary="Updates a subscription", - * description="Handles the updating of a subscription by id", + * path="/api/v1/webhooks/{id}", + * operationId="updateWebhook", + * tags={"webhooks"}, + * summary="Updates a Webhook", + * description="Handles the updating of a Webhook 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"), @@ -218,7 +218,7 @@ class SubscriptionController extends BaseController * @OA\Parameter( * name="id", * in="path", - * description="The Subscription Hashed ID", + * description="The Webhook Hashed ID", * example="D2J234DFA", * required=true, * @OA\Schema( @@ -228,11 +228,11 @@ class SubscriptionController extends BaseController * ), * @OA\Response( * response=200, - * description="Returns the subscription object", + * description="Returns the Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -248,16 +248,16 @@ class SubscriptionController extends BaseController * ) * */ - public function update(UpdateSubscriptionRequest $request, Subscription $subscription) + public function update(UpdateWebhookRequest $request, Webhook $webhook) { - if ($request->entityIsDeleted($subscription)) { + if ($request->entityIsDeleted($webhook)) { return $request->disallowUpdate(); } - $subscription->fill($request->all()); - $subscription->save(); + $webhook->fill($request->all()); + $webhook->save(); - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** @@ -268,10 +268,10 @@ class SubscriptionController extends BaseController * * * @OA\Get( - * path="/api/v1/subscriptions/create", - * operationId="getSubscriptionsCreate", - * tags={"subscriptions"}, - * summary="Gets a new blank subscription object", + * path="/api/v1/webhooks/create", + * operationId="getWebhooksCreate", + * tags={"webhooks"}, + * summary="Gets a new blank Webhook 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"), @@ -279,11 +279,11 @@ class SubscriptionController extends BaseController * @OA\Parameter(ref="#/components/parameters/include"), * @OA\Response( * response=200, - * description="A blank subscription object", + * description="A blank Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -299,13 +299,13 @@ class SubscriptionController extends BaseController * ) * */ - public function create(CreateSubscriptionRequest $request) + public function create(CreateWebhookRequest $request) { - $subscription = SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id); - $subscription->fill($request->all()); - $subscription->save(); + $webhook = WebhookFactory::create(auth()->user()->company()->id, auth()->user()->id); + $webhook->fill($request->all()); + $webhook->save(); - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** @@ -317,22 +317,22 @@ class SubscriptionController extends BaseController * * * @OA\Post( - * path="/api/v1/subscriptions", - * operationId="storeSubscription", - * tags={"subscriptions"}, - * summary="Adds a subscription", - * description="Adds an subscription to a company", + * path="/api/v1/webhooks", + * operationId="storeWebhook", + * tags={"webhooks"}, + * summary="Adds a Webhook", + * description="Adds an Webhook 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 subscription object", + * description="Returns the saved Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -348,13 +348,27 @@ class SubscriptionController extends BaseController * ) * */ - public function store(StoreSubscriptionRequest $request) + public function store(StoreWebhookRequest $request) { - $subscription = SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id); - $subscription->fill($request->all()); - $subscription->save(); + $event_id = $request->input('event_id'); + $target_url = $request->input('target_url'); - return $this->itemResponse($subscription); + if (!in_array($event_id, Webhook::$valid_events)) { + return response()->json("Invalid event", 400); + } + + $webhook = new Webhook; + $webhook->company_id = auth()->user()->company()->id; + $webhook->user_id = auth()->user()->id; + $webhook->event_id = $event_id; + $webhook->target_url = $target_url; + $webhook->save(); + + if (!$webhook->id) { + return response()->json('Failed to create Webhook', 400); + } + + return $this->itemResponse($webhook); } /** @@ -365,11 +379,11 @@ class SubscriptionController extends BaseController * * * @OA\Delete( - * path="/api/v1/subscriptions/{id}", - * operationId="deleteSubscription", - * tags={"subscriptions"}, - * summary="Deletes a subscription", - * description="Handles the deletion of a subscription by id", + * path="/api/v1/Webhooks/{id}", + * operationId="deleteWebhook", + * tags={"Webhooks"}, + * summary="Deletes a Webhook", + * description="Handles the deletion of a Webhook 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"), @@ -377,7 +391,7 @@ class SubscriptionController extends BaseController * @OA\Parameter( * name="id", * in="path", - * description="The Subscription Hashed ID", + * description="The Webhook Hashed ID", * example="D2J234DFA", * required=true, * @OA\Schema( @@ -406,26 +420,26 @@ class SubscriptionController extends BaseController * ) * */ - public function destroy(DestroySubscriptionRequest $request, Subscription $subscription) + public function destroy(DestroyWebhookRequest $request, Webhook $webhook) { //may not need these destroy routes as we are using actions to 'archive/delete' - $subscription->delete(); + $webhook->delete(); - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** * Perform bulk actions on the list view * - * @param BulkSubscriptionRequest $request + * @param BulkWebhookRequest $request * @return \Illuminate\Http\Response * * * @OA\Post( - * path="/api/v1/subscriptions/bulk", - * operationId="bulkSubscriptions", - * tags={"subscriptions"}, - * summary="Performs bulk actions on an array of subscriptions", + * path="/api/v1/webhooks/bulk", + * operationId="bulkWebhooks", + * tags={"webhooks"}, + * summary="Performs bulk actions on an array of Webhooks", * description="", * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), @@ -448,11 +462,11 @@ class SubscriptionController extends BaseController * ), * @OA\Response( * response=200, - * description="The Subscription User response", + * description="The Webhook User response", * @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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -471,129 +485,18 @@ class SubscriptionController extends BaseController $action = request()->input('action'); $ids = request()->input('ids'); - $subscriptions = Subscription::withTrashed()->find($this->transformKeys($ids)); - $subscriptions->each(function ($subscription, $key) use ($action) { - if (auth()->user()->can('edit', $subscription)) { - $this->base_repo->{$action}($subscription); + $webhooks = Webhook::withTrashed()->find($this->transformKeys($ids)); + + + $webhooks->each(function ($webhook, $key) use ($action) { + if (auth()->user()->can('edit', $webhook)) { + $this->base_repo->{$action}($webhook); } }); - return $this->listResponse(Subscription::withTrashed()->whereIn('id', $this->transformKeys($ids))); + return $this->listResponse(Webhook::withTrashed()->whereIn('id', $this->transformKeys($ids))); } - /** - * Store a newly created resource in storage. - * - * @OA\Post( - * path="/api/v1/hooks", - * operationId="storeHook", - * tags={"hooks"}, - * summary="Adds a hook", - * description="Adds a hooks 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 hooks 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/Subscription"), - * ), - * @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 subscribe(StoreSubscriptionRequest $request) - { - $event_id = $request->input('event_id'); - $target_url = $request->input('target_url'); - - if (!in_array($event_id, Subscription::$valid_events)) { - return response()->json("Invalid event", 400); - } - - $subscription = new Subscription; - $subscription->company_id = auth()->user()->company()->id; - $subscription->user_id = auth()->user()->id; - $subscription->event_id = $event_id; - $subscription->target_url = $target_url; - $subscription->save(); - - if (!$subscription->id) { - return response()->json('Failed to create subscription', 400); - } - - return $this->itemResponse($subscription); - } - - /** - * Remove the specified resource from storage. - * - * @param int $id - * @return \Illuminate\Http\Response - * - * - * @OA\Delete( - * path="/api/v1/hooks/{subscription_id}", - * operationId="deleteHook", - * tags={"hooks"}, - * summary="Deletes a hook", - * description="Handles the deletion of a hook 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="subscription_id", - * in="path", - * description="The Subscription 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 unsubscribe(DestroySubscriptionRequest $request, Subscription $subscription) - { - $subscription->delete(); - - return $this->itemResponse($subscription); - } } diff --git a/app/Http/Requests/Subscription/BulkSubscriptionRequest.php b/app/Http/Requests/Webhook/BulkWebhookRequest.php similarity index 90% rename from app/Http/Requests/Subscription/BulkSubscriptionRequest.php rename to app/Http/Requests/Webhook/BulkWebhookRequest.php index 3fc119941ec3..ade367a2d055 100644 --- a/app/Http/Requests/Subscription/BulkSubscriptionRequest.php +++ b/app/Http/Requests/Webhook/BulkWebhookRequest.php @@ -1,12 +1,12 @@ update(['latest_version' => $version_file]); } diff --git a/app/Jobs/Util/SubscriptionHandler.php b/app/Jobs/Util/WebhookHandler.php similarity index 94% rename from app/Jobs/Util/SubscriptionHandler.php rename to app/Jobs/Util/WebhookHandler.php index a35ad135a682..0212fc08a465 100644 --- a/app/Jobs/Util/SubscriptionHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -2,7 +2,6 @@ namespace App\Jobs\Util; -use App\Models\Subscription; use App\Transformers\ArraySerializer; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -12,7 +11,7 @@ use Illuminate\Queue\SerializesModels; use League\Fractal\Manager; use League\Fractal\Resource\Item; -class SubscriptionHandler implements ShouldQueue +class WebhookHandler implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; @@ -45,7 +44,7 @@ class SubscriptionHandler implements ShouldQueue //info("i got past the check"); - $subscriptions = Subscription::where('company_id', $this->entity->company_id) + $subscriptions = \App\Models\Webhook::where('company_id', $this->entity->company_id) ->where('event_id', $this->event_id) ->get(); diff --git a/app/Models/Payment.php b/app/Models/Payment.php index ef94c316da3e..b902d17441bc 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -35,7 +35,7 @@ class Payment extends BaseModel use Refundable; const STATUS_PENDING = 1; - const STATUS_VOIDED = 2; + const STATUS_CANCELLED = 2; const STATUS_FAILED = 3; const STATUS_COMPLETED = 4; const STATUS_PARTIALLY_REFUNDED = 5; @@ -167,7 +167,7 @@ class Payment extends BaseModel case self::STATUS_PENDING: return '