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

[2.x] Fix Inertia redirect #11

Merged
merged 1 commit into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "^3.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);
}
}