Skip to content

Commit

Permalink
Fix deleting related resources (#91)
Browse files Browse the repository at this point in the history
* Fix issue with nullable billable on events

* Prevent firing of events when billable is deleted

* wip
  • Loading branch information
driesvints authored May 27, 2024
1 parent d5be423 commit 4fca113
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ private function handleSubscriptionUpdated(array $payload): void

$subscription = $subscription->sync($payload['data']['attributes']);

SubscriptionUpdated::dispatch($subscription->billable, $subscription, $payload);
if ($subscription->billable) {
SubscriptionUpdated::dispatch($subscription->billable, $subscription, $payload);
}
}

private function handleSubscriptionCancelled(array $payload): void
Expand All @@ -176,7 +178,9 @@ private function handleSubscriptionCancelled(array $payload): void

$subscription = $subscription->sync($payload['data']['attributes']);

SubscriptionCancelled::dispatch($subscription->billable, $subscription, $payload);
if ($subscription->billable) {
SubscriptionCancelled::dispatch($subscription->billable, $subscription, $payload);
}
}

private function handleSubscriptionResumed(array $payload): void
Expand All @@ -198,7 +202,9 @@ private function handleSubscriptionExpired(array $payload): void

$subscription = $subscription->sync($payload['data']['attributes']);

SubscriptionExpired::dispatch($subscription->billable, $subscription, $payload);
if ($subscription->billable) {
SubscriptionExpired::dispatch($subscription->billable, $subscription, $payload);
}
}

private function handleSubscriptionPaused(array $payload): void
Expand All @@ -225,21 +231,30 @@ private function handleSubscriptionUnpaused(array $payload): void

private function handleSubscriptionPaymentSuccess(array $payload): void
{
if ($subscription = $this->findSubscription($payload['data']['attributes']['subscription_id'])) {
if (
($subscription = $this->findSubscription($payload['data']['attributes']['subscription_id'])) &&
$subscription->billable
) {
SubscriptionPaymentSuccess::dispatch($subscription->billable, $subscription, $payload);
}
}

private function handleSubscriptionPaymentFailed(array $payload): void
{
if ($subscription = $this->findSubscription($payload['data']['attributes']['subscription_id'])) {
if (
($subscription = $this->findSubscription($payload['data']['attributes']['subscription_id'])) &&
$subscription->billable
) {
SubscriptionPaymentFailed::dispatch($subscription->billable, $subscription, $payload);
}
}

private function handleSubscriptionPaymentRecovered(array $payload): void
{
if ($subscription = $this->findSubscription($payload['data']['attributes']['subscription_id'])) {
if (
($subscription = $this->findSubscription($payload['data']['attributes']['subscription_id'])) &&
$subscription->billable
) {
SubscriptionPaymentRecovered::dispatch($subscription->billable, $subscription, $payload);
}
}
Expand Down

0 comments on commit 4fca113

Please sign in to comment.