mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Merge pull request #6216 from turbo124/v5-develop
Fixes for displaying enabled gateways for payment methods
This commit is contained in:
commit
f863e08bcd
@ -397,30 +397,52 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
*/
|
||||
public function getCreditCardGateway() :?CompanyGateway
|
||||
{
|
||||
$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) {
|
||||
$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;
|
||||
}
|
||||
// /* It is very important to respect the order of the company_gateway_ids as they are ordered by priority*/
|
||||
// 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 (in_array(GatewayType::CREDIT_CARD, $gateway->driver($this)->gatewayTypeEnabled(GatewayType::CREDIT_CARD))) {
|
||||
return $gateway;
|
||||
// foreach ($gateways as $gateway) {
|
||||
// if (in_array(GatewayType::CREDIT_CARD, $gateway->driver($this)->gatewayTypeEnabled($gateway, GatewayType::CREDIT_CARD))) {
|
||||
// return $gateway;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return null;
|
||||
//
|
||||
|
||||
$pms = $this->service()->getPaymentMethods(0);
|
||||
|
||||
foreach($pms as $pm)
|
||||
{
|
||||
|
||||
if($pm['gateway_type_id'] == GatewayType::CREDIT_CARD)
|
||||
{
|
||||
$cg = CompanyGateway::find($pm['company_gateway_id']);
|
||||
|
||||
if($cg && $cg->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled)
|
||||
return $cg;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
//todo refactor this - it is only searching for existing tokens
|
||||
public function getBankTransferGateway() :?CompanyGateway
|
||||
{
|
||||
$pms = $this->service()->getPaymentMethods(0);
|
||||
@ -428,8 +450,14 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
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']);
|
||||
{
|
||||
$cg = CompanyGateway::find($pm['company_gateway_id']);
|
||||
|
||||
if($cg && $cg->fees_and_limits->{GatewayType::BANK_TRANSFER}->is_enabled)
|
||||
return $cg;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -437,8 +465,14 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
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']);
|
||||
{
|
||||
$cg = CompanyGateway::find($pm['company_gateway_id']);
|
||||
|
||||
if($cg && $cg->fees_and_limits->{GatewayType::SEPA}->is_enabled)
|
||||
return $cg;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user