mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #6884 from turbo124/v5-develop
Throw exception on paytrace failure
This commit is contained in:
commit
91e87d97d3
@ -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');
|
||||
}
|
||||
|
40
app/Http/ValidationRules/ValidAmount.php
Normal file
40
app/Http/ValidationRules/ValidAmount.php
Normal 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');
|
||||
}
|
||||
}
|
@ -42,6 +42,9 @@ class EntityViewedObject
|
||||
public function build()
|
||||
{
|
||||
|
||||
if(!$this->entity)
|
||||
return;
|
||||
|
||||
App::forgetInstance('translator');
|
||||
/* Init a new copy of the translator*/
|
||||
$t = app('translator');
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
|
143
tests/Integration/Validation/AmountValidationRuleTest.php
Normal file
143
tests/Integration/Validation/AmountValidationRuleTest.php
Normal 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user