Create endpoint for canceling subscription
MODIFY
app/Http/Controllers/SettingsController.php
app/Http/Controllers/SettingsController.php
@@ -143,8 +143,33 @@ class SettingsController extends Controller
(new CreateStripeCustomerAction())->execute($user->id);
}
+ $stripeSubscription = (new FetchStripeSubscriptionAction())->execute($user->id);
+
+ if ($stripeSubscription) {
+ return redirect()->route('settings.billing');
+ }
+
$stripeCheckoutId = (new CreateStripeCheckoutAction())->execute($user->id);
return view('stripe_checkout_redirect', ['stripeCheckoutId' => $stripeCheckoutId]);
}
+
+ public function postCancel(Request $request)
+ {
+ $user = $request->user();
+
+ if (!$user->stripe_customer_id) {
+ return redirect()->route('settings.billing');
+ }
+
+ $stripeSubscription = (new FetchStripeSubscriptionAction())->execute($user->id);
+
+ if (!$stripeSubscription) {
+ return redirect()->route('settings.billing');
+ }
+
+ $stripeSubscription->cancel();
+
+ return redirect()->route('settings.billing');
+ }
}

MODIFY
routes/web.php
routes/web.php
@@ -123,6 +123,7 @@ Route::group(['middleware' => ['auth']], function () {
Route::get('/settings/preferences', [SettingsController::class, 'getPreferences'])->name('preferences');
Route::get('/settings/billing', [SettingsController::class, 'getBilling'])->name('billing')->middleware('stripe');
Route::post('/settings/billing/upgrade', [SettingsController::class, 'postUpgrade'])->name('billing.upgrade')->middleware('stripe');
+ Route::post('/settings/billing/cancel', [SettingsController::class, 'postCancel'])->name('billing.cancel')->middleware('stripe');
Route::get('/settings/spaces', [SettingsController::class, 'getSpaces'])->name('spaces.index');
});

Create endpoint for canceling subscription