mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
This commit is contained in:
parent
1a68dcacea
commit
2ad973359b
@ -64,73 +64,73 @@ use Log;
|
|||||||
|
|
||||||
class TransactionTransformer implements BankRevenueInterface
|
class TransactionTransformer implements BankRevenueInterface
|
||||||
{
|
{
|
||||||
use AppSetup;
|
use AppSetup;
|
||||||
|
|
||||||
public function transform($transactionResponse)
|
public function transform($transactionResponse)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"]))
|
if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"]))
|
||||||
throw new \Exception('invalid dataset');
|
throw new \Exception('invalid dataset');
|
||||||
|
|
||||||
foreach ($transactionResponse["transactions"]["booked"] as $transaction) {
|
foreach ($transactionResponse["transactions"]["booked"] as $transaction) {
|
||||||
$data[] = $this->transformTransaction($transaction);
|
$data[] = $this->transformTransaction($transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
public function transformTransaction($transaction)
|
||||||
}
|
{
|
||||||
|
|
||||||
public function transformTransaction($transaction)
|
if (!array_key_exists('transactionId', $transaction) || !array_key_exists('transactionAmount', $transaction))
|
||||||
{
|
throw new \Exception('invalid dataset');
|
||||||
|
|
||||||
if (!array_key_exists('transactionId', $transaction) || !array_key_exists('transactionAmount', $transaction))
|
// description could be in varios places
|
||||||
throw new \Exception('invalid dataset');
|
$description = '';
|
||||||
|
if (array_key_exists('remittanceInformationStructured', $transaction))
|
||||||
|
$description = $transaction["remittanceInformationStructured"];
|
||||||
|
else if (array_key_exists('remittanceInformationStructuredArray', $transaction))
|
||||||
|
$description = implode(' \r\n', $transaction["remittanceInformationStructuredArray"]);
|
||||||
|
else if (array_key_exists('remittanceInformationUnstructured', $transaction))
|
||||||
|
$description = $transaction["remittanceInformationUnstructured"];
|
||||||
|
else
|
||||||
|
Log::warning("Missing description for the following transaction: " . json_encode($transaction));
|
||||||
|
|
||||||
// description could be in varios places
|
return [
|
||||||
$description = '';
|
'transaction_id' => $transaction["transactionId"],
|
||||||
if (array_key_exists('remittanceInformationStructured', $transaction))
|
'amount' => abs((int) $transaction["transactionAmount"]["amount"]),
|
||||||
$description = $transaction["remittanceInformationStructured"];
|
'currency_id' => $this->convertCurrency($transaction["transactionAmount"]["currency"]),
|
||||||
else if (array_key_exists('remittanceInformationStructuredArray', $transaction))
|
'category_id' => null, // nordigen has no categories
|
||||||
$description = implode(' \r\n', $transaction["remittanceInformationStructuredArray"]);
|
'category_type' => array_key_exists('additionalInformation', $transaction) ? $transaction["additionalInformation"] : '', // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc
|
||||||
else if (array_key_exists('remittanceInformationUnstructured', $transaction))
|
'date' => $transaction["bookingDate"],
|
||||||
$description = $transaction["remittanceInformationUnstructured"];
|
'description' => $description,
|
||||||
else
|
'participant' => array_key_exists('debtorAccount', $transaction) && array_key_exists('iban', $transaction["debtorAccount"]) ? $transaction['debtorAccount']['iban'] : null,
|
||||||
Log::warning("Missing description for the following transaction: " . json_encode($transaction));
|
'participant_name' => array_key_exists('debtorName', $transaction) ? $transaction['debtorName'] : null,
|
||||||
|
'base_type' => (int) $transaction["transactionAmount"]["amount"] <= 0 ? 'DEBIT' : 'CREDIT',
|
||||||
|
];
|
||||||
|
|
||||||
return [
|
|
||||||
'transaction_id' => $transaction["transactionId"],
|
|
||||||
'amount' => abs((int) $transaction["transactionAmount"]["amount"]),
|
|
||||||
'currency_id' => $this->convertCurrency($transaction["transactionAmount"]["currency"]),
|
|
||||||
'category_id' => 0, // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc
|
|
||||||
'category_type' => array_key_exists('additionalInformation', $transaction) ? $transaction["additionalInformation"] : '', // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc
|
|
||||||
'date' => $transaction["bookingDate"],
|
|
||||||
'description' => $description,
|
|
||||||
'participant' => array_key_exists('debtorAccount', $transaction) && array_key_exists('iban', $transaction["debtorAccount"]) ? $transaction['debtorAccount']['iban'] : null,
|
|
||||||
'participant_name' => array_key_exists('debtorName', $transaction) ? $transaction['debtorName'] : null,
|
|
||||||
'base_type' => (int) $transaction["transactionAmount"]["amount"] <= 0 ? 'DEBIT' : 'CREDIT',
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function convertCurrency(string $code)
|
|
||||||
{
|
|
||||||
|
|
||||||
$currencies = Cache::get('currencies');
|
|
||||||
|
|
||||||
if (!$currencies) {
|
|
||||||
$this->buildCache(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$currency = $currencies->filter(function ($item) use ($code) {
|
private function convertCurrency(string $code)
|
||||||
return $item->code == $code;
|
{
|
||||||
})->first();
|
|
||||||
|
|
||||||
if ($currency)
|
$currencies = Cache::get('currencies');
|
||||||
return $currency->id;
|
|
||||||
|
|
||||||
return 1;
|
if (!$currencies) {
|
||||||
|
$this->buildCache(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
$currency = $currencies->filter(function ($item) use ($code) {
|
||||||
|
return $item->code == $code;
|
||||||
|
})->first();
|
||||||
|
|
||||||
|
if ($currency)
|
||||||
|
return $currency->id;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user