diff --git a/app/Factory/CompanyGatewayFactory.php b/app/Factory/CompanyGatewayFactory.php index cc7ec46297..f19391ce3b 100644 --- a/app/Factory/CompanyGatewayFactory.php +++ b/app/Factory/CompanyGatewayFactory.php @@ -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; } } diff --git a/app/Http/Controllers/CompanyGatewayController.php b/app/Http/Controllers/CompanyGatewayController.php index 3674f1aa4e..6e0bba277b 100644 --- a/app/Http/Controllers/CompanyGatewayController.php +++ b/app/Http/Controllers/CompanyGatewayController.php @@ -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); } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 51fc3eb722..9823753544 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -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)) {