mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 16:34:35 -04:00
Refactor company gateway queries to ensure their order is respected
This commit is contained in:
parent
64d7edf513
commit
8c72321c09
@ -364,10 +364,17 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
{
|
{
|
||||||
$company_gateways = $this->getSetting('company_gateway_ids');
|
$company_gateways = $this->getSetting('company_gateway_ids');
|
||||||
|
|
||||||
|
/* It is very important to respect the order of the company_gateway_ids as they are ordered by priority*/
|
||||||
if (strlen($company_gateways)>=1) {
|
if (strlen($company_gateways)>=1) {
|
||||||
$gateways = $this->company->company_gateways->whereIn('id', $company_gateways);
|
$transformed_ids = $this->transformKeys(explode(",", $company_gateways));
|
||||||
|
$gateways = $this->company
|
||||||
|
->company_gateways
|
||||||
|
->whereIn('id', $transformed_ids)
|
||||||
|
->sortby(function($model) use ($transformed_ids){
|
||||||
|
return array_search($model->id, $transformed_ids);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
$gateways = $this->company->company_gateways;
|
$gateways = $this->company->company_gateways;//todo perhaps we can remove this or keep as a catch all.
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($gateways as $gateway) {
|
foreach ($gateways as $gateway) {
|
||||||
@ -384,7 +391,13 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
$company_gateways = $this->getSetting('company_gateway_ids');
|
$company_gateways = $this->getSetting('company_gateway_ids');
|
||||||
|
|
||||||
if (strlen($company_gateways)>=1) {
|
if (strlen($company_gateways)>=1) {
|
||||||
$gateways = $this->company->company_gateways->whereIn('id', $company_gateways);
|
$transformed_ids = $this->transformKeys(explode(",", $company_gateways));
|
||||||
|
$gateways = $this->company
|
||||||
|
->company_gateways
|
||||||
|
->whereIn('id', $transformed_ids)
|
||||||
|
->sortby(function($model) use ($transformed_ids){
|
||||||
|
return array_search($model->id, $transformed_ids);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
$gateways = $this->company->company_gateways;
|
$gateways = $this->company->company_gateways;
|
||||||
}
|
}
|
||||||
@ -448,7 +461,14 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
$company_gateways = $this->getSetting('company_gateway_ids');
|
$company_gateways = $this->getSetting('company_gateway_ids');
|
||||||
|
|
||||||
if ($company_gateways) {
|
if ($company_gateways) {
|
||||||
$gateways = $this->company->company_gateways->whereIn('id', $payment_gateways); //this will never hit
|
$transformed_ids = $this->transformKeys(explode(",", $company_gateways));
|
||||||
|
$gateways = $this->company
|
||||||
|
->company_gateways
|
||||||
|
->whereIn('id', $transformed_ids)
|
||||||
|
->sortby(function($model) use ($transformed_ids){
|
||||||
|
return array_search($model->id, $transformed_ids);
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$gateways = $this->company->company_gateways->where('is_deleted', false);
|
$gateways = $this->company->company_gateways->where('is_deleted', false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user