1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Http/Controllers/ImportQuickbooksController.php

59 lines
1.7 KiB
PHP
Raw Normal View History

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();
Cache::put($state, $token, 190);
2024-07-23 02:02:13 +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
}