I'm not sure if this is the best way to do it, but i've managed to get it working at least. I'll note down what i've done just in case someone comes across this is the future.
Create app\Listeners\SubscribeToFreePlanIfNoPlanActive.php
<?php
namespace App\Listeners;
use Laravel\Spark\Spark;
use Laravel\Spark\Events\Auth\UserRegistered;
class SubscribeToFreePlanIfNoPlanActive
{
/**
* Handle the event.
*
* @param UserRegistered $event
* @return void
*/
public function handle(UserRegistered $event)
{
if(!$event->user->subscribed()){
$plan = Spark::activePlans()->where('name', 'Basic')->first();
$event->user->newSubscription('default', $plan->id)->create();
}
}
}
Update app\Providers\EventServiceProvider.php
//...
protected $listen = [
// User Related Events...
'Laravel\Spark\Events\Auth\UserRegistered' => [
'Laravel\Spark\Listeners\Subscription\CreateTrialEndingNotification',
\App\Listeners\SubscribeToFreePlanIfNoPlanActive::class,
],
//...
When a user registers, if they are not on a paid plan it will subscribe them to the free basic plan, which will create the customer in stripe and subscribe them to the stripe plan as well.
I'm not sure if this is going to work in the long run, but its what i've got at the moment.