mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Check that a company gateway always has at least one fee and limits object
This commit is contained in:
parent
3d468e5f40
commit
4b87df07b7
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Factory;
|
||||
|
||||
use App\DataMapper\FeesAndLimits;
|
||||
use App\Models\CompanyGateway;
|
||||
|
||||
class CompanyGatewayFactory
|
||||
@ -20,6 +21,7 @@ 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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user