James Cole 4 years ago
parent
commit
9e4aa8c7fb
No known key found for this signature in database GPG Key ID: BDE6667570EADBD5
  1. 18
      app/Http/Middleware/TrustProxies.php
  2. 2
      app/Services/Nordigen/Conversion/Routine/GenerateTransactions.php
  3. 90
      app/Services/Nordigen/Model/Transaction.php

18
app/Http/Middleware/TrustProxies.php

@ -2,6 +2,7 @@
namespace App\Http\Middleware;
use Illuminate\Config\Repository;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
@ -25,4 +26,21 @@ class TrustProxies extends Middleware
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
/**
* TrustProxies constructor.
*
* @param Repository $config
*/
public function __construct(Repository $config)
{
$trustedProxies = (string) config('trustedproxy.proxies');
$this->proxies = explode(',', $trustedProxies);
if ('**' === $trustedProxies) {
$this->proxies = '**';
}
if ('*' === $trustedProxies) {
$this->proxies = '*';
}
}
}

2
app/Services/Nordigen/Conversion/Routine/GenerateTransactions.php

@ -198,7 +198,7 @@ class GenerateTransactions
private function generateTransaction(string $accountId, Transaction $entry): array
{
Log::debug(sprintf('Nordigen transaction: "%s" with amount %s %s', $entry->getDescription(), $entry->currencyCode, $entry->transactionAmount));
Log::debug('Original Nordigen transaction', $entry->toLocalArray());
//Log::debug('Original Nordigen transaction', $entry->toLocalArray());
$return = [
'apply_rules' => $this->configuration->isRules(),

90
app/Services/Nordigen/Model/Transaction.php

@ -88,7 +88,7 @@ class Transaction
*/
public static function fromArray($array): self
{
//Log::debug('Transaction from array', $array);
Log::debug('Nordigen transaction from array', $array);
$object = new self;
$object->additionalInformation = $array['additionalInformation'] ?? '';
@ -188,56 +188,34 @@ class Transaction
}
/**
* Return name of the destination account. Depends also on the amount
* Return name of the destination account
*
* @return string|null
*/
public function getDestinationName(): ?string
{
if (1 === bccomp($this->transactionAmount, '0')) {
Log::debug(sprintf('Destination name is "debtor" because %s > 0.', $this->transactionAmount));
// amount is positive, its a deposit, return creditor
if ('' !== $this->debtorName) {
Log::debug(sprintf('Destination name is "%s"', $this->debtorName));
return $this->debtorName;
}
}
if (1 !== bccomp($this->transactionAmount, '0')) {
Log::debug(sprintf('Destination name is "creditor" because %s < 0.', $this->transactionAmount));
if ('' !== $this->creditorName) {
Log::debug(sprintf('Destination name is "%s"', $this->creditorName));
return $this->creditorName;
}
Log::debug(__METHOD__);
if ('' !== $this->creditorName) {
Log::debug(sprintf('Destination name is "%s" (creditor)', $this->creditorName));
return $this->creditorName;
}
Log::warning(sprintf('Transaction "%s" has no destination account information.', $this->transactionId));
Log::warning(sprintf('Transaction "%s" has no destination account name information.', $this->transactionId));
return null;
}
/**
* Return IBAN of the destination account. Depends also on the amount
* Return IBAN of the destination account
*
* @return string|null
*/
public function getDestinationIban(): ?string
{
if (1 === bccomp($this->transactionAmount, '0')) {
Log::debug(sprintf('Destination IBAN is "debtor" because %s > 0.', $this->transactionAmount));
// amount is positive, its a deposit, return creditor
if ('' !== $this->debtorAccountIban) {
Log::debug(sprintf('Destination IBAN is "%s"', $this->debtorAccountIban));
return $this->debtorAccountIban;
}
Log::debug(__METHOD__);
if ('' !== $this->creditorAccountIban) {
Log::debug(sprintf('Destination IBAN is "%s" (creditor)', $this->creditorAccountIban));
return $this->creditorAccountIban;
}
if (1 !== bccomp($this->transactionAmount, '0')) {
Log::debug(sprintf('Destination IBAN is "creditor" because %s < 0.', $this->transactionAmount));
if ('' !== $this->creditorAccountIban) {
Log::debug(sprintf('Destination IBAN is "%s"', $this->creditorAccountIban));
return $this->creditorAccountIban;
}
}
Log::warning(sprintf('Transaction "%s" has no destination IBAN.', $this->transactionId));
Log::warning(sprintf('Transaction "%s" has no destination IBAN information.', $this->transactionId));
return null;
}
@ -249,23 +227,12 @@ class Transaction
*/
public function getSourceName(): ?string
{
if (-1 === bccomp($this->transactionAmount, '0')) {
Log::debug(sprintf('Source name is "debtor" because %s < 0.', $this->transactionAmount));
// amount is positive, its a deposit, return creditor
if ('' !== $this->debtorName) {
Log::debug(sprintf('Source name is "%s"', $this->debtorName));
return $this->debtorName;
}
Log::debug(__METHOD__);
if ('' !== $this->debtorName) {
Log::debug(sprintf('Source name is "%s" (debtor)', $this->debtorName));
return $this->debtorName;
}
if (-1 !== bccomp($this->transactionAmount, '0')) {
Log::debug(sprintf('Source name is "creditor" because %s > 0.', $this->transactionAmount));
if ('' !== $this->creditorName) {
Log::debug(sprintf('Source name is "%s"', $this->creditorName));
return $this->creditorName;
}
}
Log::warning(sprintf('Transaction "%s" has no source account information.', $this->transactionId));
Log::warning(sprintf('Transaction "%s" has no source account name information.', $this->transactionId));
return null;
}
@ -276,22 +243,11 @@ class Transaction
*/
public function getSourceIban(): ?string
{
if (-1 === bccomp($this->transactionAmount, '0')) {
Log::debug(sprintf('Source IBAN is from "debtor" because %s < 0.', $this->transactionAmount));
// amount is positive, its a deposit, return creditor
if ('' !== $this->debtorAccountIban) {
Log::debug(sprintf('Source IBAN is "%s"', $this->debtorAccountIban));
return $this->debtorAccountIban;
}
Log::debug(__METHOD__);
if ('' !== $this->debtorAccountIban) {
Log::debug(sprintf('Source IBAN is "%s" (debtor)', $this->debtorAccountIban));
return $this->debtorAccountIban;
}
if (-1 !== bccomp($this->transactionAmount, '0')) {
Log::debug(sprintf('Source IBAN is "creditor" because %s > 0.', $this->transactionAmount));
if ('' !== $this->creditorAccountIban) {
Log::debug(sprintf('Source IBAN is "%s"', $this->creditorAccountIban));
return $this->creditorAccountIban;
}
}
Log::warning(sprintf('Transaction "%s" has no source IBAN information.', $this->transactionId));
return null;
}
@ -408,7 +364,7 @@ class Transaction
} catch (JsonException $e) {
Log::error(sprintf('Could not parse array into JSON: %s', $e->getMessage()));
}
$object->transactionId = Uuid::uuid5(config('importer.namespace'), $hash);
$object->transactionId = (string) Uuid::uuid5(config('importer.namespace'), $hash);
}
return $object;

Loading…
Cancel
Save