1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #9362 from turbo124/v5-develop

Handle edge case with Nordigen where account appears active
This commit is contained in:
David Bomba 2024-03-10 13:22:07 +11:00 committed by GitHub
commit f5386f00dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 143 additions and 10 deletions

View File

@ -97,11 +97,11 @@ class Nordigen
return $it->transform($out);
} catch (\Exception $e) {
if (strpos($e->getMessage(), "Invalid Account ID") !== false) {
return false;
}
throw $e;
nlog("Nordigen getAccount() failed => {$account_id} => " . $e->getMessage());
return false;
}
}

View File

@ -44,6 +44,7 @@ class StoreProjectRequest extends Request
$rules['name'] = 'required';
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
$rules['budgeted_hours'] = 'sometimes|numeric';
if (isset($this->number)) {
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id);
@ -74,6 +75,9 @@ class StoreProjectRequest extends Request
$input['color'] = '';
}
if(array_key_exists('budgeted_hours', $input) && empty($input['budgeted_hours']))
$input['budgeted_hours'] = 0;
$this->replace($input);
}

View File

@ -45,6 +45,8 @@ class UpdateProjectRequest extends Request
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id)->ignore($this->project->id);
}
$rules['budgeted_hours'] = 'sometimes|numeric';
if ($this->file('documents') && is_array($this->file('documents'))) {
$rules['documents.*'] = $this->file_validation;
} elseif ($this->file('documents')) {
@ -73,6 +75,10 @@ class UpdateProjectRequest extends Request
if (array_key_exists('color', $input) && is_null($input['color'])) {
$input['color'] = '';
}
if(array_key_exists('budgeted_hours', $input) && empty($input['budgeted_hours'])) {
$input['budgeted_hours'] = 0;
}
$this->replace($input);
}

View File

@ -114,23 +114,26 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
private function updateAccount()
{
if (!$this->nordigen->isAccountActive($this->bank_integration->nordigen_account_id)) {
$is_account_active = $this->nordigen->isAccountActive($this->bank_integration->nordigen_account_id);
$account = $this->nordigen->getAccount($this->bank_integration->nordigen_account_id);
if (!$is_account_active || !$account) {
$this->bank_integration->disabled_upstream = true;
$this->bank_integration->save();
$this->stop_loop = false;
nlog("Nordigen: account inactive: " . $this->bank_integration->nordigen_account_id);
// @turbo124 @todo send email for expired account
$this->nordigen->disabledAccountEmail($this->bank_integration);
return;
}
$this->nordigen_account = $this->nordigen->getAccount($this->bank_integration->nordigen_account_id);
$this->nordigen_account = $account;
$this->bank_integration->disabled_upstream = false;
$this->bank_integration->bank_account_status = $this->nordigen_account['account_status'];
$this->bank_integration->balance = $this->nordigen_account['current_balance'];
$this->bank_integration->bank_account_status = $account['account_status'];
$this->bank_integration->balance = $account['current_balance'];
$this->bank_integration->save();
}

View File

@ -49,6 +49,12 @@ class ProjectTransformer extends EntityTransformer
public function includeClient(Project $project): \League\Fractal\Resource\Item
{
if (!$project->client) {
nlog("Project {$project->hashed_id} does not have a client attached - this project is in a bad state");
return null;
}
$transformer = new ClientTransformer($this->serializer);
return $this->includeItem($project->client, $transformer, Client::class);

View File

@ -460,7 +460,7 @@ $lang = array(
'edit_token' => 'Edit Token',
'delete_token' => 'Delete Token',
'token' => 'Token',
'add_gateway' => 'Add Gateway',
'add_gateway' => 'Add Payment Gateway',
'delete_gateway' => 'Delete Gateway',
'edit_gateway' => 'Edit Gateway',
'updated_gateway' => 'Successfully updated gateway',
@ -5251,6 +5251,9 @@ $lang = array(
'payment_type_help' => 'The default payment type to be used for payments',
'quote_valid_until_help' => 'The number of days that the quote is valid for',
'expense_payment_type_help' => 'The default expense payment type to be used',
'paylater' => 'Pay in 4',
'payment_provider' => 'Payment Provider',
);
return $lang;

View File

@ -29,6 +29,8 @@ class ProjectApiTest extends TestCase
use DatabaseTransactions;
use MockAccountData;
protected $faker;
protected function setUp() :void
{
parent::setUp();
@ -42,6 +44,110 @@ class ProjectApiTest extends TestCase
Model::reguard();
}
public function testProjectValidationForBudgetedHoursPut()
{
$data = $this->project->toArray();
$data['budgeted_hours'] = "aa";
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/projects/{$this->project->hashed_id}", $data);
$response->assertStatus(422);
}
public function testProjectValidationForBudgetedHoursPutNull()
{
$data = $this->project->toArray();
$data['budgeted_hours'] = null;
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/projects/{$this->project->hashed_id}", $data);
$response->assertStatus(200);
}
public function testProjectValidationForBudgetedHoursPutEmpty()
{
$data = $this->project->toArray();
$data['budgeted_hours'] = "";
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/projects/{$this->project->hashed_id}", $data);
$response->assertStatus(200);
}
public function testProjectValidationForBudgetedHours()
{
$data = [
'name' => $this->faker->firstName(),
'client_id' => $this->client->hashed_id,
'number' => 'duplicate',
'budgeted_hours' => null
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/projects', $data);
$response->assertStatus(200);
}
public function testProjectValidationForBudgetedHours2()
{
$data = [
'name' => $this->faker->firstName(),
'client_id' => $this->client->hashed_id,
'number' => 'duplicate',
'budgeted_hours' => "a"
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/projects', $data);
$response->assertStatus(422);
}
public function testProjectValidationForBudgetedHours3()
{
$data = [
'name' => $this->faker->firstName(),
'client_id' => $this->client->hashed_id,
'number' => 'duplicate',
'budgeted_hours' => ""
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/projects', $data);
$response->assertStatus(200);
}
public function testProjectGetFilter()
{
$response = $this->withHeaders([

View File

@ -72,6 +72,11 @@ trait MockAccountData
use MakesHash;
use GeneratesCounter;
/**
* @var
*/
public $project;
/**
* @var
*/