diff --git a/app/Http/Controllers/ClientPortal/SwitchCompanyController.php b/app/Http/Controllers/ClientPortal/SwitchCompanyController.php index 627dd6e18d28..2867541476d6 100644 --- a/app/Http/Controllers/ClientPortal/SwitchCompanyController.php +++ b/app/Http/Controllers/ClientPortal/SwitchCompanyController.php @@ -27,7 +27,7 @@ class SwitchCompanyController extends Controller ->where('id', $this->transformKeys($contact)) ->first(); - Auth::guard('contact')->login($client_contact, true); + auth()->guard('contact')->user()->login($client_contact, true); return redirect('/client/dashboard'); } diff --git a/app/Http/ValidationRules/ValidAmount.php b/app/Http/ValidationRules/ValidAmount.php new file mode 100644 index 000000000000..d2832e83a046 --- /dev/null +++ b/app/Http/ValidationRules/ValidAmount.php @@ -0,0 +1,40 @@ +entity) + return; + App::forgetInstance('translator'); /* Init a new copy of the translator*/ $t = app('translator'); diff --git a/app/PaymentDrivers/PaytracePaymentDriver.php b/app/PaymentDrivers/PaytracePaymentDriver.php index 3b164f4a64b8..f834791c4311 100644 --- a/app/PaymentDrivers/PaytracePaymentDriver.php +++ b/app/PaymentDrivers/PaytracePaymentDriver.php @@ -11,6 +11,7 @@ namespace App\PaymentDrivers; +use App\Exceptions\SystemError; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -192,7 +193,7 @@ class PaytracePaymentDriver extends BaseDriver $auth_data = json_decode($response); if(!property_exists($auth_data, 'access_token')) - throw new \Exception('Error authenticating with PayTrace'); + throw new SystemError('Error authenticating with PayTrace'); $headers = []; $headers[] = 'Content-type: application/json'; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index e8c367e9d0f9..441e7382691c 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -4334,6 +4334,7 @@ $LANG = array( 'clone_to_expense' => 'Clone to expense', 'checkout' => 'Checkout', 'acss' => 'Pre-authorized debit payments', + 'invalid_amount' => 'Invalid amount. Number/Decimal values only.' ); return $LANG; diff --git a/tests/Integration/Validation/AmountValidationRuleTest.php b/tests/Integration/Validation/AmountValidationRuleTest.php new file mode 100644 index 000000000000..82a9b06c0a69 --- /dev/null +++ b/tests/Integration/Validation/AmountValidationRuleTest.php @@ -0,0 +1,143 @@ + [new ValidAmount()] + ]; + + $data = [ + 'amount' => 1, + ]; + + $v = $this->app['validator']->make($data, $rules); + $this->assertTrue($v->passes()); + } + + public function testInvalidAmountValid() + { + $rules = [ + 'amount' => [new ValidAmount()] + ]; + + $data = [ + 'amount' => "aa", + ]; + + $v = $this->app['validator']->make($data, $rules); + $this->assertFalse($v->passes()); + } + + public function testIllegalChars() + { + $rules = [ + 'amount' => [new ValidAmount()] + ]; + + $data = [ + 'amount' => "5+5", + ]; + + $v = $this->app['validator']->make($data, $rules); + $this->assertFalse($v->passes()); + } + + public function testIllegalCharsNaked() + { + $rules = [ + 'amount' => [new ValidAmount()] + ]; + + $data = [ + 'amount' => 5+5, //resolves as 10 - but in practice, i believe this amount is wrapped in quotes so interpreted as a string + ]; + + $v = $this->app['validator']->make($data, $rules); + $this->assertTrue($v->passes()); + } + + + public function testinValidScenario1() + { + $rules = [ + 'amount' => [new ValidAmount()] + ]; + + $data = [ + 'amount' => "-10x", + ]; + + $v = $this->app['validator']->make($data, $rules); + $this->assertFalse($v->passes()); + } + + public function testValidScenario2() + { + $rules = [ + 'amount' => [new ValidAmount()] + ]; + + $data = [ + 'amount' => -10, + ]; + + $v = $this->app['validator']->make($data, $rules); + $this->assertTrue($v->passes()); + } + + + public function testValidScenario3() + { + $rules = [ + 'amount' => [new ValidAmount()] + ]; + + $data = [ + 'amount' => "-10", + ]; + + $v = $this->app['validator']->make($data, $rules); + $this->assertTrue($v->passes()); + } + + public function testInValidScenario4() + { + $rules = [ + 'amount' => [new ValidAmount()] + ]; + + $data = [ + 'amount' => "-0 1", + ]; + + $v = $this->app['validator']->make($data, $rules); + $this->assertFalse($v->passes()); + } +} + +