2024-07-23 02:02:13 +02:00
|
|
|
<?php
|
2024-08-23 14:55:31 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
2024-07-23 02:02:13 +02:00
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-08-21 07:07:52 +02:00
|
|
|
use App\Http\Requests\Quickbooks\AuthorizedQuickbooksRequest;
|
2024-08-21 05:04:09 +02:00
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use App\Http\Requests\Quickbooks\AuthQuickbooksRequest;
|
2024-08-26 12:17:51 +02:00
|
|
|
use App\Services\Quickbooks\QuickbooksService;
|
2024-07-23 02:02:13 +02:00
|
|
|
|
|
|
|
class ImportQuickbooksController extends BaseController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
*/
|
2024-08-21 05:04:09 +02:00
|
|
|
public function authorizeQuickbooks(AuthQuickbooksRequest $request, string $token)
|
2024-07-23 02:02:13 +02:00
|
|
|
{
|
2024-08-22 08:45:06 +02:00
|
|
|
|
2024-08-21 05:04:09 +02:00
|
|
|
MultiDB::findAndSetDbByCompanyKey($request->getTokenContent()['company_key']);
|
|
|
|
$company = $request->getCompany();
|
|
|
|
$qb = new QuickbooksService($company);
|
|
|
|
|
2024-08-23 14:55:31 +02:00
|
|
|
$authorizationUrl = $qb->sdk()->getAuthorizationUrl();
|
|
|
|
$state = $qb->sdk()->getState();
|
2024-08-02 04:32:20 +02:00
|
|
|
|
2024-08-08 18:53:45 +02:00
|
|
|
Cache::put($state, $token, 190);
|
2024-07-23 02:02:13 +02:00
|
|
|
|
2024-08-02 04:32:20 +02:00
|
|
|
return redirect()->to($authorizationUrl);
|
2024-07-23 02:02:13 +02:00
|
|
|
}
|
2024-09-25 06:20:49 +02:00
|
|
|
|
|
|
|
public function onAuthorized(AuthorizedQuickbooksRequest $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
MultiDB::findAndSetDbByCompanyKey($request->getTokenContent()['company_key']);
|
|
|
|
$company = $request->getCompany();
|
|
|
|
$qb = new QuickbooksService($company);
|
|
|
|
|
|
|
|
$realm = $request->query('realmId');
|
|
|
|
$access_token_object = $qb->sdk()->accessTokenFromCode($request->query('code'), $realm);
|
|
|
|
$qb->sdk()->saveOAuthToken($access_token_object);
|
|
|
|
|
|
|
|
return redirect(config('ninja.react_url'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-23 02:02:13 +02:00
|
|
|
|
|
|
|
}
|