company_key = $company_key; $this->company_gateway_id = $company_gateway_id; } public function handle() { MultiDB::findAndSetDbByCompanyKey($this->company_key); $company = Company::where('company_key', $this->company_key)->first(); $company_gateway = CompanyGateway::find($this->company_gateway_id); $stripe = $company_gateway->driver()->init(); $endpoints = \Stripe\WebhookEndpoint::all([], $stripe->stripe_connect_auth); $webhook_url = $company_gateway->webhookUrl(); foreach ($endpoints['data'] as $endpoint) { if ($endpoint->url === $webhook_url) { \Stripe\WebhookEndpoint::update($endpoint->id, ['enabled_events' => $this->events], $stripe->stripe_connect_auth); $this->url_found = true; } } /* Add new webhook */ if (! $this->url_found) { \Stripe\WebhookEndpoint::create([ 'url' => $webhook_url, 'enabled_events' => $this->events, ], $stripe->stripe_connect_auth); } } }