1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Merge pull request #3886 from turbo124/v2

Refactors
This commit is contained in:
David Bomba 2020-07-06 21:45:05 +10:00 committed by GitHub
commit dd425b6ee0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 467 additions and 404 deletions

View File

@ -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);

View File

@ -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()) {

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -215,6 +215,8 @@ class InvoiceController extends BaseController
event(new InvoiceWasCreated($invoice, $invoice->company));
$invoice = $invoice->service()->triggeredActions($request)->save();
return $this->itemResponse($invoice);
}

View File

@ -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);
}
}

View File

@ -1,12 +1,12 @@
<?php
namespace App\Http\Requests\Subscription;
namespace App\Http\Requests\Webhook;
use App\Utils\Traits\BulkOptions;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\Vendor;
class BulkSubscriptionRequest extends FormRequest
class BulkWebhookRequest extends FormRequest
{
use BulkOptions;

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Subscription;
namespace App\Http\Requests\Webhook;
use App\Http\Requests\Request;
use App\Models\Vendor;
class ShowSubscriptionRequest extends Request
class CreateWebhookRequest extends Request
{
/**
* Determine if the user is authorized to make this request.

View File

@ -9,11 +9,11 @@
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Subscription;
namespace App\Http\Requests\Webhook;
use App\Http\Requests\Request;
class DestroySubscriptionRequest extends Request
class DestroyWebhookRequest extends Request
{
/**

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Subscription;
namespace App\Http\Requests\Webhook;
use App\Http\Requests\Request;
use App\Models\Vendor;
class EditSubscriptionRequest extends Request
class EditWebhookRequest extends Request
{
/**
* Determine if the user is authorized to make this request.

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Subscription;
namespace App\Http\Requests\Webhook;
use App\Http\Requests\Request;
use App\Models\Vendor;
class CreateSubscriptionRequest extends Request
class ShowWebhookRequest extends Request
{
/**
* Determine if the user is authorized to make this request.

View File

@ -9,11 +9,11 @@
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Subscription;
namespace App\Http\Requests\Webhook;
use App\Http\Requests\Request;
class StoreSubscriptionRequest extends Request
class StoreWebhookRequest extends Request
{
/**

View File

@ -9,14 +9,14 @@
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Subscription;
namespace App\Http\Requests\Webhook;
use App\Http\Requests\Request;
use App\Utils\Traits\ChecksEntityStatus;
use App\Utils\Traits\MakesHash;
use Illuminate\Validation\Rule;
class UpdateSubscriptionRequest extends Request
class UpdateWebhookRequest extends Request
{
use MakesHash;
use ChecksEntityStatus;

View File

@ -36,6 +36,8 @@ class VersionCheck implements ShouldQueue
{
$version_file = file_get_contents(config('ninja.version_url'));
info("latest version = {$version_file}");
if ($version_file) {
Account::whereNotNull('id')->update(['latest_version' => $version_file]);
}

View File

@ -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();

View File

@ -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 '<h6><span class="badge badge-secondary">'.ctrans('texts.payment_status_1').'</span></h6>';
break;
case self::STATUS_VOIDED:
case self::STATUS_CANCELLED:
return '<h6><span class="badge badge-warning">'.ctrans('texts.payment_status_2').'</span></h6>';
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));

View File

@ -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;

View File

@ -12,9 +12,9 @@
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 +28,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 +39,7 @@ class ClientObserver
*/
public function updated(Client $client)
{
SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_CLIENT, $client);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CLIENT, $client);
}
/**
@ -50,7 +50,7 @@ class ClientObserver
*/
public function deleted(Client $client)
{
SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_CLIENT, $client);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_CLIENT, $client);
}

View File

