* Make Stripe Checkout configurable via billing env knobs Replace the hard-required $1 first-month coupon with env-driven trial days, optional coupon, and allow_promotion_codes so SaaS can switch checkout modes without a code change. Co-authored-by: Cursor <cursoragent@cursor.com> * Fix no-effect ReflectionClass import in checkout test CI treats bare global use statements as ErrorException and aborts loading the suite before any assertions run. Co-authored-by: Cursor <cursoragent@cursor.com> * Document checkout env knobs in AGENTS.md instead of .ai/ Remove the Boost record-rule .ai/rules folder and keep durable billing checkout guidance in AGENTS.md / CLAUDE.md project-specific rules. Co-authored-by: Cursor <cursoragent@cursor.com> * Harden checkout env knobs from review findings Default allow_promotion_codes to false, grant Stripe trial only to first-time subscribers, clarify the coupon/promo XOR error, and cover negative XOR cases plus StartSubscriptionCheckout wiring. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Billing;
|
|
|
|
use App\Models\Account;
|
|
use App\Support\Billing\ConfigureSubscriptionCheckout;
|
|
use Inertia\Inertia;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class StartSubscriptionCheckout
|
|
{
|
|
/**
|
|
* Create a Stripe Checkout session for the given price and return an Inertia
|
|
* redirect to it. Quantity tracks the account's workspace count. Trial days,
|
|
* optional first-month coupon, and promotion codes come from cashier /
|
|
* trypost billing env config via ConfigureSubscriptionCheckout.
|
|
*/
|
|
public function redirect(Account $account, string $priceId, string $cancelUrl): Response
|
|
{
|
|
$account->createOrGetStripeCustomer([
|
|
'email' => $account->stripeEmail(),
|
|
'name' => $account->stripeName(),
|
|
]);
|
|
|
|
$subscription = $account->newSubscription(Account::SUBSCRIPTION_NAME, $priceId)
|
|
->quantity(max(1, $account->workspaces()->count()));
|
|
|
|
ConfigureSubscriptionCheckout::apply($subscription, $account);
|
|
|
|
$session = $subscription->checkout([
|
|
'success_url' => route('app.billing.processing').'?session_id={CHECKOUT_SESSION_ID}',
|
|
'cancel_url' => $cancelUrl,
|
|
]);
|
|
|
|
return Inertia::location($session->url);
|
|
}
|
|
}
|