Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10 from renoki-co/fix/redirect
Browse files Browse the repository at this point in the history
[3.x] Fix Inertia redirect
  • Loading branch information
rennokki authored Apr 6, 2021
2 parents be60605 + d7cb1c7 commit 650b653
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^4.0"
},
"autoload": {
Expand All @@ -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",
Expand Down
15 changes: 6 additions & 9 deletions src/Http/Controllers/Inertia/BillingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,25 +19,22 @@ class BillingController extends Controller
public function portal(Request $request)
{
return $this->getBillingPortalRedirect(
BillingPortal::getBillableFromRequest($request), false
BillingPortal::getBillableFromRequest($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'))
);
}
}
2 changes: 1 addition & 1 deletion tests/BillingPortalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function test_billing_redirect_to_portal()

$this->actingAs($user)
->get(route('billing-portal.portal'))
->assertStatus(302);
->assertStatus(409);
}
}

0 comments on commit 650b653

Please sign in to comment.