@ -11,9 +11,9 @@
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 +25,7 @@ class ExpenseObserver
*/
public function created(Expense $expense)
{
SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_EXPENSE, $expense);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense);
}
/**
@ -36,7 +36,7 @@ class ExpenseObserver
*/
public function updated(Expense $expense)
{
SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_EXPENSE, $expense);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense);
}
/**
@ -47,7 +47,7 @@ class ExpenseObserver
*/
public function deleted(Expense $expense)
{
SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_EXPENSE, $expense);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense);
}
/**

View File

@ -11,9 +11,9 @@
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 +25,7 @@ class InvoiceObserver
*/
public function created(Invoice $invoice)
{
SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_INVOICE, $invoice);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice);
}
/**
@ -36,7 +36,7 @@ class InvoiceObserver
*/
public function updated(Invoice $invoice)
{
SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_INVOICE, $invoice);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice);
}
/**
@ -47,7 +47,7 @@ class InvoiceObserver
*/
public function deleted(Invoice $invoice)
{
SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_INVOICE, $invoice);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice);
}
/**

View File

@ -12,9 +12,9 @@
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 +26,7 @@ class PaymentObserver
*/
public function created(Payment $payment)
{
SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_PAYMENT, $payment);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment);
}
/**
@ -47,7 +47,7 @@ class PaymentObserver
*/
public function deleted(Payment $payment)
{
SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_PAYMENT, $payment);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment);
}
/**

View File

@ -11,9 +11,9 @@
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 +25,7 @@ class QuoteObserver
*/
public function created(Quote $quote)
{
SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_QUOTE, $quote);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote);
}
/**
@ -36,7 +36,7 @@ class QuoteObserver
*/
public function updated(Quote $quote)
{
SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_QUOTE, $quote);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote);
}
/**
@ -47,7 +47,7 @@ class QuoteObserver
*/
public function deleted(Quote $quote)
{
SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_QUOTE, $quote);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote);
}
/**

View File

@ -11,9 +11,9 @@
namespace App\Observers;
use App\Jobs\Util\SubscriptionHandler;
use App\Models\Subscription;
use App\Jobs\Util\WebhookHandler;
use App\Models\Task;
use App\Models\Webhook;
class TaskObserver
{
@ -25,7 +25,7 @@ class TaskObserver
*/
public function created(Task $task)
{
SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_TASK, $task);
WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task);
}
/**
@ -36,7 +36,7 @@ class TaskObserver
*/
public function updated(Task $task)
{
SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_TASK, $task);
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task);
}
/**
@ -47,7 +47,7 @@ class TaskObserver
*/
public function deleted(Task $task)
{
SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_TASK, $task);
WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task);
}
/**

View File

@ -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(
[

View File

@ -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'));
}
}

View File

@ -12,9 +12,9 @@
namespace App\Policies;
/**
* Class SubscriptionPolicy
* Class WebhookPolicy
* @package App\Policies
*/
class SubscriptionPolicy extends EntityPolicy
class WebhookPolicy extends EntityPolicy
{
}

View File

@ -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,

View File

