diff --git a/app/Models/Client.php b/app/Models/Client.php index 46b538a8f1ff..0edddde42f6c 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -13,6 +13,7 @@ namespace App\Models; use App\DataMapper\ClientSettings; use App\DataMapper\CompanySettings; +use App\Models\CompanyGateway; use App\Models\Presenters\ClientPresenter; use App\Services\Client\ClientService; use App\Utils\Traits\AppSetup; @@ -422,35 +423,57 @@ class Client extends BaseModel implements HasLocalePreference public function getBankTransferGateway() :?CompanyGateway { - $company_gateways = $this->getSetting('company_gateway_ids'); + $pms = $this->service()->getPaymentMethods(0); + + if($this->currency()->code == 'USD' && in_array(GatewayType::BANK_TRANSFER, array_column($pms, 'gateway_type_id'))){ + + foreach($pms as $pm){ + if($pm['gateway_type_id'] == GatewayType::BANK_TRANSFER) + return CompanyGateway::find($pm['company_gateway_id']); + } - if (strlen($company_gateways) >= 1) { - $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 { - $gateways = $this->company->company_gateways; } - foreach ($gateways as $gateway) { - if ($this->currency()->code == 'USD' && in_array(GatewayType::BANK_TRANSFER, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::BANK_TRANSFER))) { - return $gateway; + if($this->currency()->code == 'EUR' && in_array(GatewayType::BANK_TRANSFER, array_column($pms, 'gateway_type_id'))){ + + foreach($pms as $pm){ + if($pm['gateway_type_id'] == GatewayType::SEPA) + return CompanyGateway::find($pm['company_gateway_id']); } - if ($this->currency()->code == 'EUR' && in_array(GatewayType::SEPA, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::SEPA))) { - return $gateway; - } } return null; + // $company_gateways = $this->getSetting('company_gateway_ids'); + + // if (strlen($company_gateways) >= 1) { + // $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 { + // $gateways = $this->company->company_gateways; + // } + + // foreach ($gateways as $gateway) { + // if ($this->currency()->code == 'USD' && in_array(GatewayType::BANK_TRANSFER, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::BANK_TRANSFER))) { + // return $gateway; + // } + + // if ($this->currency()->code == 'EUR' && in_array(GatewayType::SEPA, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::SEPA))) { + // return $gateway; + // } + // } + + // return null; } public function getBankTransferMethodType() { + if ($this->currency()->code == 'USD') { return GatewayType::BANK_TRANSFER; }