To achieve a single combined subscription with both a fixed-price and a metered (usage-based) price in Stripe using Laravel Cashier, you need to use subscription items. Stripe supports multiple prices per subscription, and each price can have its own billing scheme (recurring or metered).
Here’s how you can set it up in Laravel Cashier:
1. Create the subscription with multiple items
You can use the addPrice and meteredPrice methods when creating a subscription:
use Laravel\Cashier\Cashier;
// Assume $fixedPriceId and $meteredPriceId are the Stripe price IDs
$user->newSubscription('default', $fixedPriceId)
->addPrice($meteredPriceId, [
'quantity' => null, // For metered, Stripe expects null here
'metered' => true, // Indicate that this price is metered
])
->create('pm_card_visa');
2. Report usage for the metered item
For the metered item, you need to report usage to Stripe throughout the billing period:
$user->subscription('default')
->reportUsage($meteredPriceId, $quantity, $timestamp);
$quantity: Number of units used.$timestamp: Unix timestamp of the usage event.
3. Result
This will create a single Stripe subscription with:
- A fixed monthly price (recurring item).
- A usage-based price (metered item).
At the end of each billing period, Stripe will generate one invoice that combines both items.
Example with Cashier's addPrice and metered usage
$user->newSubscription('default', $fixedPriceId)
->addPrice($meteredPriceId)
->create('pm_card_visa');
When you add a metered price, Stripe itself knows (based on the price setup in the dashboard) whether it is metered or fixed, so you don't need to specify 'metered' here—just ensure your Stripe price is properly configured as metered.
Then, just report usage as shown above during the billing period.
Notes:
- Make sure both prices (recurring and metered) are set up in Stripe, with the proper billing scheme.
- Laravel Cashier (as of v13+) supports multiple prices per subscription.
- Check official Cashier docs for any version-specific details.
Summary:
Yes, you can create a single subscription with both fixed and metered pricing using multiple prices on the subscription. Use addPrice() with your recurring and metered prices, and report usage for metered items as needed. Stripe will generate a unified invoice per billing period.