@ -37,7 +37,8 @@ class TokenRepository extends BaseRepository
public function save(array $data, CompanyToken $company_token)
{
$company_token->fill($data);
$company_token->is_system = true;
$company_token->save();
return $company_token;

View File

@ -22,6 +22,7 @@ use App\Services\Invoice\HandleCancellation;
use App\Services\Invoice\HandleReversal;
use App\Services\Invoice\MarkInvoicePaid;
use App\Services\Invoice\MarkSent;
use App\Services\Invoice\TriggeredActions;
use App\Services\Invoice\UpdateBalance;
use Illuminate\Support\Carbon;
@ -136,6 +137,13 @@ class InvoiceService
return $this;
}
public function triggeredActions($request)
{
$this->invoice = (new TriggeredActions($this->invoice, $request))->run();
return $this;
}
public function markViewed()
{
$this->invoice->last_viewed = Carbon::now()->format('Y-m-d H:i');

View File

@ -0,0 +1,80 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Invoice;
use App\Events\Invoice\InvoiceWasEmailed;
use App\Events\Payment\PaymentWasCreated;
use App\Factory\PaymentFactory;
use App\Helpers\Email\InvoiceEmail;
use App\Jobs\Invoice\EmailInvoice;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\Payment;
use App\Services\AbstractService;
use App\Services\Client\ClientService;
use App\Services\Payment\PaymentService;
use App\Utils\Traits\GeneratesCounter;
use Illuminate\Http\Request;
class TriggeredActions extends AbstractService
{
use GeneratesCounter;
private $request;
private $invoice;
public function __construct(Invoice $invoice, Request $request)
{
$this->request = $request;
$this->invoice = $invoice;
}
public function run()
{
//the request may have buried in it additional actions we should automatically perform on the invoice
if($this->request->has('send_email')) {
}
if($this->request->has('auto_bill')) {
}
if($this->request->has('paid')) {
}
return $this->invoice;
}
private function sendEmail()
{
$reminder_template = $this->invoice->calculateTemplate();
$this->invoice->invitations->load('contact.client.country','invoice.client.country','invoice.company')->each(function ($invitation) use($reminder_template){
$email_builder = (new InvoiceEmail())->build($invitation, $reminder_template);
EmailInvoice::dispatch($email_builder, $invitation, $this->invoice->company);
});
if ($this->invoice->invitations->count() > 0) {
event(new InvoiceWasEmailed($this->invoice->invitations->first(), $this->invoice->company));
}
}
}

View File

@ -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;
}

View File

@ -0,0 +1,51 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Quote;
use App\Jobs\Quote\CreateQuotePdf;
use App\Models\ClientContact;
use App\Models\Quote;
use App\Services\AbstractService;
use Illuminate\Support\Facades\Storage;
class GetQuotePdf extends AbstractService
{
public function __construct(Quote $quote, ClientContact $contact = null)
{
$this->quote = $quote;
$this->contact = $contact;
}
public function run()
{
if (!$this->contact) {
$this->contact = $this->quote->client->primary_contact()->first();
}
$invitation = $this->quote->invitations->where('client_contact_id', $this->contact->id)->first();
$path = $this->quote->client->invoice_filepath();
$file_path = $path . $this->quote->number . '.pdf';
$disk = config('filesystems.default');
$file = Storage::disk($disk)->exists($file_path);
if (!$file) {
$file_path = CreateQuotePdf::dispatchNow($invitation);
}
return Storage::disk($disk)->path($file_path);
}
}

View File

