|
|
@ -90,7 +90,7 @@ class Transaction |
|
|
|
public string $ultimateDebtor; |
|
|
|
|
|
|
|
// new fields
|
|
|
|
public ?Carbon $valueDate = null; |
|
|
|
public ?Carbon $valueDate = null; |
|
|
|
|
|
|
|
/** |
|
|
|
* Creates a transaction from a downloaded array. |
|
|
@ -100,12 +100,12 @@ class Transaction |
|
|
|
public static function fromArray($array): self |
|
|
|
{ |
|
|
|
Log::debug('GoCardless transaction from array', $array); |
|
|
|
$object = new self(); |
|
|
|
$object->tags = []; |
|
|
|
$object->additionalInformation = trim($array['additionalInformation'] ?? ''); |
|
|
|
$object->additionalInformationStructured = trim($array['additionalInformationStructured'] ?? ''); |
|
|
|
$object->bankTransactionCode = trim($array['bankTransactionCode'] ?? ''); |
|
|
|
$object->bookingDate = array_key_exists('bookingDate', $array) ? Carbon::createFromFormat('!Y-m-d', $array['bookingDate'], config('app.timezone')) : null; |
|
|
|
$object = new self(); |
|
|
|
$object->tags = []; |
|
|
|
$object->additionalInformation = trim($array['additionalInformation'] ?? ''); |
|
|
|
$object->additionalInformationStructured = trim($array['additionalInformationStructured'] ?? ''); |
|
|
|
$object->bankTransactionCode = trim($array['bankTransactionCode'] ?? ''); |
|
|
|
$object->bookingDate = array_key_exists('bookingDate', $array) ? Carbon::createFromFormat('!Y-m-d', $array['bookingDate'], config('app.timezone')) : null; |
|
|
|
|
|
|
|
// overrule with "bookingDateTime" if present:
|
|
|
|
if (array_key_exists('bookingDateTime', $array)) { |
|
|
@ -139,11 +139,11 @@ class Transaction |
|
|
|
$object->valueDate = array_key_exists('valueDate', $array) ? Carbon::createFromFormat('!Y-m-d', $array['valueDate'], config('app.timezone')) : null; |
|
|
|
|
|
|
|
// undocumented values
|
|
|
|
$object->endToEndId = trim($array['endToEndId'] ?? ''); // from Rabobank NL
|
|
|
|
$object->endToEndId = trim($array['endToEndId'] ?? ''); // from Rabobank NL
|
|
|
|
|
|
|
|
// overrule transaction id when empty using the internal ID:
|
|
|
|
// 2025-09-07: switch to using internal transaction ID, never "transactionId".
|
|
|
|
$object->transactionId = trim($array['internalTransactionId'] ?? ''); |
|
|
|
$object->transactionId = trim($array['internalTransactionId'] ?? ''); |
|
|
|
|
|
|
|
// models:
|
|
|
|
if (array_key_exists('balanceAfterTransaction', $array) && is_array($array['balanceAfterTransaction'])) { |
|
|
@ -158,35 +158,35 @@ class Transaction |
|
|
|
} |
|
|
|
|
|
|
|
// add "pending" or "booked" if it exists.
|
|
|
|
$key = (string)$array['key']; |
|
|
|
$key = (string)$array['key']; |
|
|
|
if ('' !== $key) { |
|
|
|
$object->tags[] = $key; |
|
|
|
} |
|
|
|
|
|
|
|
// add merchant category code, if it exists:
|
|
|
|
$merchantCode = (string)($array['merchant_category_code'] ?? ''); |
|
|
|
$merchantCode = (string)($array['merchant_category_code'] ?? ''); |
|
|
|
if ('' !== $merchantCode) { |
|
|
|
$object->tags[] = $merchantCode; |
|
|
|
} |
|
|
|
|
|
|
|
// array values:
|
|
|
|
$object->creditorAccountIban = trim($array['creditorAccount']['iban'] ?? ''); |
|
|
|
$object->creditorAccountBban = trim($array['creditorAccount']['bban'] ?? ''); |
|
|
|
$object->creditorAccountCurrency = trim($array['creditorAccount']['currency'] ?? ''); |
|
|
|
$object->creditorAccountIban = trim($array['creditorAccount']['iban'] ?? ''); |
|
|
|
$object->creditorAccountBban = trim($array['creditorAccount']['bban'] ?? ''); |
|
|
|
$object->creditorAccountCurrency = trim($array['creditorAccount']['currency'] ?? ''); |
|
|
|
|
|
|
|
$object->debtorAccountIban = trim($array['debtorAccount']['iban'] ?? ''); |
|
|
|
$object->debtorAccountBban = trim($array['debtorAccount']['bban'] ?? ''); |
|
|
|
$object->debtorAccountCurrency = trim($array['debtorAccount']['currency'] ?? ''); |
|
|
|
$object->debtorAccountIban = trim($array['debtorAccount']['iban'] ?? ''); |
|
|
|
$object->debtorAccountBban = trim($array['debtorAccount']['bban'] ?? ''); |
|
|
|
$object->debtorAccountCurrency = trim($array['debtorAccount']['currency'] ?? ''); |
|
|
|
|
|
|
|
$object->transactionAmount = trim($array['transactionAmount']['amount'] ?? ''); |
|
|
|
$object->currencyCode = trim($array['transactionAmount']['currency'] ?? ''); |
|
|
|
$object->transactionAmount = trim($array['transactionAmount']['amount'] ?? ''); |
|
|
|
$object->currencyCode = trim($array['transactionAmount']['currency'] ?? ''); |
|
|
|
|
|
|
|
// other fields:
|
|
|
|
$object->accountIdentifier = $array['account_id'] ?? ''; |
|
|
|
$object->accountIdentifier = $array['account_id'] ?? ''; |
|
|
|
|
|
|
|
// generate transactionID if empty:
|
|
|
|
if ('' === $object->transactionId) { |
|
|
|
$hash = hash('sha256', (string)microtime()); |
|
|
|
$hash = hash('sha256', (string)microtime()); |
|
|
|
|
|
|
|
try { |
|
|
|
$hash = hash('sha256', json_encode($array, JSON_THROW_ON_ERROR)); |
|
|
@ -209,7 +209,7 @@ class Transaction |
|
|
|
*/ |
|
|
|
public static function fromLocalArray(array $array): self |
|
|
|
{ |
|
|
|
$object = new self(); |
|
|
|
$object = new self(); |
|
|
|
|
|
|
|
$object->tags = []; |
|
|
|
$object->additionalInformation = $array['additional_information']; |
|
|
@ -248,23 +248,23 @@ class Transaction |
|
|
|
} |
|
|
|
|
|
|
|
// undocumented values:
|
|
|
|
$object->endToEndId = $array['end_to_end_id']; |
|
|
|
$object->endToEndId = $array['end_to_end_id']; |
|
|
|
|
|
|
|
// TODO copy paste code.
|
|
|
|
$object->debtorAccountIban = array_key_exists('iban', $array['debtor_account']) ? $array['debtor_account']['iban'] : ''; |
|
|
|
$object->creditorAccountIban = array_key_exists('iban', $array['creditor_account']) ? $array['creditor_account']['iban'] : ''; |
|
|
|
$object->debtorAccountIban = array_key_exists('iban', $array['debtor_account']) ? $array['debtor_account']['iban'] : ''; |
|
|
|
$object->creditorAccountIban = array_key_exists('iban', $array['creditor_account']) ? $array['creditor_account']['iban'] : ''; |
|
|
|
|
|
|
|
$object->debtorAccountBban = array_key_exists('bban', $array['debtor_account']) ? $array['debtor_account']['bban'] : ''; |
|
|
|
$object->creditorAccountBban = array_key_exists('bban', $array['creditor_account']) ? $array['creditor_account']['bban'] : ''; |
|
|
|
$object->debtorAccountBban = array_key_exists('bban', $array['debtor_account']) ? $array['debtor_account']['bban'] : ''; |
|
|
|
$object->creditorAccountBban = array_key_exists('bban', $array['creditor_account']) ? $array['creditor_account']['bban'] : ''; |
|
|
|
|
|
|
|
$object->debtorAccountCurrency = array_key_exists('currency', $array['debtor_account']) ? $array['debtor_account']['currency'] : ''; |
|
|
|
$object->creditorAccountCurrency = array_key_exists('currency', $array['creditor_account']) ? $array['creditor_account']['currency'] : ''; |
|
|
|
$object->debtorAccountCurrency = array_key_exists('currency', $array['debtor_account']) ? $array['debtor_account']['currency'] : ''; |
|
|
|
$object->creditorAccountCurrency = array_key_exists('currency', $array['creditor_account']) ? $array['creditor_account']['currency'] : ''; |
|
|
|
|
|
|
|
// $object-> = $array[''];
|
|
|
|
|
|
|
|
// generate transactionID if empty:
|
|
|
|
if ('' === $object->transactionId) { |
|
|
|
$hash = hash('sha256', (string)microtime()); |
|
|
|
$hash = hash('sha256', (string)microtime()); |
|
|
|
|
|
|
|
try { |
|
|
|
$hash = hash('sha256', json_encode($array, JSON_THROW_ON_ERROR)); |
|
|
@ -347,6 +347,7 @@ class Transaction |
|
|
|
$transactionId = substr(trim((string)preg_replace('/\s+/', ' ', $this->transactionId)), 0, 125); |
|
|
|
|
|
|
|
Log::debug(sprintf('Returning transaction ID: %s and %s are joined.', $accountId, $transactionId)); |
|
|
|
|
|
|
|
return trim(sprintf('%s-%s', $accountId, $transactionId)); |
|
|
|
} |
|
|
|
|
|
|
@ -430,7 +431,7 @@ class Transaction |
|
|
|
|
|
|
|
// room for other fields
|
|
|
|
if (str_contains("\n", $this->getDescription())) { |
|
|
|
$notes .= "\n\n" . $this->getDescription(); |
|
|
|
$notes .= "\n\n".$this->getDescription(); |
|
|
|
} |
|
|
|
|
|
|
|
return trim($notes); |
|
|
|