From e9d4803ba289addae4d52948b7a434ea757152c6 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 6 Apr 2021 11:52:45 +0300 Subject: [PATCH] Fixing redirect to portal --- composer.json | 3 ++- .../Controllers/Inertia/BillingController.php | 15 ++++++--------- tests/BillingPortalTest.php | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 0cc0c82..506294d 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "php": "^7.3|^8.0", "laravel/framework": "^8.23", - "laravel/jetstream": "^1.6|^2.0", + "laravel/jetstream": "^2.3", "renoki-co/cashier-register": "^3.4.0" }, "autoload": { @@ -32,6 +32,7 @@ }, "require-dev": { "claudiodekker/inertia-laravel-testing": "^1.2.0", + "doctrine/dbal": "^2.6|^3.0", "laravel/legacy-factories": "^1.1", "mockery/mockery": "^1.4", "orchestra/database": "^6.0", diff --git a/src/Http/Controllers/Inertia/BillingController.php b/src/Http/Controllers/Inertia/BillingController.php index 1be1c44..4aa6d9b 100644 --- a/src/Http/Controllers/Inertia/BillingController.php +++ b/src/Http/Controllers/Inertia/BillingController.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Redirect; +use Inertia\Inertia; use RenokiCo\BillingPortal\BillingPortal; class BillingController extends Controller @@ -19,7 +19,7 @@ class BillingController extends Controller public function portal(Request $request) { return $this->getBillingPortalRedirect( - BillingPortal::getBillableFromRequest($request), false + BillingPortal::getBillableFromRequest($request) ); } @@ -27,17 +27,14 @@ public function portal(Request $request) * Get the billing portal redirect response. * * @param \Illuminate\Database\Eloquent\Model $model - * @param bool $asResponse * @return Illuminate\Routing\Redirector|\Illuminate\Http\Response */ - protected function getBillingPortalRedirect(Model $user, bool $asResponse = true) + protected function getBillingPortalRedirect(Model $user) { $user->createOrGetStripeCustomer(); - $url = $user->billingPortalUrl(route('billing-portal.subscription.index')); - - return $asResponse - ? response('', 409)->header('X-Inertia-Location', $url) - : Redirect::to($url); + return Inertia::location( + $user->billingPortalUrl(route('billing-portal.subscription.index')) + ); } } diff --git a/tests/BillingPortalTest.php b/tests/BillingPortalTest.php index 616a422..05bcd99 100644 --- a/tests/BillingPortalTest.php +++ b/tests/BillingPortalTest.php @@ -18,6 +18,6 @@ public function test_billing_redirect_to_portal() $this->actingAs($user) ->get(route('billing-portal.portal')) - ->assertStatus(302); + ->assertStatus(409); } }