1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Check that a company gateway always has at least one fee and limits object

This commit is contained in:
David Bomba 2021-01-22 08:36:25 +11:00
parent 3d468e5f40
commit 4b87df07b7
3 changed files with 17 additions and 2 deletions

View File

@ -11,6 +11,7 @@
namespace App\Factory;
use App\DataMapper\FeesAndLimits;
use App\Models\CompanyGateway;
class CompanyGatewayFactory
@ -20,7 +21,8 @@ class CompanyGatewayFactory
$company_gateway = new CompanyGateway;
$company_gateway->company_id = $company_id;
$company_gateway->user_id = $user_id;
// $company_gateway->fees_and_limits = new FeesAndLimits;
return $company_gateway;
}
}

View File

@ -11,6 +11,7 @@
namespace App\Http\Controllers;
use App\DataMapper\FeesAndLimits;
use App\Factory\CompanyGatewayFactory;
use App\Http\Requests\CompanyGateway\CreateCompanyGatewayRequest;
use App\Http\Requests\CompanyGateway\DestroyCompanyGatewayRequest;
@ -18,6 +19,7 @@ use App\Http\Requests\CompanyGateway\EditCompanyGatewayRequest;
use App\Http\Requests\CompanyGateway\ShowCompanyGatewayRequest;
use App\Http\Requests\CompanyGateway\StoreCompanyGatewayRequest;
use App\Http\Requests\CompanyGateway\UpdateCompanyGatewayRequest;
use App\Models\Client;
use App\Models\CompanyGateway;
use App\Repositories\CompanyRepository;
use App\Transformers\CompanyGatewayTransformer;
@ -191,6 +193,18 @@ class CompanyGatewayController extends BaseController
$company_gateway->fill($request->all());
$company_gateway->save();
/*Always ensure at least one fees and limits object is set per gateway*/
if(!isset($company_gateway->fees_and_limits)) {
$gateway_types = $company_gateway->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$company_gateway->fees_and_limits = $fees_and_limits;
$company_gateway->save();
}
return $this->itemResponse($company_gateway);
}

View File

@ -108,7 +108,6 @@ class CompanyGateway extends BaseModel
private function driver_class()
{
$class = 'App\\PaymentDrivers\\'.$this->gateway->provider.'PaymentDriver';
//$class = str_replace('\\', '', $class);
$class = str_replace('_', '', $class);
if (class_exists($class)) {