[17.x] Flexible Billing Support for Laravel Cashier#1772
[17.x] Flexible Billing Support for Laravel Cashier#1772Diddyy wants to merge 23 commits intolaravel:developfrom
Conversation
- Introduced 'default_billing_mode' configuration in cashier.php to set the default billing mode for new subscriptions. - Added new migration files for 'subscription_schedules' and 'quotes' tables. - Implemented billing mode management in Subscription, Quote, and their respective builders. - Enhanced CheckoutBuilder to handle billing mode during subscription creation. - Added tests for flexible billing mode functionality in subscriptions and quotes. This update requires Stripe API version 2025-06-30.basil or later for flexible billing features.
- Standardized spacing and formatting in various classes, including CheckoutBuilder, Quote, Subscription, and others. - Removed unnecessary blank lines and ensured consistent use of whitespace. - Added missing newlines at the end of several files to comply with coding standards. - Improved readability and maintainability of the codebase. This commit does not introduce any new features or changes to functionality.
…files - Improved code style by removing unnecessary blank lines and ensuring consistent whitespace usage. - Added missing newlines at the end of several files to comply with coding standards. - Enhanced readability and maintainability of the codebase without introducing new features or functionality.
|
I honestly don't know if I have the appetite for this right now seeing how much code we would be committing to maintaining forever. I will table this for sometime after 16.x release. |
|
I've started using flexible mode together with Cashier for a usage based subscription. One of the things that should be fixed here is that, currently, when removing or swapping a metered price, Cashier sets
We need to check whether You know, in case this MR ever plans to get merged. |
|
Thank you a lot @Diddyy for sharing this PR! |
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
|
@Diddyy I moved this for Additionally, it does seems that flexible billing mode doesn't support quantity, how does this PR handle that? |
Ace! Yeah I think that’s wise. I’d welcome any efforts to handle that however. |
| | | ||
| */ | ||
|
|
||
| 'default_billing_mode' => env('CASHIER_DEFAULT_BILLING_MODE', 'classic'), |
There was a problem hiding this comment.
Not sure if this should be a configuration or something that we configure in a service provider:
Cashier::defaultBillingMode('classic');| */ | ||
| public function up(): void | ||
| { | ||
| Schema::create('quotes', function (Blueprint $table) { |
There was a problem hiding this comment.
There's a high possibility that quotes table might already exists in existing application and this could cause issue.
| * @throws \Stripe\Exception\ApiErrorException | ||
| * @throws \InvalidArgumentException | ||
| */ | ||
| public function migrateBillingMode(array $options = []) |
There was a problem hiding this comment.
maybe migrateToFlexibleBillingMode()
| /** | ||
| * Set the billing mode for the subscription. | ||
| * | ||
| * @param string $type |
There was a problem hiding this comment.
| * @param string $type | |
| * @param 'classic'|'flexible' $type |
Added an Issue #1819 and separate PR #1820 to address just this |
| * | ||
| * @throws \InvalidArgumentException | ||
| */ | ||
| protected function validateFlexibleBillingSupport() |
There was a problem hiding this comment.
| protected function validateFlexibleBillingSupport() | |
| protected function assertFlexibleBillingSupport() |
This PR introduces comprehensive Flexible Billing support to Laravel Cashier, enabling modern usage-based billing models, billing credits, and advanced subscription management that aligns with Stripe's latest Basil API capabilities.
What is Flexible Billing?
Flexible Billing represents the future of subscription commerce, moving beyond traditional fixed-price subscriptions to support:
Flexible Billing Features
1. Usage-Based Billing (
ManagesUsageBillingtrait)2. Billing Credits Management (
ManagesBillingCreditstrait)3. Advanced Subscription Scheduling for Flexible Billing
4. Real-World Flexible Billing Use Cases
This implementation enables modern SaaS pricing models:
Flexible Billing Infrastructure
Enhanced Database Schema for Usage Billing
meter_idandmeter_event_namecolumns tosubscription_itemstablemetadataJSON column tosubscription_schedulestableStripe API Modernization
flexiblevsclassicbilling modesAdvanced Subscription Management
Testing
Breaking Changes
Minor Breaking Changes
Migration to Flexible Billing
Enable Flexible Billing Features
Implement Usage-Based Pricing
Create Flexible Subscriptions
Documentation Updates Needed
Key achievements:
This enables Laravel applications to compete with modern SaaS pricing models and unlock new revenue opportunities through flexible, usage-based billing.
/cc @taylorotwell @driesvints @crynobone