Skip to content

Commit d15015e

Browse files
committed
Adjustment to routes
1 parent ee5417a commit d15015e

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/ShopifyApp/Traits/AuthControllerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function authenticate(AuthShop $request)
4444
$authHandler = new AuthShopHandler($shopDomain);
4545
$authHandler->storeSession();
4646

47-
if (!isset($request['code'])) {
47+
if (!$request->has('code')) {
4848
// Handle a request without a code, do a fullpage redirect
4949
$authUrl = $authHandler->buildAuthUrl();
5050

src/ShopifyApp/Traits/BillingControllerTrait.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ trait BillingControllerTrait
2121
/**
2222
* Redirects to billing screen for Shopify.
2323
*
24-
* @param \OhMyBrew\ShopifyApp\Models\Plan $billingPlan The plan.
24+
* @param \OhMyBrew\ShopifyApp\Models\Plan|null $plan The plan.
2525
*
2626
* @return \Illuminate\View\View
2727
*/
28-
public function index(Plan $billingPlan)
28+
public function index(Plan $plan = null)
2929
{
30+
// If the plan is null, get a plan
31+
if (is_null($plan)) {
32+
$plan = Plan::where('on_install', true)->first();
33+
}
34+
3035
// Get the confirmation URL
31-
$bp = new BillingPlan(ShopifyApp::shop(), $billingPlan);
36+
$bp = new BillingPlan(ShopifyApp::shop(), $plan);
3237
$url = $bp->confirmationUrl();
3338

3439
// Do a fullpage redirect
@@ -38,23 +43,23 @@ public function index(Plan $billingPlan)
3843
/**
3944
* Processes the response from the customer.
4045
*
41-
* @param \OhMyBrew\ShopifyApp\Models\Plan $billingPlan The plan.
46+
* @param \OhMyBrew\ShopifyApp\Models\Plan $plan The plan.
4247
*
4348
* @return \Illuminate\Http\RedirectResponse
4449
*/
45-
public function process(Plan $billingPlan)
50+
public function process(Plan $plan)
4651
{
4752
// Activate the plan and save
4853
$shop = ShopifyApp::shop();
49-
$bp = new BillingPlan($shop, $billingPlan);
54+
$bp = new BillingPlan($shop, $plan);
5055
$bp->setChargeId(Request::query('charge_id'));
5156
$bp->activate();
5257
$bp->save();
5358

5459
// All good, update the shop's plan and take them off freemium (if applicable)
5560
$shop->update([
5661
'freemium' => false,
57-
'plan_id' => $billingPlan->id,
62+
'plan_id' => $plan->id,
5863
]);
5964

6065
// Go to homepage of app

src/ShopifyApp/resources/routes.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@
1111
|
1212
*/
1313

14-
// Bind the billing plan to an actual plan
15-
Route::bind('billingPlan', function ($value) {
16-
if ($value === null) {
17-
// Find the on-install plan
18-
return Plan::where('on_install', true)->first();
19-
}
20-
21-
// Find the plan passed to the method
22-
return Plan::where('id', $value)->first();
23-
});
24-
2514
Route::group(['middleware' => ['web']], function () {
2615
/*
2716
|--------------------------------------------------------------------------
@@ -80,10 +69,10 @@
8069
*/
8170

8271
Route::get(
83-
'/billing/{billingPlan?}',
72+
'/billing/{plan?}',
8473
'OhMyBrew\ShopifyApp\Controllers\BillingController@index'
8574
)
86-
->where('billingPlan', '^([0-9]+|)$')
75+
->where('plan', '^([0-9]+|)$')
8776
->name('billing');
8877

8978
/*
@@ -96,10 +85,10 @@
9685
*/
9786

9887
Route::get(
99-
'/billing/process/{billingPlan?}',
88+
'/billing/process/{plan?}',
10089
'OhMyBrew\ShopifyApp\Controllers\BillingController@process'
10190
)
102-
->where('billingPlan', '^([0-9]+|)$')
91+
->where('plan', '^([0-9]+|)$')
10392
->name('billing.process');
10493

10594
/*

0 commit comments

Comments
 (0)