Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wearecontrast's avatar

Subscribe to Free plan in Stripe

Hey,

I'm trying to get Spark to subscribe a User to a free plan in Stripe.

Here's my SparkServiceProvider::booted

Spark::useStripe();

Spark::plan('Basic', 'basic-yearly')->yearly();
Spark::plan('Pro', 'pro-yearly')->price(19)->yearly();

By default, Spark only subscribes the user in Stripe if the plan has a price greater than 0.

I'm trying to figure out what events/classes i need to hook into/override so that when a user signs up (with no credit card) on the free plan, they are created as a customer in Stripe, and then subscribed to the basic-yearly plan.

I'm still in the process of looking through all the Spark classes to try and figure it out myself, but i thought i'd throw it out here in case anyone has already tried this.

Thanks

0 likes
4 replies
MikeHopley's avatar

Stripe doesn't have a concept of a customer with no funding source -- as in, I don't think they will allow you to create one!

Think about it for a moment. What does a "free plan without card" actually mean? Surely it's exactly the same as just registering a user on your site. You don't need Stripe / Spark for this.

wearecontrast's avatar

Thanks for the reply @MikeHopley

I just double checked, and it is possible to create a customer in Stripe without having a card. I understand what you are getting at though.

The reason i'm looking to do this is so that external services i have that hook into the data in Stripe can also see users that aren't paying me anything, but are still using my service.

I know of other people that are putting free users in Stripe, but they're not using Spark.

Any help would be greatly appreacted

MikeHopley's avatar

The reason i'm looking to do this is so that external services i have that hook into the data in Stripe can also see users that aren't paying me anything, but are still using my service.

Ah okay, that makes sense.

Sorry I can't help here, as I'm not familiar with Spark. Good luck!

wearecontrast's avatar

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.

Please or to participate in this conversation.