From 0d06bc1f7ecfaab99bf38ee292d1672cc70c398a Mon Sep 17 00:00:00 2001 From: guglicap Date: Mon, 16 Dec 2024 21:11:32 +0100 Subject: [PATCH] Hype Bank (`HYPE_HYEEIT22`) Enhancements (#512) --- src/app-gocardless/bank-factory.js | 2 + src/app-gocardless/banks/hype_hyeeit22.js | 77 +++++++++++++++++++++++ upcoming-release-notes/512.md | 6 ++ 3 files changed, 85 insertions(+) create mode 100644 src/app-gocardless/banks/hype_hyeeit22.js create mode 100644 upcoming-release-notes/512.md diff --git a/src/app-gocardless/bank-factory.js b/src/app-gocardless/bank-factory.js index d4666365e..d101928f6 100644 --- a/src/app-gocardless/bank-factory.js +++ b/src/app-gocardless/bank-factory.js @@ -11,6 +11,7 @@ import DanskeBankDabNO22 from './banks/danskebank-dabno22.js'; import EasybankBawaatww from './banks/easybank-bawaatww.js'; import Fortuneo from './banks/FORTUNEO_FTNOFRP1XXX.js'; import HanseaticBank from './banks/HANSEATIC_HSTBDEHH.js'; +import Hype_HYEEIT22 from './banks/hype_hyeeit22.js'; import IngIngbrobu from './banks/ing-ingbrobu.js'; import IngIngddeff from './banks/ing-ingddeff.js'; import IngPlIngbplpw from './banks/ing-pl-ingbplpw.js'; @@ -46,6 +47,7 @@ export const banks = [ EasybankBawaatww, Fortuneo, HanseaticBank, + Hype_HYEEIT22, IngIngbrobu, IngIngddeff, IngPlIngbplpw, diff --git a/src/app-gocardless/banks/hype_hyeeit22.js b/src/app-gocardless/banks/hype_hyeeit22.js new file mode 100644 index 000000000..7091f3c7a --- /dev/null +++ b/src/app-gocardless/banks/hype_hyeeit22.js @@ -0,0 +1,77 @@ +import Fallback from './integration-bank.js'; + +import { formatPayeeName } from '../../util/payee-name.js'; + +/** @type {import('./bank.interface.js').IBank} */ +export default { + ...Fallback, + + institutionIds: ['HYPE_HYEEIT22'], + + accessValidForDays: 90, + + normalizeTransaction(transaction, _booked) { + /** Online card payments - identified by "crd" transaction code + * always start with PAGAMENTO PRESSO + + */ + if (transaction.proprietaryBankTransactionCode == 'crd') { + // remove PAGAMENTO PRESSO and set payee name + transaction.debtorName = + transaction.remittanceInformationUnstructured?.slice( + 'PAGAMENTO PRESSO '.length, + ); + } + /** + * In-app money transfers (p2p) and bank transfers (bon) have remittance info structure like + * DENARO (INVIATO/RICEVUTO) (A/DA) {payee_name} - {payment_info} (p2p) + * HAI (INVIATO/RICEVUTO) UN BONIFICO (A/DA) {payee_name} - {payment_info} (bon) + */ + if ( + transaction.proprietaryBankTransactionCode == 'p2p' || + transaction.proprietaryBankTransactionCode == 'bon' + ) { + // keep only {payment_info} portion of remittance info + // NOTE: if {payee_name} contains dashes (unlikely / impossible?), this probably gets bugged! + let infoIdx = + transaction.remittanceInformationUnstructured.indexOf(' - ') + 3; + transaction.remittanceInformationUnstructured = + infoIdx == -1 + ? transaction.remittanceInformationUnstructured + : transaction.remittanceInformationUnstructured.slice(infoIdx).trim(); + } + /** + * CONVERT ESCAPED UNICODE TO CODEPOINTS + * p2p payments allow user to write arbitrary unicode strings as messages + * gocardless reports unicode codepoints as \Uxxxx + * so it groups them in 4bytes bundles + * the code below assumes this is always the case + */ + if (transaction.proprietaryBankTransactionCode == 'p2p') { + let str = transaction.remittanceInformationUnstructured; + let idx = str.indexOf('\\U'); + let start_idx = idx; + let codepoints = []; + while (idx !== -1) { + codepoints.push(parseInt(str.slice(idx + 2, idx + 6), 16)); + let next_idx = str.indexOf('\\U', idx + 6); + if (next_idx == idx + 6) { + idx = next_idx; + continue; + } + str = + str.slice(0, start_idx) + + String.fromCodePoint(...codepoints) + + str.slice(idx + 6); + codepoints = []; + idx = str.indexOf('\\U'); // slight inefficiency? + start_idx = idx; + } + transaction.remittanceInformationUnstructured = str; + } + return { + ...transaction, + payeeName: formatPayeeName(transaction), + date: transaction.valueDate || transaction.bookingDate, + }; + }, +}; diff --git a/upcoming-release-notes/512.md b/upcoming-release-notes/512.md new file mode 100644 index 000000000..4a047ac86 --- /dev/null +++ b/upcoming-release-notes/512.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [guglicap] +--- + +Enhances Hype Bank transaction info parsing