Skip to content

Commit

Permalink
Fix BancSabadell payee name based on the transaction amount (#445)
Browse files Browse the repository at this point in the history
* Fix BancSabadell creditor and debtor names

* release notes
  • Loading branch information
davidmartos96 authored Sep 8, 2024
1 parent d60e750 commit 41b1215
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AbancaCaglesmm from './banks/abanca-caglesmm.js';
import AmericanExpressAesudef1 from './banks/american-express-aesudef1.js';
import BancsabadellBsabesbb from './banks/bancsabadell-bsabesbbb.js';
import BankinterBkbkesmm from './banks/bankinter-bkbkesmm.js';
import Belfius from './banks/belfius_gkccbebb.js';
import Berliner_Sparkasse_beladebexxx from './banks/berliner_sparkasse_beladebexxx.js';
Expand All @@ -26,6 +27,7 @@ import VirginNrnbgb22 from './banks/virgin_nrnbgb22.js';
export const banks = [
AbancaCaglesmm,
AmericanExpressAesudef1,
BancsabadellBsabesbb,
BankinterBkbkesmm,
Belfius,
Berliner_Sparkasse_beladebexxx,
Expand Down
36 changes: 36 additions & 0 deletions src/app-gocardless/banks/bancsabadell-bsabesbbb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Fallback from './integration-bank.js';

import { formatPayeeName } from '../../util/payee-name.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
...Fallback,

institutionIds: ['BANCSABADELL_BSABESBB'],

accessValidForDays: 180,

// Sabadell transactions don't get the creditorName/debtorName properly
normalizeTransaction(transaction, _booked) {
const amount = transaction.transactionAmount.amount;

// The amount is negative for outgoing transactions, positive for incoming transactions.
const isCreditorPayee = Number.parseFloat(amount) < 0;

const payeeName = transaction.remittanceInformationUnstructuredArray
.join(' ')
.trim();

// The payee name is the creditor name for outgoing transactions and the debtor name for incoming transactions.
const creditorName = isCreditorPayee ? payeeName : null;
const debtorName = isCreditorPayee ? null : payeeName;

transaction.creditorName = creditorName;
transaction.debtorName = debtorName;

return {
...transaction,
payeeName: formatPayeeName(transaction),
};
},
};
39 changes: 39 additions & 0 deletions src/app-gocardless/banks/tests/bancsabadell-bsabesbbb.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Sabadell from '../bancsabadell-bsabesbbb.js';

describe('BancSabadell', () => {
describe('#normalizeTransaction', () => {
describe('returns the creditorName and debtorName from remittanceInformationUnstructuredArray', () => {
it('debtor role - amount < 0', () => {
const transaction = {
transactionAmount: { amount: '-100', currency: 'EUR' },
remittanceInformationUnstructuredArray: ['some-creditor-name'],
internalTransactionId: 'd7dca139cf31d9',
transactionId: '04704109322',
};
const normalizedTransaction = Sabadell.normalizeTransaction(
transaction,
true,
);
expect(normalizedTransaction.creditorName).toEqual(
'some-creditor-name',
);
expect(normalizedTransaction.debtorName).toEqual(null);
});

it('creditor role - amount > 0', () => {
const transaction = {
transactionAmount: { amount: '100', currency: 'EUR' },
remittanceInformationUnstructuredArray: ['some-debtor-name'],
internalTransactionId: 'd7dca139cf31d9',
transactionId: '04704109322',
};
const normalizedTransaction = Sabadell.normalizeTransaction(
transaction,
true,
);
expect(normalizedTransaction.debtorName).toEqual('some-debtor-name');
expect(normalizedTransaction.creditorName).toEqual(null);
});
});
});
});
6 changes: 6 additions & 0 deletions upcoming-release-notes/445.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [davidmartos96]
---

Fix BancSabadell payee name based on the transaction amount

0 comments on commit 41b1215

Please sign in to comment.