Adjustments for Stripe Webhooks

This commit is contained in:
David Bomba 2022-05-30 20:05:34 +10:00
parent 83f011d3b0
commit 4b796fe362

View File

@ -41,6 +41,8 @@ class StripeWebhook implements ShouldQueue
public string $company_key; public string $company_key;
private bool $url_found = false;
private array $events = [ private array $events = [
'source.chargeable', 'source.chargeable',
'charge.succeeded', 'charge.succeeded',
@ -64,9 +66,7 @@ class StripeWebhook implements ShouldQueue
$company_gateway = CompanyGateway::find($this->company_gateway_id); $company_gateway = CompanyGateway::find($this->company_gateway_id);
$driver = $company_gateway->driver(); $stripe = $company_gateway->driver()->init();
$stripe = $driver->init();
$endpoints = \Stripe\WebhookEndpoint::all([], $stripe->stripe_connect_auth); $endpoints = \Stripe\WebhookEndpoint::all([], $stripe->stripe_connect_auth);
@ -77,19 +77,22 @@ class StripeWebhook implements ShouldQueue
if($endpoint->url === $webhook_url) if($endpoint->url === $webhook_url)
{ {
\Stripe\WebhookEndpoint::update($endpoint->id, $this->events, $stripe->stripe_connect_auth);
\Stripe\WebhookEndpoint::update($endpoint->id, ['enabled_events' => $this->events], $stripe->stripe_connect_auth);
$this->url_found = true;
} }
} }
/* Add new webhook */ /* Add new webhook */
if(count($endpoints['data'] == 0) if(!$this->url_found)
{ {
\Stripe\WebhookEndpoint::create([ \Stripe\WebhookEndpoint::create([
'url' => $webhook_url, 'url' => $webhook_url,
'enabled_events' => $this->events, 'enabled_events' => $this->events,
], $stripe->stripe_connect_auth) ], $stripe->stripe_connect_auth);
} }
} }