1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00

Merge pull request #6884 from turbo124/v5-develop

Throw exception on paytrace failure
This commit is contained in:
David Bomba 2021-10-23 15:28:23 +11:00 committed by GitHub
commit 91e87d97d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 190 additions and 2 deletions

View File

@ -27,7 +27,7 @@ class SwitchCompanyController extends Controller
->where('id', $this->transformKeys($contact)) ->where('id', $this->transformKeys($contact))
->first(); ->first();
Auth::guard('contact')->login($client_contact, true); auth()->guard('contact')->user()->login($client_contact, true);
return redirect('/client/dashboard'); return redirect('/client/dashboard');
} }

View File

@ -0,0 +1,40 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\ValidationRules;
use App\Libraries\MultiDB;
use Illuminate\Contracts\Validation\Rule;
/**
* Class ValidAmount.
*/
class ValidAmount implements Rule
{
/**
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return trim($value, '-1234567890.,') === '';
}
/**
* @return string
*/
public function message()
{
return ctrans('texts.invalid_amount');
}
}

View File

@ -42,6 +42,9 @@ class EntityViewedObject
public function build() public function build()
{ {
if(!$this->entity)
return;
App::forgetInstance('translator'); App::forgetInstance('translator');
/* Init a new copy of the translator*/ /* Init a new copy of the translator*/
$t = app('translator'); $t = app('translator');

View File

@ -11,6 +11,7 @@
namespace App\PaymentDrivers; namespace App\PaymentDrivers;
use App\Exceptions\SystemError;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
@ -192,7 +193,7 @@ class PaytracePaymentDriver extends BaseDriver
$auth_data = json_decode($response); $auth_data = json_decode($response);
if(!property_exists($auth_data, 'access_token')) if(!property_exists($auth_data, 'access_token'))
throw new \Exception('Error authenticating with PayTrace'); throw new SystemError('Error authenticating with PayTrace');
$headers = []; $headers = [];
$headers[] = 'Content-type: application/json'; $headers[] = 'Content-type: application/json';

View File

@ -4334,6 +4334,7 @@ $LANG = array(
'clone_to_expense' => 'Clone to expense', 'clone_to_expense' => 'Clone to expense',
'checkout' => 'Checkout', 'checkout' => 'Checkout',
'acss' => 'Pre-authorized debit payments', 'acss' => 'Pre-authorized debit payments',
'invalid_amount' => 'Invalid amount. Number/Decimal values only.'
); );
return $LANG; return $LANG;

View File

@ -0,0 +1,143 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Integration\Validation;
use App\Http\ValidationRules\ValidAmount;
use Tests\TestCase;
/**
* @test
*/
class AmountValidationRuleTest extends TestCase
{
public function setUp() :void
{
parent::setUp();
}
public function testSimpleAmountValid()
{
$rules = [
'amount' => [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());
}
}