Consolidate prediction functionality by merging /api/prediction endpoint into /api/stations response. Move prediction logic from PredictionController into StationController, returning prediction data alongside station results. Replace usePrediction composable with unified useStations that returns {stations, meta, prediction}. Remove PredictionRequest, related tests, and unused Vue components (FuelFinderTest, MapTest, RecommendationTest, StationListTest). Add PredictionFull component and UpsellBanner. Extend NationalFuelPredictionService to include weekly_summary (7-day series, yesterday/today averages, cheapest/priciest days) and oil signal from price_predictions table. Update Home.vue to consume prediction from stations response. Add Plan::resolveCadenceForUser helper and configure Cashier to use custom Subscription model.
50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\PlanTier;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Laravel\Cashier\Checkout;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class BillingController extends Controller
|
|
{
|
|
/**
|
|
* Redirect the user to a Stripe Checkout session for the requested plan + cadence.
|
|
*/
|
|
public function checkout(Request $request, string $tier, string $cadence): Response|RedirectResponse|Checkout
|
|
{
|
|
abort_unless(in_array($tier, [PlanTier::Basic->value, PlanTier::Plus->value, PlanTier::Pro->value], true), 404);
|
|
abort_unless(in_array($cadence, ['monthly', 'annual'], true), 404);
|
|
|
|
$priceId = config("services.stripe.prices.{$tier}.{$cadence}");
|
|
|
|
abort_if(empty($priceId), 404, "No Stripe price configured for {$tier} {$cadence}");
|
|
|
|
return $request->user()
|
|
->newSubscription('default', $priceId)
|
|
->allowPromotionCodes()
|
|
->checkout([
|
|
'success_url' => route('billing.success').'?session_id={CHECKOUT_SESSION_ID}',
|
|
'cancel_url' => route('billing.cancel'),
|
|
]);
|
|
}
|
|
|
|
/** Redirect the user to the Stripe-hosted Customer Billing Portal. */
|
|
public function portal(Request $request): Response|RedirectResponse
|
|
{
|
|
return $request->user()->redirectToBillingPortal(route('dashboard'));
|
|
}
|
|
|
|
public function success(): RedirectResponse
|
|
{
|
|
return redirect()->route('dashboard')->with('status', 'subscription_started');
|
|
}
|
|
|
|
public function cancel(): RedirectResponse
|
|
{
|
|
return redirect()->route('dashboard')->with('status', 'subscription_cancelled');
|
|
}
|
|
}
|