1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spinen\QuickBooks\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Routing\UrlGenerator; |
6
|
|
|
use Illuminate\Contracts\View\Factory as ViewFactory; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Illuminate\Routing\Controller as LaravelController; |
9
|
|
|
use Illuminate\Routing\Redirector; |
10
|
|
|
use Spinen\QuickBooks\Client as QuickBooks; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Controller |
14
|
|
|
* |
15
|
|
|
* @package Spinen\QuickBooks |
16
|
|
|
*/ |
17
|
|
|
class Controller extends LaravelController |
18
|
|
|
{ |
19
|
|
|
// NOTE: When using constructor injection for QuickBooks, there is a race issue with the boot order of the app |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Form to connect/disconnect user to QuickBooks |
23
|
|
|
* |
24
|
|
|
* If the user has a valid OAuth, then give form to disconnect, otherwise link to connect it |
25
|
|
|
* |
26
|
|
|
* @param QuickBooks $quickbooks |
27
|
|
|
* @param ViewFactory $view_factory |
28
|
|
|
* |
29
|
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\View\View |
|
|
|
|
30
|
|
|
* @throws \QuickBooksOnline\API\Exception\SdkException |
31
|
|
|
* @throws \QuickBooksOnline\API\Exception\ServiceException |
32
|
|
|
*/ |
33
|
2 |
|
public function connect(QuickBooks $quickbooks, ViewFactory $view_factory) |
34
|
|
|
{ |
35
|
|
|
// Give view to remove token if user already linked account |
36
|
2 |
|
if ($quickbooks->hasValidRefreshToken()) { |
37
|
1 |
|
return $view_factory->make('quickbooks::disconnect') |
38
|
1 |
|
->with('company', $quickbooks->getDataService() |
39
|
1 |
|
->getCompanyInfo()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// Give view to link account |
43
|
1 |
|
return $view_factory->make('quickbooks::connect') |
44
|
1 |
|
->with('authorization_uri', $quickbooks->authorizationUri()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Removes the token |
49
|
|
|
* |
50
|
|
|
* @param Redirector $redirector |
51
|
|
|
* @param QuickBooks $quickbooks |
52
|
|
|
* |
53
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View |
54
|
|
|
* @throws \Exception |
55
|
|
|
*/ |
56
|
1 |
|
public function disconnect(Redirector $redirector, Request $request, QuickBooks $quickbooks) |
57
|
|
|
{ |
58
|
1 |
|
$quickbooks->deleteToken(); |
59
|
|
|
|
60
|
1 |
|
$request->session()->flash('success', 'Disconnected from QuickBooks'); |
61
|
|
|
|
62
|
1 |
|
return $redirector->back(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Accept the code from QuickBooks to request token |
67
|
|
|
* |
68
|
|
|
* Once a user approves linking account, then QuickBooks sends back |
69
|
|
|
* a code which can be converted to an OAuth token. |
70
|
|
|
* |
71
|
|
|
* @param Redirector $redirector |
72
|
|
|
* @param Request $request |
73
|
|
|
* @param QuickBooks $quickbooks |
74
|
|
|
* @param UrlGenerator $url_generator |
75
|
|
|
* |
76
|
|
|
* @return \Illuminate\Http\RedirectResponse |
77
|
|
|
* @throws \QuickBooksOnline\API\Exception\SdkException |
78
|
|
|
* @throws \QuickBooksOnline\API\Exception\ServiceException |
79
|
|
|
*/ |
80
|
1 |
|
public function token(Redirector $redirector, Request $request, QuickBooks $quickbooks, UrlGenerator $url_generator) |
81
|
|
|
{ |
82
|
|
|
// TODO: Deal with exceptions |
83
|
1 |
|
$quickbooks->exchangeCodeForToken($request->get('code'), $request->get('realmId')); |
84
|
|
|
|
85
|
1 |
|
$request->session()->flash('success', 'Connected to QuickBooks'); |
86
|
|
|
|
87
|
1 |
|
return $redirector->intended($url_generator->route('quickbooks.connect')); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths