-
-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
254 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
src/app-gocardless/banks/tests/bancsabadell-bsabesbbb.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}); | ||
}); | ||
}; | ||
} |
Oops, something went wrong.