Skip to content

Commit f4c6273

Browse files
author
Tyler King
authored
ITP route (potential) route fix (gnikyt#678)
1 parent 0cb0934 commit f4c6273

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

src/ShopifyApp/resources/routes/shopify.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
$manualRoutes = explode(',', $manualRoutes);
2222
}
2323

24+
// Route which require ITP checks
2425
Route::group(['prefix' => getShopifyConfig('prefix'), 'middleware' => ['itp', 'web']], function () use ($manualRoutes) {
2526
/*
2627
|--------------------------------------------------------------------------
@@ -41,6 +42,28 @@
4142
->name(getShopifyConfig('route_names.home'));
4243
}
4344

45+
/*
46+
|--------------------------------------------------------------------------
47+
| ITP
48+
|--------------------------------------------------------------------------
49+
|
50+
| Handles ITP and issues with it.
51+
|
52+
*/
53+
54+
if (registerPackageRoute('itp', $manualRoutes)) {
55+
Route::get('/itp', 'Osiset\ShopifyApp\Http\Controllers\ItpController@attempt')
56+
->name(getShopifyConfig('route_names.itp'));
57+
}
58+
59+
if (registerPackageRoute('itp.ask', $manualRoutes)) {
60+
Route::get('/itp/ask', 'Osiset\ShopifyApp\Http\Controllers\ItpController@ask')
61+
->name(getShopifyConfig('route_names.itp.ask'));
62+
}
63+
});
64+
65+
// Routes without ITP checks
66+
Route::group(['prefix' => getShopifyConfig('prefix'), 'middleware' => ['web']], function () use ($manualRoutes) {
4467
/*
4568
|--------------------------------------------------------------------------
4669
| Authenticate Method
@@ -132,23 +155,4 @@
132155
->middleware(['auth.shopify'])
133156
->name(getShopifyConfig('route_names.billing.usage_charge'));
134157
}
135-
136-
/*
137-
|--------------------------------------------------------------------------
138-
| ITP
139-
|--------------------------------------------------------------------------
140-
|
141-
| Handles ITP and issues with it.
142-
|
143-
*/
144-
145-
if (registerPackageRoute('itp', $manualRoutes)) {
146-
Route::get('/itp', 'Osiset\ShopifyApp\Http\Controllers\ItpController@attempt')
147-
->name(getShopifyConfig('route_names.itp'));
148-
}
149-
150-
if (registerPackageRoute('itp.ask', $manualRoutes)) {
151-
Route::get('/itp/ask', 'Osiset\ShopifyApp\Http\Controllers\ItpController@ask')
152-
->name(getShopifyConfig('route_names.itp.ask'));
153-
}
154158
});

tests/Traits/AuthControllerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function setUp(): void
2727
public function testAuthRedirectsToShopifyWhenNoCode(): void
2828
{
2929
// Run the request
30-
$response = $this->call('post', '/authenticate', ['shop' => 'example.myshopify.com'], ['itp' => true]);
30+
$response = $this->call('post', '/authenticate', ['shop' => 'example.myshopify.com']);
3131

3232
// Check the view
3333
$response->assertViewHas('shopDomain', 'example.myshopify.com');
@@ -51,7 +51,7 @@ public function testAuthAcceptsShopWithCode(): void
5151
'timestamp' => '1337178173',
5252
];
5353

54-
$response = $this->call('get', '/authenticate', $hmacParams, ['itp' => true]);
54+
$response = $this->call('get', '/authenticate', $hmacParams);
5555
$response->assertRedirect();
5656
}
5757

@@ -67,7 +67,7 @@ public function testAuthThrowExceptionForBadHmac(): void
6767
'timestamp' => '1337178173',
6868
];
6969

70-
$response = $this->call('get', '/authenticate', $hmacParams, ['itp' => true]);
70+
$response = $this->call('get', '/authenticate', $hmacParams);
7171
$response->assertStatus(500);
7272
}
7373

@@ -88,14 +88,14 @@ public function testReturnToMethod(): void
8888
'timestamp' => '1337178173',
8989
];
9090

91-
$response = $this->call('get', '/authenticate', $hmacParams, ['itp' => true]);
91+
$response = $this->call('get', '/authenticate', $hmacParams);
9292
$response->assertRedirect('http://localhost/orders');
9393
}
9494

9595
public function testOauthRedirect(): void
9696
{
9797
// Run the request
98-
$response = $this->call('get', '/authenticate/oauth', ['shop' => 'example.myshopify.com'], ['itp' => true]);
98+
$response = $this->call('get', '/authenticate/oauth', ['shop' => 'example.myshopify.com']);
9999
$response->assertViewHas(
100100
'authUrl',
101101
'https://example.myshopify.com/admin/oauth/authorize?client_id='.env('SHOPIFY_API_KEY').'&scope=read_products%2Cwrite_products&redirect_uri=https%3A%2F%2Flocalhost%2Fauthenticate'

tests/Traits/BillingControllerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testSendsShopToBillingScreen(): void
4343
factory(Plan::class)->states('type_recurring', 'installable')->create();
4444

4545
// Run the call
46-
$response = $this->call('get', '/billing', [], ['itp' => true]);
46+
$response = $this->call('get', '/billing', []);
4747
$response->assertViewHas(
4848
'url',
4949
'https://example.myshopify.com/admin/charges/1029266947/confirm_recurring_application_charge?signature=BAhpBANeWT0%3D--64de8739eb1e63a8f848382bb757b20343eb414f'
@@ -66,7 +66,7 @@ public function testShopAcceptsBilling(): void
6666
$plan = factory(Plan::class)->states('type_recurring')->create();
6767

6868
// Run the call
69-
$response = $this->call('get', "/billing/process/{$plan->id}", ['charge_id' => 1], ['itp' => true]);
69+
$response = $this->call('get', "/billing/process/{$plan->id}", ['charge_id' => 1]);
7070

7171
// Refresh the model
7272
$shop->refresh();
@@ -103,7 +103,7 @@ public function testUsageChargeSuccess(): void
103103
$signature = createHmac(['data' => $data, 'buildQuery' => true], $secret);
104104

105105
// Run the call
106-
$response = $this->call('post', '/billing/usage-charge', array_merge($data, ['signature' => $signature]), ['itp' => true]);
106+
$response = $this->call('post', '/billing/usage-charge', array_merge($data, ['signature' => $signature]));
107107
$response->assertRedirect($data['redirect']);
108108
$response->assertSessionHas('success');
109109

@@ -112,7 +112,7 @@ public function testUsageChargeSuccess(): void
112112
$signature = createHmac(['data' => $data, 'buildQuery' => true], $secret);
113113

114114
// Run the call
115-
$response = $this->call('post', '/billing/usage-charge', array_merge($data, ['signature' => $signature]), ['itp' => true]);
115+
$response = $this->call('post', '/billing/usage-charge', array_merge($data, ['signature' => $signature]));
116116
$response->assertRedirect('http://localhost');
117117
$response->assertSessionHas('success');
118118
}

0 commit comments

Comments
 (0)