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

Mike Swan's avatar

Multiple Subscriptions with Spark

Hi all,

Just have a general question if anyone has worked around Spark to use multiple subscriptions for a user. My pricing structure is essentially a minimum yearly subscription for 25 team members and I'm using Spark for this.

I want to give the option for the user to add team members at an additional cost per team member. I was thinking about creating another database for cashier to look at for the additional team member subscription and then I can just anchor the billing dates to the other subscription. I haven't even attempted this yet so not sure if it will work...just thought I'd ask before messing around.

Hopefully this makes sense. Any suggestions are appreciated. Thanks

0 likes
1 reply
LaryAI's avatar
Level 58

To handle multiple subscriptions with Laravel Spark, you can indeed manage additional subscriptions for users, such as adding team members at an additional cost. Here’s a structured approach to achieve this:

  1. Primary Subscription for Base Plan: This will be your main subscription that covers the minimum yearly subscription for 25 team members.

  2. Additional Subscription for Extra Team Members: This will handle the additional cost per team member.

Step-by-Step Solution

  1. Set Up Primary Subscription: Ensure you have your primary subscription set up in Spark. This will be the base plan for 25 team members.

  2. Create Additional Subscription Logic: You can create a new subscription for additional team members. This can be managed by creating a new plan in Stripe and linking it to your Spark application.

  3. Anchor Billing Dates: To ensure the billing dates are aligned, you can use Stripe’s billing_cycle_anchor parameter when creating the additional subscription.

Example Code

Here’s an example of how you might implement this in your Laravel application:

use Laravel\Cashier\SubscriptionBuilder;
use App\Models\User;

public function addAdditionalTeamMembers(User $user, int $additionalMembers)
{
    // Define the additional team member plan ID from Stripe
    $additionalPlanId = 'plan_additional_team_member';

    // Calculate the total cost for additional members
    $additionalCost = $additionalMembers * config('services.stripe.additional_member_cost');

    // Create or update the additional subscription
    $subscription = $user->newSubscription('additional_team_members', $additionalPlanId)
        ->quantity($additionalMembers)
        ->anchorBillingCycleOn($user->subscription('main')->asStripeSubscription()->current_period_end)
        ->create();

    return $subscription;
}

Explanation

  1. Primary Subscription: Ensure the user has a primary subscription (main) for the base plan.

  2. Additional Subscription:

    • newSubscription('additional_team_members', $additionalPlanId): Creates a new subscription for additional team members.
    • quantity($additionalMembers): Sets the quantity to the number of additional team members.
    • anchorBillingCycleOn($user->subscription('main')->asStripeSubscription()->current_period_end): Aligns the billing cycle of the additional subscription with the primary subscription.
  3. Configuration:

    • config('services.stripe.additional_member_cost'): Fetches the cost per additional team member from the configuration.

Database Considerations

You might want to store the additional team members in a separate table or add a column to your existing subscriptions table to track the number of additional team members.

Conclusion

By following this approach, you can manage multiple subscriptions for a user in Laravel Spark, ensuring that the billing cycles are aligned and additional costs are handled appropriately. This solution leverages Laravel Cashier’s capabilities to manage subscriptions and Stripe’s billing cycle anchor feature to synchronize billing dates.

Please or to participate in this conversation.