Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrocadomoreira authored Sep 10, 2024
2 parents 7bca20f + 41b1215 commit d9d6454
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 132 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);
});
});
});
});
13 changes: 10 additions & 3 deletions src/app-gocardless/util/handle-error.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { inspect } from 'util';

export function handleError(func) {
return (req, res) => {
func(req, res).catch((err) => {
console.log('Error', req.originalUrl, err);
res.status(500);
res.send({ status: 'error', reason: 'internal-error' });
console.log('Error', req.originalUrl, inspect(err, { depth: null }));
res.send({
status: 'ok',
data: {
error_code: 'INTERNAL_ERROR',
error_type: err.message ? err.message : 'internal-error',
},
});
});
};
}
Loading

0 comments on commit d9d6454

Please sign in to comment.