diff --git a/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php b/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php index ecd9e410c768..9e3ebe6f3763 100644 --- a/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php +++ b/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php @@ -25,6 +25,7 @@ class StoreCompanyGatewayRequest extends Request * * @return bool */ + public function authorize() : bool { return auth()->user()->isAdmin(); @@ -43,27 +44,32 @@ class StoreCompanyGatewayRequest extends Request protected function prepareForValidation() { $input = $this->all(); + $gateway = Gateway::where('key', $input['gateway_key'])->first(); $default_gateway_fields = json_decode($gateway->fields); /*Force gateway properties */ if (isset($input['config']) && is_object(json_decode($input['config']))) { + foreach (json_decode($input['config']) as $key => $value) { + $default_gateway_fields->{$key} = $value; + } $input['config'] = json_encode($default_gateway_fields); + } - if (isset($input['config'])) { + if (isset($input['config'])) $input['config'] = encrypt($input['config']); - } - - if (isset($input['fees_and_limits'])) { + + if (isset($input['fees_and_limits'])) $input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']); - } - + $this->replace($input); } + + } diff --git a/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php b/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php index e8f31ac1b7fc..4863a0f5ab54 100644 --- a/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php +++ b/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php @@ -78,24 +78,6 @@ trait CompanyGatewayFeesAndLimitsSaver } } - // public function cleanFeesAndLimits($fees_and_limits) - // { - // $new_arr = []; - - // foreach ($fees_and_limits as $key => $value) { - // $fal = new FeesAndLimits; - - // foreach ($value as $k => $v) { - // $fal->{$k} = $v; - // $fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v); - // } - - // $new_arr[$key] = (array)$fal; - // } - - // return $new_arr; - // } - // public function cleanFeesAndLimits($fees_and_limits) { $new_arr = [];