remove branding for subscribed users (#424)
* removebrandingfor subscribed users * backend changes, test * fix test name * fix disable branding * Fix linting --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
26
app/Events/SubscriptionCreated.php
Normal file
26
app/Events/SubscriptionCreated.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Billing\Subscription;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SubscriptionCreated
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithSockets;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct(public Subscription $subscription)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
26
app/Listeners/HandleSubscriptionCreated.php
Normal file
26
app/Listeners/HandleSubscriptionCreated.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\SubscriptionCreated;
|
||||
|
||||
class HandleSubscriptionCreated
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function handle(SubscriptionCreated $event)
|
||||
{
|
||||
$user = $event->subscription->user;
|
||||
|
||||
// Remove branding
|
||||
$user->workspaces()->with('forms')->get()->each(function ($workspace) {
|
||||
$workspace->forms()->update(['no_branding' => true]);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Billing;
|
||||
|
||||
use App\Events\SubscriptionCreated;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Laravel\Cashier\Subscription as CashierSubscription;
|
||||
|
||||
@@ -9,6 +10,10 @@ class Subscription extends CashierSubscription
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $dispatchesEvents = [
|
||||
'created' => SubscriptionCreated::class,
|
||||
];
|
||||
|
||||
public static function booted(): void
|
||||
{
|
||||
static::saved(function (Subscription $sub) {
|
||||
|
||||
@@ -5,9 +5,11 @@ namespace App\Providers;
|
||||
use App\Events\Forms\FormSubmitted;
|
||||
use App\Events\Models\FormCreated;
|
||||
use App\Events\Models\FormIntegrationsEventCreated;
|
||||
use App\Events\SubscriptionCreated;
|
||||
use App\Listeners\Forms\FormCreationConfirmation;
|
||||
use App\Listeners\Forms\FormIntegrationsEventListener;
|
||||
use App\Listeners\Forms\NotifyFormSubmission;
|
||||
use App\Listeners\HandleSubscriptionCreated;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
@@ -32,6 +34,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
FormIntegrationsEventCreated::class => [
|
||||
FormIntegrationsEventListener::class,
|
||||
],
|
||||
SubscriptionCreated::class => [
|
||||
HandleSubscriptionCreated::class
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user