From 4c321d41c35ab7dc28c33cb3aaa419ddbed2820d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 21:22:36 +1000 Subject: [PATCH] Change subscriptions to webhooks --- app/Console/Commands/DemoMode.php | 16 +- ...criptionFactory.php => WebhookFactory.php} | 20 +- ...criptionFilters.php => WebhookFilters.php} | 34 +- ...onController.php => WebhookController.php} | 333 +++++++----------- .../BulkWebhookRequest.php} | 4 +- .../CreateWebhookRequest.php} | 4 +- .../DestroyWebhookRequest.php} | 4 +- .../EditWebhookRequest.php} | 4 +- .../ShowWebhookRequest.php} | 4 +- .../StoreWebhookRequest.php} | 4 +- .../UpdateWebhookRequest.php} | 4 +- ...criptionHandler.php => WebhookHandler.php} | 4 +- app/Models/Payment.php | 8 +- app/Models/{Subscription.php => Webhook.php} | 2 +- app/Observers/ClientObserver.php | 9 +- app/Observers/ExpenseObserver.php | 9 +- app/Observers/InvoiceObserver.php | 9 +- app/Observers/PaymentObserver.php | 7 +- app/Observers/QuoteObserver.php | 9 +- app/Observers/TaskObserver.php | 9 +- .../PayPalExpressPaymentDriver.php | 2 +- app/PaymentDrivers/Stripe/SOFORT.php | 2 +- ...bscriptionPolicy.php => WebhookPolicy.php} | 4 +- app/Providers/AuthServiceProvider.php | 6 +- app/Services/Payment/DeletePayment.php | 4 +- app/Transformers/CompanyTokenTransformer.php | 1 + app/Transformers/SubscriptionTransformer.php | 39 -- app/Transformers/WebhookTransformer.php | 39 ++ composer.lock | 14 - ..._05_084934_company_too_large_attribute.php | 8 + resources/lang/en/texts.php | 3 + routes/api.php | 5 +- ...criptionAPITest.php => WebhookAPITest.php} | 20 +- 33 files changed, 281 insertions(+), 363 deletions(-) rename app/Factory/{SubscriptionFactory.php => WebhookFactory.php} (51%) rename app/Filters/{SubscriptionFilters.php => WebhookFilters.php} (78%) rename app/Http/Controllers/{SubscriptionController.php => WebhookController.php} (56%) rename app/Http/Requests/{Subscription/BulkSubscriptionRequest.php => Webhook/BulkWebhookRequest.php} (90%) rename app/Http/Requests/{Subscription/ShowSubscriptionRequest.php => Webhook/CreateWebhookRequest.php} (85%) rename app/Http/Requests/{Subscription/DestroySubscriptionRequest.php => Webhook/DestroyWebhookRequest.php} (84%) rename app/Http/Requests/{Subscription/EditSubscriptionRequest.php => Webhook/EditWebhookRequest.php} (85%) rename app/Http/Requests/{Subscription/CreateSubscriptionRequest.php => Webhook/ShowWebhookRequest.php} (85%) rename app/Http/Requests/{Subscription/StoreSubscriptionRequest.php => Webhook/StoreWebhookRequest.php} (89%) rename app/Http/Requests/{Subscription/UpdateSubscriptionRequest.php => Webhook/UpdateWebhookRequest.php} (90%) rename app/Jobs/Util/{SubscriptionHandler.php => WebhookHandler.php} (95%) rename app/Models/{Subscription.php => Webhook.php} (97%) rename app/Policies/{SubscriptionPolicy.php => WebhookPolicy.php} (81%) delete mode 100644 app/Transformers/SubscriptionTransformer.php create mode 100644 app/Transformers/WebhookTransformer.php rename tests/Feature/{SubscriptionAPITest.php => WebhookAPITest.php} (82%) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index cafec284f086..c2ac9e0caa4f 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -307,8 +307,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 +415,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/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/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 @@ entity->company_id) + $subscriptions = 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 '
'.ctrans('texts.payment_status_1').'
'; break; - case self::STATUS_VOIDED: + case self::STATUS_CANCELLED: return '
'.ctrans('texts.payment_status_2').'
'; break; case self::STATUS_FAILED: @@ -248,7 +248,7 @@ class Payment extends BaseModel public function isVoided() { - return $this->status_id == self::STATUS_VOIDED; + return $this->status_id == self::STATUS_CANCELLED; } public function isPartiallyRefunded() @@ -274,7 +274,7 @@ class Payment extends BaseModel } $this->refunded = $this->amount; - $this->status_id = self::STATUS_VOIDED; + $this->status_id = self::STATUS_CANCELLED; $this->save(); event(new PaymentWasVoided($this)); diff --git a/app/Models/Subscription.php b/app/Models/Webhook.php similarity index 97% rename from app/Models/Subscription.php rename to app/Models/Webhook.php index 60b29bb72f33..0b4b3a1e39e2 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Webhook.php @@ -14,7 +14,7 @@ namespace App\Models; use App\Models\Filterable; use Illuminate\Database\Eloquent\SoftDeletes; -class Subscription extends BaseModel +class Webhook extends BaseModel { use SoftDeletes; use Filterable; diff --git a/app/Observers/ClientObserver.php b/app/Observers/ClientObserver.php index e4d93ed15807..d602083fc195 100644 --- a/app/Observers/ClientObserver.php +++ b/app/Observers/ClientObserver.php @@ -12,9 +12,10 @@ namespace App\Observers; use App\Events\Client\ClientWasCreated; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Client; use App\Models\Subscription; +use App\Models\Webhook; class ClientObserver { @@ -28,7 +29,7 @@ class ClientObserver { event(new ClientWasCreated($client, $client->company)); - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_CLIENT, $client); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client); } /** @@ -39,7 +40,7 @@ class ClientObserver */ public function updated(Client $client) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_CLIENT, $client); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CLIENT, $client); } /** @@ -50,7 +51,7 @@ class ClientObserver */ public function deleted(Client $client) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_CLIENT, $client); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_CLIENT, $client); } diff --git a/app/Observers/ExpenseObserver.php b/app/Observers/ExpenseObserver.php index 74e9fd1a1365..381f31ababcc 100644 --- a/app/Observers/ExpenseObserver.php +++ b/app/Observers/ExpenseObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Expense; use App\Models\Subscription; +use App\Models\Webhook; class ExpenseObserver { @@ -25,7 +26,7 @@ class ExpenseObserver */ public function created(Expense $expense) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_EXPENSE, $expense); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense); } /** @@ -36,7 +37,7 @@ class ExpenseObserver */ public function updated(Expense $expense) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_EXPENSE, $expense); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense); } /** @@ -47,7 +48,7 @@ class ExpenseObserver */ public function deleted(Expense $expense) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_EXPENSE, $expense); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense); } /** diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index dcd427bfd744..0d0e369ac9aa 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Invoice; use App\Models\Subscription; +use App\Models\Webhook; class InvoiceObserver { @@ -25,7 +26,7 @@ class InvoiceObserver */ public function created(Invoice $invoice) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_INVOICE, $invoice); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice); } /** @@ -36,7 +37,7 @@ class InvoiceObserver */ public function updated(Invoice $invoice) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_INVOICE, $invoice); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice); } /** @@ -47,7 +48,7 @@ class InvoiceObserver */ public function deleted(Invoice $invoice) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_INVOICE, $invoice); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice); } /** diff --git a/app/Observers/PaymentObserver.php b/app/Observers/PaymentObserver.php index 9f8ca335469b..19859359be9f 100644 --- a/app/Observers/PaymentObserver.php +++ b/app/Observers/PaymentObserver.php @@ -12,9 +12,10 @@ namespace App\Observers; use App\Events\Payment\PaymentWasCreated; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Payment; use App\Models\Subscription; +use App\Models\Webhook; class PaymentObserver { @@ -26,7 +27,7 @@ class PaymentObserver */ public function created(Payment $payment) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_PAYMENT, $payment); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment); } /** @@ -47,7 +48,7 @@ class PaymentObserver */ public function deleted(Payment $payment) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_PAYMENT, $payment); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment); } /** diff --git a/app/Observers/QuoteObserver.php b/app/Observers/QuoteObserver.php index 3661d3c20799..44e3fff0d923 100644 --- a/app/Observers/QuoteObserver.php +++ b/app/Observers/QuoteObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Quote; use App\Models\Subscription; +use App\Models\Webhook; class QuoteObserver { @@ -25,7 +26,7 @@ class QuoteObserver */ public function created(Quote $quote) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_QUOTE, $quote); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote); } /** @@ -36,7 +37,7 @@ class QuoteObserver */ public function updated(Quote $quote) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_QUOTE, $quote); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote); } /** @@ -47,7 +48,7 @@ class QuoteObserver */ public function deleted(Quote $quote) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_QUOTE, $quote); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote); } /** diff --git a/app/Observers/TaskObserver.php b/app/Observers/TaskObserver.php index 40b25075a713..fe4d0f3fe7a3 100644 --- a/app/Observers/TaskObserver.php +++ b/app/Observers/TaskObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Subscription; use App\Models\Task; +use App\Models\Webhook; class TaskObserver { @@ -25,7 +26,7 @@ class TaskObserver */ public function created(Task $task) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_TASK, $task); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task); } /** @@ -36,7 +37,7 @@ class TaskObserver */ public function updated(Task $task) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_TASK, $task); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task); } /** @@ -47,7 +48,7 @@ class TaskObserver */ public function deleted(Task $task) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_TASK, $task); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task); } /** diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index e2b8b01f02c2..4440e1911b41 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -131,7 +131,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver $transaction_reference = $response->getTransactionReference() ?: $request->input('token'); if ($response->isCancelled()) { - return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_voided')); + return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_cancelled')); } elseif ($response->isSuccessful()) { SystemLogger::dispatch( [ diff --git a/app/PaymentDrivers/Stripe/SOFORT.php b/app/PaymentDrivers/Stripe/SOFORT.php index fc47742bb495..f2e521f4fdbc 100644 --- a/app/PaymentDrivers/Stripe/SOFORT.php +++ b/app/PaymentDrivers/Stripe/SOFORT.php @@ -102,6 +102,6 @@ class SOFORT public function processUnsuccessfulPayment($state) { - return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_voided')); + return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_cancelled')); } } diff --git a/app/Policies/SubscriptionPolicy.php b/app/Policies/WebhookPolicy.php similarity index 81% rename from app/Policies/SubscriptionPolicy.php rename to app/Policies/WebhookPolicy.php index 65201bbe88f3..11c620ef810e 100644 --- a/app/Policies/SubscriptionPolicy.php +++ b/app/Policies/WebhookPolicy.php @@ -12,9 +12,9 @@ namespace App\Policies; /** - * Class SubscriptionPolicy + * Class WebhookPolicy * @package App\Policies */ -class SubscriptionPolicy extends EntityPolicy +class WebhookPolicy extends EntityPolicy { } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 5996bae84888..6f6909681ce5 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -28,10 +28,10 @@ use App\Models\Product; use App\Models\Quote; use App\Models\RecurringInvoice; use App\Models\RecurringQuote; -use App\Models\Subscription; use App\Models\TaxRate; use App\Models\User; use App\Models\Vendor; +use App\Models\Webhook; use App\Policies\ActivityPolicy; use App\Policies\ClientPolicy; use App\Policies\CompanyGatewayPolicy; @@ -49,10 +49,10 @@ use App\Policies\ProductPolicy; use App\Policies\QuotePolicy; use App\Policies\RecurringInvoicePolicy; use App\Policies\RecurringQuotePolicy; -use App\Policies\SubscriptionPolicy; use App\Policies\TaxRatePolicy; use App\Policies\UserPolicy; use App\Policies\VendorPolicy; +use App\Policies\WebhookPolicy; use Auth; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Gate; @@ -82,7 +82,7 @@ class AuthServiceProvider extends ServiceProvider Quote::class => QuotePolicy::class, RecurringInvoice::class => RecurringInvoicePolicy::class, RecurringQuote::class => RecurringQuotePolicy::class, - Subscription::class => SubscriptionPolicy::class, + Webhook::class => WebhookPolicy::class, TaxRate::class => TaxRatePolicy::class, User::class => UserPolicy::class, Vendor::class => VendorPolicy::class, diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index f4ad8fbb23f2..548237a90980 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -38,7 +38,7 @@ class DeletePayment public function run() { - return $this->setStatus(Payment::STATUS_VOIDED) //sets status of payment + return $this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment ->updateCreditables() //return the credits first ->adjustInvoices() ->updateClient() @@ -109,7 +109,7 @@ class DeletePayment private function setStatus($status) { - $this->payment->status_id = Payment::STATUS_VOIDED; + $this->payment->status_id = Payment::STATUS_CANCELLED; return $this; } diff --git a/app/Transformers/CompanyTokenTransformer.php b/app/Transformers/CompanyTokenTransformer.php index 89eb6b61ee42..cd41378703bc 100644 --- a/app/Transformers/CompanyTokenTransformer.php +++ b/app/Transformers/CompanyTokenTransformer.php @@ -46,6 +46,7 @@ class CompanyTokenTransformer extends EntityTransformer 'user_id' => $this->encodePrimaryKey($company_token->user_id), 'token' => $company_token->token, 'name' => $company_token->name ?: '', + 'is_system' =>(bool)$company_token->is_system, 'updated_at' => (int)$company_token->updated_at, 'archived_at' => (int)$company_token->deleted_at, 'created_at' => (int)$company_token->created_at, diff --git a/app/Transformers/SubscriptionTransformer.php b/app/Transformers/SubscriptionTransformer.php deleted file mode 100644 index b27d8d172db4..000000000000 --- a/app/Transformers/SubscriptionTransformer.php +++ /dev/null @@ -1,39 +0,0 @@ - (string) $this->encodePrimaryKey($subscription->id), - 'company_id' => (string) $this->encodePrimaryKey($subscription->company_id), - 'user_id' => (string) $this->encodePrimaryKey($subscription->user_id), - 'archived_at' => (int)$subscription->deleted_at, - 'updated_at' => (int)$subscription->updated_at, - 'created_at' => (int)$subscription->created_at, - 'is_deleted' => (bool)$subscription->is_deleted, - 'target_url' => $subscription->target_url ? (string) $subscription->target_url : '', - 'event_id' => (string) $subscription->event_id, - 'format' => (string) $subscription->format, - ]; - } -} diff --git a/app/Transformers/WebhookTransformer.php b/app/Transformers/WebhookTransformer.php new file mode 100644 index 000000000000..4ffff6398bd0 --- /dev/null +++ b/app/Transformers/WebhookTransformer.php @@ -0,0 +1,39 @@ + (string) $this->encodePrimaryKey($webhook->id), + 'company_id' => (string) $this->encodePrimaryKey($webhook->company_id), + 'user_id' => (string) $this->encodePrimaryKey($webhook->user_id), + 'archived_at' => (int)$webhook->deleted_at, + 'updated_at' => (int)$webhook->updated_at, + 'created_at' => (int)$webhook->created_at, + 'is_deleted' => (bool)$webhook->is_deleted, + 'target_url' => $webhook->target_url ? (string) $webhook->target_url : '', + 'event_id' => (string) $webhook->event_id, + 'format' => (string) $webhook->format, + ]; + } +} diff --git a/composer.lock b/composer.lock index 65cde2fc85f5..6b23f442e8d9 100644 --- a/composer.lock +++ b/composer.lock @@ -1089,20 +1089,6 @@ "sqlserver", "sqlsrv" ], - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal", - "type": "tidelift" - } - ], "time": "2020-04-20T17:19:26+00:00" }, { diff --git a/database/migrations/2020_07_05_084934_company_too_large_attribute.php b/database/migrations/2020_07_05_084934_company_too_large_attribute.php index a87cdbec2fa0..7086b7139ce2 100644 --- a/database/migrations/2020_07_05_084934_company_too_large_attribute.php +++ b/database/migrations/2020_07_05_084934_company_too_large_attribute.php @@ -13,9 +13,17 @@ class CompanyTooLargeAttribute extends Migration */ public function up() { + Schema::table('companies', function (Blueprint $table) { $table->boolean('is_large')->default(0); }); + + Schema::table('company_tokens', function (Blueprint $table) { + $table->boolean('is_system')->default(0); + }); + + Schema::rename('subscriptions', 'webhooks'); + } /** diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index d3367910f1b4..1edee92a325d 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3234,6 +3234,9 @@ return [ 'enable_only_for_development' => 'Enable only for development', 'test_pdf' => 'Test PDF', + 'status_cancelled' => 'Cancelled', 'checkout_authorize_label' => 'Checkout.com can be can saved as payment method for future use, once you complete your first transaction. Don\'t forget to check "Save card" during payment process.', + + ]; diff --git a/routes/api.php b/routes/api.php index ee263086ff99..650d953553d1 100644 --- a/routes/api.php +++ b/routes/api.php @@ -135,8 +135,9 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a /*Subscription and Webhook routes */ Route::post('hooks', 'SubscriptionController@subscribe')->name('hooks.subscribe'); Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe'); - Route::resource('subscriptions', 'SubscriptionController'); - Route::post('subscriptions/bulk', 'SubscriptionController@bulk')->name('subscriptions.bulk'); + + Route::resource('webhooks', 'WebhookController'); + Route::post('webhooks/bulk', 'WebhookController@bulk')->name('webhooks.bulk'); /*Company Ledger */ Route::get('company_ledger', 'CompanyLedgerController@index')->name('company_ledger.index'); diff --git a/tests/Feature/SubscriptionAPITest.php b/tests/Feature/WebhookAPITest.php similarity index 82% rename from tests/Feature/SubscriptionAPITest.php rename to tests/Feature/WebhookAPITest.php index c52b9b228ea1..128f4752bfa1 100644 --- a/tests/Feature/SubscriptionAPITest.php +++ b/tests/Feature/WebhookAPITest.php @@ -15,10 +15,10 @@ use Tests\TestCase; /** * @test - * @covers App\Http\Controllers\SubscriptionController + * @covers App\Http\Controllers\WebhookController */ -class SubscriptionAPITest extends TestCase +class WebhookAPITest extends TestCase { use MakesHash; use DatabaseTransactions; @@ -41,17 +41,17 @@ class SubscriptionAPITest extends TestCase $this->withoutExceptionHandling(); } - public function testSubscriptionGetRoute() + public function testWebhookGetRoute() { $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->get('/api/v1/subscriptions'); + ])->get('/api/v1/webhooks'); $response->assertStatus(200); } - public function testSubscriptionPostRoute() + public function testWebhookPostRoute() { $data = [ 'target_url' => 'http://hook.com', @@ -62,7 +62,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->post('/api/v1/subscriptions', $data); + ])->post('/api/v1/webhooks', $data); $response->assertStatus(200); @@ -77,7 +77,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->put('/api/v1/subscriptions/'.$arr['data']['id'], $data); + ])->put('/api/v1/webhooks/'.$arr['data']['id'], $data); $response->assertStatus(200); @@ -88,7 +88,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->delete('/api/v1/subscriptions/'.$arr['data']['id']); + ])->delete('/api/v1/webhooks/'.$arr['data']['id']); $arr = $response->json(); @@ -103,7 +103,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token - ])->post('/api/v1/subscriptions/bulk?action=restore', $data); + ])->post('/api/v1/webhooks/bulk?action=restore', $data); $arr = $response->json(); @@ -113,7 +113,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token - ])->post('/api/v1/subscriptions/bulk?action=delete', $data); + ])->post('/api/v1/webhooks/bulk?action=delete', $data); $arr = $response->json();