diff --git a/app/PaymentDrivers/Stripe/Jobs/StripeWebhook.php b/app/PaymentDrivers/Stripe/Jobs/StripeWebhook.php new file mode 100644 index 000000000000..6b77bb05f2f9 --- /dev/null +++ b/app/PaymentDrivers/Stripe/Jobs/StripeWebhook.php @@ -0,0 +1,97 @@ +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); + + $driver = $company_gateway->driver(); + + $stripe = $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, $this->events, $stripe->stripe_connect_auth); + } + + } + + /* Add new webhook */ + if(count($endpoints['data'] == 0) + { + + \Stripe\WebhookEndpoint::create([ + 'url' => $webhook_url, + 'enabled_events' => $this->events, + ], $stripe->stripe_connect_auth) + + } + } + +} \ No newline at end of file