Merge pull request #7489 from turbo124/v5-develop

Adjustments for Stripe Webhooks
This commit is contained in:
David Bomba 2022-05-31 07:40:52 +10:00 committed by GitHub
commit 978884f2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -23,6 +23,7 @@ use App\Http\Requests\CompanyGateway\UpdateCompanyGatewayRequest;
use App\Jobs\Util\ApplePayDomain;
use App\Models\Client;
use App\Models\CompanyGateway;
use App\PaymentDrivers\Stripe\Jobs\StripeWebhook;
use App\Repositories\CompanyRepository;
use App\Transformers\CompanyGatewayTransformer;
use App\Utils\Traits\MakesHash;
@ -212,6 +213,11 @@ class CompanyGatewayController extends BaseController
ApplePayDomain::dispatch($company_gateway, $company_gateway->company->db);
if(in_array($company_gateway->gateway_key, $this->stripe_keys))
{
StripeWebhook::dispatch($company_gateway->company->company_key, $company_gateway->id);
}
return $this->itemResponse($company_gateway);
}

View File

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