A local-first personal finance app
GoCardless: derive Alior payee from the card transaction description (#8738)
Marcin Radoszewskifaadbb37bbf6
diff --git a/packages/sync-server/src/app-gocardless/banks/alior_albpplpw.ts b/packages/sync-server/src/app-gocardless/banks/alior_albpplpw.tsnew file mode 100644index 0000000000..5d89aa0cfb--- /dev/null+++ b/packages/sync-server/src/app-gocardless/banks/alior_albpplpw.ts@@ -0,0 +1,53 @@+import type { IBank } from './bank.interface';+import Fallback from './integration-bank';++/**+ * Alior Bank stopped returning `creditorName` on outgoing transactions in+ * early July 2026. For card payments the merchant is still there, behind a+ * fixed prefix, in `remittanceInformationUnstructured`:+ *+ * "Transakcja kartą debetową, Example Coffee Bar"+ *+ * Without the merchant, `formatPayeeName` walks its fallback chain down to+ * `debtorName`, which on an outgoing transaction is the account holder. Every+ * card payment then gets booked against the account holder instead of the+ * shop.+ *+ * Only card payments are handled here. On the remaining outgoing transactions+ * (transfers, ATM withdrawals, loan instalments) the recipient is not present+ * in the payload at all, so there is nothing better to fall back to.+ *+ * Everything after the first comma is the merchant: Alior truncates that field+ * to 22 characters and appends nothing after it, so there are no further comma+ * separated fields to trip over. Checked against a 90 day window of real card+ * payments: none of the merchant names contained a comma or a line break, and+ * `remittanceInformationUnstructuredArray` was always a single element equal to+ * `remittanceInformationUnstructured`.+ */+const CARD_PAYMENT_MERCHANT = /^Transakcja kartą [^,]+,\s*(.+)$/is;++export default {+ ...Fallback,++ institutionIds: ['ALIOR_ALBPPLPW'],++ normalizeTransaction(transaction, booked) {+ const editedTrans = { ...transaction };++ if (+ Number(transaction.transactionAmount.amount) < 0 &&+ !transaction.creditorName+ ) {+ const remittanceInfo =+ transaction.remittanceInformationUnstructured ?? '';+ const merchant =+ remittanceInfo.match(CARD_PAYMENT_MERCHANT)?.[1].trim() ?? '';++ if (merchant) {+ editedTrans.creditorName = merchant;+ }+ }++ return Fallback.normalizeTransaction(transaction, booked, editedTrans);+ },+} satisfies IBank;diff --git a/packages/sync-server/src/app-gocardless/banks/tests/alior_albpplpw.spec.ts b/packages/sync-server/src/app-gocardless/banks/tests/alior_albpplpw.spec.tsnew file mode 100644index 0000000000..9031341d0a--- /dev/null+++ b/packages/sync-server/src/app-gocardless/banks/tests/alior_albpplpw.spec.ts@@ -0,0 +1,97 @@+import AliorAlbpplpw from '#app-gocardless/banks/alior_albpplpw';++describe('alior_albpplpw', () => {+ describe('#normalizeTransaction', () => {+ it('takes the merchant out of remittanceInformationUnstructured on card payments', () => {+ const transaction = {+ bookingDate: '2026-01-15',+ transactionAmount: { amount: '-12.50', currency: 'PLN' },+ debtorName: 'JOHN EXAMPLE',+ debtorAccount: { iban: 'PL00000000000000000987654321' },+ remittanceInformationUnstructured:+ 'Transakcja kartą debetową, Example Coffee Bar',+ };++ const normalizedTransaction = AliorAlbpplpw.normalizeTransaction(+ transaction,+ true,+ );++ expect(normalizedTransaction?.payeeName).toEqual('Example Coffee Bar');+ });++ it('does not fall back to the account holder on card payments', () => {+ const transaction = {+ bookingDate: '2026-01-16',+ transactionAmount: { amount: '-38.20', currency: 'PLN' },+ debtorName: 'JOHN EXAMPLE',+ debtorAccount: { iban: 'PL00000000000000000987654321' },+ remittanceInformationUnstructured:+ 'Transakcja kartą debetową, EXAMPLE MARKET 01',+ };++ const normalizedTransaction = AliorAlbpplpw.normalizeTransaction(+ transaction,+ true,+ );++ expect(normalizedTransaction?.payeeName).toEqual('Example Market 01');+ });++ it('keeps creditorName when the bank does provide it', () => {+ const transaction = {+ bookingDate: '2026-01-17',+ transactionAmount: { amount: '-21.00', currency: 'PLN' },+ creditorName: 'EXAMPLE PHARMACY 07',+ debtorName: 'JOHN EXAMPLE',+ debtorAccount: { iban: 'PL00000000000000000987654321' },+ remittanceInformationUnstructured:+ 'Transakcja kartą debetową, EXAMPLE STORE 1234',+ };++ const normalizedTransaction = AliorAlbpplpw.normalizeTransaction(+ transaction,+ true,+ );++ expect(normalizedTransaction?.payeeName).toEqual('Example Pharmacy 07');+ });++ it('leaves outgoing transfers to the default behaviour', () => {+ const transaction = {+ bookingDate: '2026-01-18',+ transactionAmount: { amount: '-500.00', currency: 'PLN' },+ debtorName: 'JOHN EXAMPLE',+ debtorAccount: { iban: 'PL00000000000000000987654321' },+ remittanceInformationUnstructured: 'Przelew wychodzący',+ };++ const normalizedTransaction = AliorAlbpplpw.normalizeTransaction(+ transaction,+ true,+ );++ expect(normalizedTransaction?.payeeName).toEqual(+ 'John Example (PL00 XXX 4321)',+ );+ });++ it('leaves incoming transactions untouched', () => {+ const transaction = {+ bookingDate: '2026-01-19',+ transactionAmount: { amount: '250.00', currency: 'PLN' },+ debtorName: 'EXAMPLE COMPANY SP. Z O.O.',+ remittanceInformationUnstructured: 'Invoice 12345',+ };++ const normalizedTransaction = AliorAlbpplpw.normalizeTransaction(+ transaction,+ true,+ );++ expect(normalizedTransaction?.payeeName).toEqual(+ 'Example Company Sp. Z O.O.',+ );+ });+ });+});diff --git a/upcoming-release-notes/8738.md b/upcoming-release-notes/8738.mdnew file mode 100644index 0000000000..59b9a28841--- /dev/null+++ b/upcoming-release-notes/8738.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [marad]+---++GoCardless: use the merchant from the transaction description as the payee for Alior Bank card payments, instead of the account holder