You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Laravel Cashier实现单个订阅关联同一产品的三个Stripe计划?

Creating a Multi-Plan Subscription with Laravel Cashier

Hey there! Good news—Laravel Cashier does support creating subscriptions with multiple plans (or more accurately, multiple Stripe Price objects, since Stripe now uses Prices as the primary way to define billing tiers). Let me walk you through how to replicate your Stripe SDK functionality using Cashier.

Quick Background

First, make sure you're running a recent version of Cashier (v13+ is ideal, as it aligns with Stripe's current API structure focused on Prices rather than legacy Plans). If you're on an older version, consider updating to take advantage of this feature smoothly.

Replicating Your Stripe SDK Code in Cashier

Your original Stripe SDK code creates a subscription with multiple line items (one per plan). Cashier wraps this logic into a clean, Eloquent-friendly interface. Here's how to do it:

1. Create a New Subscription with Multiple Plans

Use the newSubscription() method on your user model (which should use the Billable trait), and pass an array of Stripe Price IDs as the second argument:

use Illuminate\Support\Facades\Auth;

$user = Auth::user();

// Create a subscription named 'main' with 3 different price plans
$subscription = $user->newSubscription('main', [
    'price_abc123', // Price ID for your first plan
    'price_def456', // Price ID for your second plan
    'price_ghi789'  // Price ID for your third plan
])->create();

Behind the scenes, Cashier translates this array into the items structure that the Stripe SDK expects, just like your original code.

2. Add Plans to an Existing Subscription

If you need to add additional plans to a subscription that's already active, you can use the addItem() method:

// Add a fourth plan to the existing 'main' subscription
$user->subscription('main')->addItem([
    'price' => 'price_jkl012'
]);

3. Include Extra Parameters (Like Metadata, Trial Periods)

You can chain additional methods to set trial periods, metadata, or other Stripe subscription options—just like you would with the raw SDK:

$subscription = $user->newSubscription('main', ['price_abc123', 'price_def456', 'price_ghi789'])
    ->trialDays(14) // Add a 14-day trial
    ->metadata(['subscription_group' => 'premium_bundle']) // Attach custom metadata
    ->create();

Key Notes

  • Use Price IDs, Not Plan IDs: Stripe has moved away from legacy Plan objects in favor of Prices (each Plan can have multiple Prices for different billing frequencies). Cashier is built around this modern approach, so make sure you're passing Price IDs from your Stripe dashboard.
  • Verify Subscription Line Items: After creating the subscription, you can check the Stripe dashboard to confirm all 3 plans are attached as line items to the subscription.

If you run into any issues, double-check that your Cashier version is up to date and that your Price IDs are correctly linked to your Stripe product.

内容的提问来源于stack exchange,提问作者Sjshovan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:42:59