mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
loop and find gateway on all connections
This commit is contained in:
parent
758e6d92f0
commit
4146464142
@ -14,6 +14,7 @@ namespace App\Http\Controllers\Gateways;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\GoCardless\WebhookRequest;
|
use App\Http\Requests\GoCardless\WebhookRequest;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
use App\Models\CompanyGateway;
|
use App\Models\CompanyGateway;
|
||||||
use App\Repositories\CompanyRepository;
|
use App\Repositories\CompanyRepository;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
@ -33,14 +34,34 @@ class GoCardlessOAuthWebhookController extends Controller
|
|||||||
$e = Arr::dot($event);
|
$e = Arr::dot($event);
|
||||||
|
|
||||||
if ($event['action'] === 'disconnected') {
|
if ($event['action'] === 'disconnected') {
|
||||||
|
|
||||||
/** @var \App\Models\CompanyGateway $company_gateway */
|
/** @var \App\Models\CompanyGateway $company_gateway */
|
||||||
$company_gateway = CompanyGateway::query()
|
$company_gateway = null;
|
||||||
->whereJsonContains('config->account_id', $e['links.organisation'])
|
|
||||||
->firstOrFail();
|
foreach (MultiDB::$dbs as $db) {
|
||||||
|
if (
|
||||||
|
/** @var \App\Models\CompanyGateway $company_gateway */
|
||||||
|
$cg = CompanyGateway::on($db)
|
||||||
|
->where('settings->organisation_id', $e['links.organisation'])
|
||||||
|
->exists()
|
||||||
|
) {
|
||||||
|
$company_gateway = $cg;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($company_gateway === null) {
|
||||||
|
return abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
$current = $company_gateway->getConfig('__current');
|
$current = $company_gateway->getConfig('__current');
|
||||||
|
|
||||||
|
$settings = $company_gateway->settings;
|
||||||
|
|
||||||
|
$settings->organisation_id = null;
|
||||||
|
|
||||||
|
$company_gateway->setSettings($settings);
|
||||||
|
|
||||||
if ($current) {
|
if ($current) {
|
||||||
$company_gateway->setConfig($current);
|
$company_gateway->setConfig($current);
|
||||||
$company_gateway->save();
|
$company_gateway->save();
|
||||||
@ -49,5 +70,7 @@ class GoCardlessOAuthWebhookController extends Controller
|
|||||||
$this->company_repository->archive($company_gateway);
|
$this->company_repository->archive($company_gateway);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user