-
-
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.
Fix BancSabadell payee name based on the transaction amount (#445)
* Fix BancSabadell creditor and debtor names * release notes
- Loading branch information
1 parent
d60e750
commit 41b1215
Showing
4 changed files
with
83 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Bugfix | ||
authors: [davidmartos96] | ||
--- | ||
|
||
Fix BancSabadell payee name based on the transaction amount |