mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #4742 from turbo124/v5-develop
Ensure a company gateway always has at least one fees_and_limits object
This commit is contained in:
commit
c0748caaec
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Factory;
|
namespace App\Factory;
|
||||||
|
|
||||||
|
use App\DataMapper\FeesAndLimits;
|
||||||
use App\Models\CompanyGateway;
|
use App\Models\CompanyGateway;
|
||||||
|
|
||||||
class CompanyGatewayFactory
|
class CompanyGatewayFactory
|
||||||
@ -20,7 +21,8 @@ class CompanyGatewayFactory
|
|||||||
$company_gateway = new CompanyGateway;
|
$company_gateway = new CompanyGateway;
|
||||||
$company_gateway->company_id = $company_id;
|
$company_gateway->company_id = $company_id;
|
||||||
$company_gateway->user_id = $user_id;
|
$company_gateway->user_id = $user_id;
|
||||||
|
// $company_gateway->fees_and_limits = new FeesAndLimits;
|
||||||
|
|
||||||
return $company_gateway;
|
return $company_gateway;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\DataMapper\FeesAndLimits;
|
||||||
use App\Factory\CompanyGatewayFactory;
|
use App\Factory\CompanyGatewayFactory;
|
||||||
use App\Http\Requests\CompanyGateway\CreateCompanyGatewayRequest;
|
use App\Http\Requests\CompanyGateway\CreateCompanyGatewayRequest;
|
||||||
use App\Http\Requests\CompanyGateway\DestroyCompanyGatewayRequest;
|
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\ShowCompanyGatewayRequest;
|
||||||
use App\Http\Requests\CompanyGateway\StoreCompanyGatewayRequest;
|
use App\Http\Requests\CompanyGateway\StoreCompanyGatewayRequest;
|
||||||
use App\Http\Requests\CompanyGateway\UpdateCompanyGatewayRequest;
|
use App\Http\Requests\CompanyGateway\UpdateCompanyGatewayRequest;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Models\CompanyGateway;
|
use App\Models\CompanyGateway;
|
||||||
use App\Repositories\CompanyRepository;
|
use App\Repositories\CompanyRepository;
|
||||||
use App\Transformers\CompanyGatewayTransformer;
|
use App\Transformers\CompanyGatewayTransformer;
|
||||||
@ -191,6 +193,18 @@ class CompanyGatewayController extends BaseController
|
|||||||
$company_gateway->fill($request->all());
|
$company_gateway->fill($request->all());
|
||||||
$company_gateway->save();
|
$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);
|
return $this->itemResponse($company_gateway);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ class StoreCompanyGatewayRequest extends Request
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function authorize() : bool
|
public function authorize() : bool
|
||||||
{
|
{
|
||||||
return auth()->user()->isAdmin();
|
return auth()->user()->isAdmin();
|
||||||
@ -43,27 +44,32 @@ class StoreCompanyGatewayRequest extends Request
|
|||||||
protected function prepareForValidation()
|
protected function prepareForValidation()
|
||||||
{
|
{
|
||||||
$input = $this->all();
|
$input = $this->all();
|
||||||
|
|
||||||
$gateway = Gateway::where('key', $input['gateway_key'])->first();
|
$gateway = Gateway::where('key', $input['gateway_key'])->first();
|
||||||
|
|
||||||
$default_gateway_fields = json_decode($gateway->fields);
|
$default_gateway_fields = json_decode($gateway->fields);
|
||||||
|
|
||||||
/*Force gateway properties */
|
/*Force gateway properties */
|
||||||
if (isset($input['config']) && is_object(json_decode($input['config']))) {
|
if (isset($input['config']) && is_object(json_decode($input['config']))) {
|
||||||
|
|
||||||
foreach (json_decode($input['config']) as $key => $value) {
|
foreach (json_decode($input['config']) as $key => $value) {
|
||||||
|
|
||||||
$default_gateway_fields->{$key} = $value;
|
$default_gateway_fields->{$key} = $value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$input['config'] = json_encode($default_gateway_fields);
|
$input['config'] = json_encode($default_gateway_fields);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($input['config'])) {
|
if (isset($input['config']))
|
||||||
$input['config'] = encrypt($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']);
|
$input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']);
|
||||||
}
|
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,6 @@ class CompanyGateway extends BaseModel
|
|||||||
private function driver_class()
|
private function driver_class()
|
||||||
{
|
{
|
||||||
$class = 'App\\PaymentDrivers\\'.$this->gateway->provider.'PaymentDriver';
|
$class = 'App\\PaymentDrivers\\'.$this->gateway->provider.'PaymentDriver';
|
||||||
//$class = str_replace('\\', '', $class);
|
|
||||||
$class = str_replace('_', '', $class);
|
$class = str_replace('_', '', $class);
|
||||||
|
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
|
@ -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)
|
public function cleanFeesAndLimits($fees_and_limits)
|
||||||
{
|
{
|
||||||
$new_arr = [];
|
$new_arr = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user