mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Merge pull request #10057 from beganovich/INV2-1544
GoCardless OAuth2: MultiDB
This commit is contained in:
commit
c327b9acf5
@ -77,6 +77,8 @@ class GoCardlessOAuthController extends Controller
|
||||
if ($response->failed()) {
|
||||
return view('auth.gocardless_connect.access_denied');
|
||||
}
|
||||
|
||||
$response = $response->json();
|
||||
|
||||
$company_gateway = CompanyGateway::query()
|
||||
->where('gateway_key', 'b9886f9257f0c6ee7c302f1c74475f6c')
|
||||
@ -92,8 +94,6 @@ class GoCardlessOAuthController extends Controller
|
||||
$company_gateway->setConfig([]);
|
||||
}
|
||||
|
||||
$response = $response->json();
|
||||
|
||||
$payload = [
|
||||
'__current' => $company_gateway->getConfig(),
|
||||
'account_id' => $response['organisation_id'],
|
||||
@ -105,6 +105,11 @@ class GoCardlessOAuthController extends Controller
|
||||
'oauth2' => true,
|
||||
];
|
||||
|
||||
$settings = new \stdClass();
|
||||
$settings->organisation_id = $response['organisation_id'];
|
||||
|
||||
$company_gateway->setSettings($settings);
|
||||
|
||||
$company_gateway->setConfig($payload);
|
||||
$company_gateway->save();
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace App\Http\Controllers\Gateways;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\GoCardless\WebhookRequest;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Repositories\CompanyRepository;
|
||||
use Illuminate\Support\Arr;
|
||||
@ -33,14 +34,34 @@ class GoCardlessOAuthWebhookController extends Controller
|
||||
$e = Arr::dot($event);
|
||||
|
||||
if ($event['action'] === 'disconnected') {
|
||||
|
||||
/** @var \App\Models\CompanyGateway $company_gateway */
|
||||
$company_gateway = CompanyGateway::query()
|
||||
->whereJsonContains('config->account_id', $e['links.organisation'])
|
||||
->firstOrFail();
|
||||
$company_gateway = null;
|
||||
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
if (
|
||||
/** @var \App\Models\CompanyGateway $company_gateway */
|
||||
$cg = CompanyGateway::on($db)
|
||||
->where('settings->organisation_id', $e['links.organisation'])
|
||||
->first()
|
||||
) {
|
||||
$company_gateway = $cg;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($company_gateway === null) {
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
$current = $company_gateway->getConfig('__current');
|
||||
|
||||
$settings = $company_gateway->settings;
|
||||
|
||||
$settings->organisation_id = null;
|
||||
|
||||
$company_gateway->setSettings($settings);
|
||||
|
||||
if ($current) {
|
||||
$company_gateway->setConfig($current);
|
||||
$company_gateway->save();
|
||||
@ -49,5 +70,7 @@ class GoCardlessOAuthWebhookController extends Controller
|
||||
$this->company_repository->archive($company_gateway);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user