@ -16,6 +16,7 @@ use App\Models\Invoice;
use App\Models\Quote;
use App\Repositories\QuoteRepository;
use App\Services\Quote\CreateInvitations;
use App\Services\Quote\GetQuotePdf;
class QuoteService
{
@ -65,9 +66,7 @@ class QuoteService
public function getQuotePdf($contact = null)
{
$get_invoice_pdf = new GetQuotePdf();
return $get_invoice_pdf($this->quote, $contact);
return (new GetQuotePdf($this->quote, $contact))->run();
}
public function sendEmail($contact = null) :QuoteService

View File

@ -42,8 +42,11 @@ class CompanyTokenTransformer extends EntityTransformer
public function transform(CompanyToken $company_token)
{
return [
'id' => $this->encodePrimaryKey($company_token->id),
'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,

View File

@ -1,39 +0,0 @@
<?php
namespace App\Transformers;
use App\Models\Subscription;
use App\Utils\Traits\MakesHash;
class SubscriptionTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [];
/**
* @var array
*/
protected $availableIncludes = [];
/**
* @param Activity $subscription
*
* @return array
*/
public function transform(Subscription $subscription)
{
return [
'id' => (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,
];
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Transformers;
use App\Models\Webhook;
use App\Utils\Traits\MakesHash;
class WebhookTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [];
/**
* @var array
*/
protected $availableIncludes = [];
/**
* @param Activity $webhook
*
* @return array
*/
public function transform(Webhook $webhook)
{
return [
'id' => (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,
];
}
}

54
composer.lock generated
View File

@ -762,16 +762,16 @@
},
{
"name": "czproject/git-php",
"version": "v3.18.0",
"version": "v3.18.1",
"source": {
"type": "git",
"url": "https://github.com/czproject/git-php.git",
"reference": "ed442216a2f981f894ac6ddb1a2091a826f809e6"
"reference": "db664a8d5a1fbfd33e1cdd6ae65bc411bd18dc73"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/czproject/git-php/zipball/ed442216a2f981f894ac6ddb1a2091a826f809e6",
"reference": "ed442216a2f981f894ac6ddb1a2091a826f809e6",
"url": "https://api.github.com/repos/czproject/git-php/zipball/db664a8d5a1fbfd33e1cdd6ae65bc411bd18dc73",
"reference": "db664a8d5a1fbfd33e1cdd6ae65bc411bd18dc73",
"shasum": ""
},
"require": {
@ -800,7 +800,7 @@
"keywords": [
"git"
],
"time": "2020-06-30T14:58:07+00:00"
"time": "2020-07-03T08:02:12+00:00"
},
{
"name": "dacastro4/laravel-gmail",
@ -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"
},
{
@ -3301,16 +3287,16 @@
},
{
"name": "livewire/livewire",
"version": "v1.2.0",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/livewire/livewire.git",
"reference": "874ba1b8d6b12efa472147697942fe2f78a5d371"
"reference": "611327efd235c462badf67e901934866ec01395e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/livewire/livewire/zipball/874ba1b8d6b12efa472147697942fe2f78a5d371",
"reference": "874ba1b8d6b12efa472147697942fe2f78a5d371",
"url": "https://api.github.com/repos/livewire/livewire/zipball/611327efd235c462badf67e901934866ec01395e",
"reference": "611327efd235c462badf67e901934866ec01395e",
"shasum": ""
},
"require": {
@ -3360,7 +3346,7 @@
"type": "github"
}
],
"time": "2020-06-08T15:12:38+00:00"
"time": "2020-07-03T12:45:59+00:00"
},
{
"name": "maennchen/zipstream-php",
@ -3701,16 +3687,16 @@
},
{
"name": "nesbot/carbon",
"version": "2.36.0",
"version": "2.36.1",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "d0b65958d9942fd1b501fdb0800c67e8323aa08d"
"reference": "ee7378a36cc62952100e718bcc58be4c7210e55f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/d0b65958d9942fd1b501fdb0800c67e8323aa08d",
"reference": "d0b65958d9942fd1b501fdb0800c67e8323aa08d",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/ee7378a36cc62952100e718bcc58be4c7210e55f",
"reference": "ee7378a36cc62952100e718bcc58be4c7210e55f",
"shasum": ""
},
"require": {
@ -3786,7 +3772,7 @@
"type": "tidelift"
}
],
"time": "2020-06-25T20:20:01+00:00"
"time": "2020-07-04T12:29:56+00:00"
},
{
"name": "nikic/php-parser",
@ -5662,16 +5648,16 @@
},
{
"name": "sentry/sentry",
"version": "2.4.0",
"version": "2.4.1",
"source": {
"type": "git",
"url": "https://github.com/getsentry/sentry-php.git",
"reference": "e44561875e0d724bac3d9cdb705bf58847acd425"
"reference": "407573e22e6cc46b72cff07c117eeb16bf3a17de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/e44561875e0d724bac3d9cdb705bf58847acd425",
"reference": "e44561875e0d724bac3d9cdb705bf58847acd425",
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/407573e22e6cc46b72cff07c117eeb16bf3a17de",
"reference": "407573e22e6cc46b72cff07c117eeb16bf3a17de",
"shasum": ""
},
"require": {
@ -5755,7 +5741,7 @@
"type": "custom"
}
],
"time": "2020-05-20T20:49:38+00:00"
"time": "2020-07-03T09:58:40+00:00"
},
{
"name": "sentry/sentry-laravel",

View File

@ -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');
}
/**

View File

@ -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.',
];

View File

@ -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');

View File

@ -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();