This repository has been archived by the owner on Feb 10, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 678
Add GoCardless integration for COMMERZBANK_COBADEFF #537
Merged
UnderKoen
merged 4 commits into
actualbudget:master
from
nsulzer:gocardless-commerzbank_cobadeff
Jan 14, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cdfb5a1
Add GoCardless integration for COMMERZBANK_COBADEFF
nsulzer 0150ff2
Add optional iban property to creditorAccount
nsulzer f66724d
Use fallback for normalizeAccount and calculateStartingBalance
nsulzer 43eed1c
Update src/app-gocardless/banks/commerzbank_cobadeff.js
UnderKoen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,54 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import Fallback from './integration-bank.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { formatPayeeName } from '../../util/payee-name.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** @type {import('./bank.interface.js').IBank} */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...Fallback, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
institutionIds: ['COMMERZBANK_COBADEFF'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
normalizeTransaction(transaction, _booked) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// remittanceInformationUnstructured is limited to 140 chars thus ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// ... missing information form remittanceInformationUnstructuredArray ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// ... so we recreate it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
transaction.remittanceInformationUnstructured = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
transaction.remittanceInformationUnstructuredArray.join(' '); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// The limitations of remittanceInformationUnstructuredArray ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// ... can result in split keywords. We fix these. Other ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// ... splits will need to be fixed by user with rules. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const keywords = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'End-to-End-Ref.:', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'Mandatsref:', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'Gläubiger-ID:', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'SEPA-BASISLASTSCHRIFT', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'Kartenzahlung', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'Dauerauftrag', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
keywords.forEach((keyword) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
transaction.remittanceInformationUnstructured = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
transaction.remittanceInformationUnstructured.replace( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// There can be spaces in keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RegExp(keyword.split('').join('\\s*'), 'gi'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
UnderKoen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
', ' + keyword + ' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Clean up remittanceInformation, deduplicate payee (removing slashes ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// ... that are added to the remittanceInformation field), and ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// ... remove clutter like "End-to-End-Ref.: NOTPROVIDED" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const payee = transaction.creditorName || transaction.debtorName || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
transaction.remittanceInformationUnstructured = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
transaction.remittanceInformationUnstructured | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.replace(/\s*(,)?\s+/g, '$1 ') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.replace(RegExp(payee.split(' ').join('(/*| )'), 'gi'), ' ') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.replace(', End-to-End-Ref.: NOTPROVIDED', '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.trim(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...transaction, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
payeeName: formatPayeeName(transaction), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
date: transaction.bookingDate, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+37
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve robustness of remittance information cleanup. The current implementation has several areas for improvement:
+ // Validate transaction object structure
+ if (!transaction || typeof transaction !== 'object') {
+ throw new Error('Invalid transaction object');
+ }
+
const payee = transaction.creditorName || transaction.debtorName || '';
+
+ // Break down complex regex into more maintainable steps
transaction.remittanceInformationUnstructured =
transaction.remittanceInformationUnstructured
- .replace(/\s*(,)?\s+/g, '$1 ')
- .replace(RegExp(payee.split(' ').join('(/*| )'), 'gi'), ' ')
+ // Normalize spaces around commas
+ .replace(/\s*,\s*/g, ', ')
+ // Normalize multiple spaces
+ .replace(/\s+/g, ' ')
+ // Remove payee name variations
+ .replace(new RegExp(
+ payee
+ .split(' ')
+ .map(part => `${part}(?:/+|\\s+)?`)
+ .join(''),
+ 'gi'
+ ), ' ')
.replace(', End-to-End-Ref.: NOTPROVIDED', '')
.trim(); 📝 Committable suggestion
Suggested change
|
110 changes: 110 additions & 0 deletions
110
src/app-gocardless/banks/tests/commerzbank_cobadeff.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,110 @@ | ||
import CommerzbankCobadeff from '../commerzbank_cobadeff.js'; | ||
|
||
describe('CommerzbankCobadeff', () => { | ||
describe('#normalizeTransaction', () => { | ||
it('correctly formats remittanceInformationUnstructured', () => { | ||
const transaction = { | ||
endToEndId: '1234567890', | ||
mandateId: '321654', | ||
bookingDate: '2024-12-20', | ||
valueDate: '2024-12-20', | ||
transactionAmount: { | ||
amount: '-12.34', | ||
currency: 'EUR', | ||
}, | ||
creditorName: 'SHOP NAME CITY DE', | ||
remittanceInformationUnstructured: | ||
'SHOP NAME//CITY/DE\n2024-12-19T15:34:31 KFN 1 AB 1234\nKartenzahlung', | ||
remittanceInformationUnstructuredArray: [ | ||
'SHOP NAME//CITY/DE', | ||
'2024-12-19T15:34:31 KFN 1 AB 1234', | ||
'Kartenzahlung', | ||
], | ||
remittanceInformationStructured: | ||
'SHOP NAME//CITY/DE 2024-12-19T15:34:31 KFN 1 AB 1234 Kartenzahlung', | ||
internalTransactionId: '3815213adb654baeadfb231c853', | ||
}; | ||
const normalizedTransaction = CommerzbankCobadeff.normalizeTransaction( | ||
transaction, | ||
false, | ||
); | ||
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( | ||
'2024-12-19T15:34:31 KFN 1 AB 1234, Kartenzahlung', | ||
); | ||
}); | ||
|
||
it('correctly formats remittanceInformationUnstructured; repair split keyword', () => { | ||
const transaction = { | ||
endToEndId: '901234567890', | ||
mandateId: 'ABC123DEF456', | ||
bookingDate: '2024-10-11', | ||
valueDate: '2024-10-11', | ||
transactionAmount: { | ||
amount: '-56.78', | ||
currency: 'EUR', | ||
}, | ||
creditorName: 'Long payee name that is eaxtly 35ch', | ||
remittanceInformationUnstructured: | ||
'Long payee name that is eaxtly 35ch\n901234567890/. Long description tha\nt gets cut and is very long, did I\nmention it is long\nEnd-to-En', | ||
remittanceInformationUnstructuredArray: [ | ||
'Long payee name that is eaxtly 35ch', | ||
'901234567890/. Long description tha', | ||
't gets cut and is very long, did I', | ||
'mention it is long', | ||
'End-to-En', | ||
'd-Ref.: 901234567890', | ||
'Mandatsref: ABC123DEF456', | ||
'Gläubiger-ID:', | ||
'AB12CDE0000000000000000012', | ||
'SEPA-BASISLASTSCHRIFT wiederholend', | ||
], | ||
remittanceInformationStructured: | ||
'Long payee name that is eaxtly 35ch 901234567890/. Long description tha t gets cut and is very long, did I mention it is long End-to-En', | ||
internalTransactionId: '812354cfdea36465asdfe', | ||
}; | ||
const normalizedTransaction = CommerzbankCobadeff.normalizeTransaction( | ||
transaction, | ||
false, | ||
); | ||
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( | ||
'901234567890/. Long description tha t gets cut and is very long, did I mention it is long, End-to-End-Ref.: 901234567890, Mandatsref: ABC123DEF456, Gläubiger-ID: AB12CDE0000000000000000012, SEPA-BASISLASTSCHRIFT wiederholend', | ||
); | ||
}); | ||
|
||
it('correctly formats remittanceInformationUnstructured; removing NOTPROVIDED', () => { | ||
const transaction = { | ||
endToEndId: 'NOTPROVIDED', | ||
bookingDate: '2024-12-02', | ||
valueDate: '2024-12-02', | ||
transactionAmount: { | ||
amount: '-9', | ||
currency: 'EUR', | ||
}, | ||
creditorName: 'CREDITOR NAME', | ||
creditorAccount: { | ||
iban: 'CREDITOR000IBAN', | ||
}, | ||
remittanceInformationUnstructured: | ||
'CREDITOR NAME\nCREDITOR00BIC\nCREDITOR000IBAN\nDESCRIPTION\nEnd-to-End-Ref.: NOTPROVIDED\nDauerauftrag', | ||
remittanceInformationUnstructuredArray: [ | ||
'CREDITOR NAME', | ||
'CREDITOR00BIC', | ||
'CREDITOR000IBAN', | ||
'DESCRIPTION', | ||
'End-to-End-Ref.: NOTPROVIDED', | ||
'Dauerauftrag', | ||
], | ||
remittanceInformationStructured: | ||
'CREDITOR NAME CREDITOR00BIC CREDITOR000IBAN DESCRIPTION End-to-End-Ref.: NOTPROVIDED Dauerauftrag', | ||
internalTransactionId: 'f617dc31ab77622bf13d6c95d6dd8b4a', | ||
}; | ||
const normalizedTransaction = CommerzbankCobadeff.normalizeTransaction( | ||
transaction, | ||
false, | ||
); | ||
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( | ||
'CREDITOR00BIC CREDITOR000IBAN DESCRIPTION, Dauerauftrag', | ||
); | ||
}); | ||
}); | ||
}); |
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,6 @@ | ||
--- | ||
category: Enhancements | ||
authors: [nsulzer] | ||
--- | ||
|
||
Add GoCardless integration for COMMERZBANK_COBADEFF |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add null check for remittanceInformationUnstructuredArray.
The array join operation could fail if the array is undefined. Consider adding a defensive check:
📝 Committable suggestion