Skip to content

Commit f169ad4

Browse files
Julien Alrickewisch
authored andcommitted
add support for originalCreditorId
1 parent 4f95a7c commit f169ad4

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ info.creditorIBAN = "DE87123456781234567890";
6565
info.creditorBIC = "XMPLDEM0XXX";
6666
info.creditorName = "Example LLC";
6767
info.creditorId = "DE98ZZZ09999999999";
68+
info.originalCreditorId = "IT66ZZZA1B2C3D4E5F6G7H8"; //optional
6869
info.batchBooking = true; //optional
6970
doc.addPaymentInfo(info);
7071

examples/example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ info.creditorIBAN = 'DE87123456781234567890';
1616
info.creditorBIC = 'XMPLDEM0XXX';
1717
info.creditorName = 'Example LLC';
1818
info.creditorId = 'DE98ZZZ09999999999';
19+
info.originalCreditorId = 'IT66ZZZA1B2C3D4E5F6G7H8';
1920
doc.addPaymentInfo(info);
2021

2122
var tx = info.createTransaction();

lib/sepa.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@
287287
/** Id assigned to the creditor */
288288
creditorId: '',
289289

290+
/** Original creditor id (optional, for creditor id migrations) */
291+
originalCreditorId: null,
292+
290293
/** Name, Address, IBAN and BIC of the creditor */
291294
creditorName: '',
292295
creditorStreet: null,
@@ -367,6 +370,10 @@
367370
assert_cid(this[pullFrom + 'Id'], pullFrom + 'Id');
368371
}
369372

373+
if (this.originalCreditorId) {
374+
assert_cid(this.originalCreditorId, 'originalCreditorId');
375+
}
376+
370377
assert_length(this[pullFrom + 'Name'], null, 70, pullFrom + 'Name');
371378
assert_length(this[pullFrom + 'Street'], null, 70, pullFrom + 'Street');
372379
assert_length(this[pullFrom + 'City'], null, 70, pullFrom + 'City');
@@ -453,6 +460,12 @@
453460
var creditorScheme = n(pmtInf, 'CdtrSchmeId', 'Id', 'PrvtId', 'Othr');
454461
r(creditorScheme, 'Id', this.creditorId);
455462
r(creditorScheme, 'SchmeNm', 'Prtry', 'SEPA');
463+
464+
if (this.originalCreditorId) {
465+
var originalCreditorScheme = n(pmtInf, 'OrgnlCdtrSchmeId', 'Id', 'PrvtId', 'Othr');
466+
r(originalCreditorScheme, 'Id', this.originalCreditorId);
467+
r(originalCreditorScheme, 'SchmeNm', 'Prtry', 'SEPA');
468+
}
456469
}
457470

458471
for (var i = 0, l = this._payments.length; i < l; ++i) {

lib/sepa.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var xpath = require('xpath');
33

44
// The following debtor id is provided by German Bundesbank for testing purposes.
55
const A_VALID_CREDITOR_ID = 'DE98ZZZ09999999999';
6+
const ANOTHER_VALID_CREDITOR_ID = 'IT66ZZZA1B2C3D4E5F6G7H8';
67

78
const A_VALID_IBAN = 'DE43500105178994141576';
89

@@ -336,14 +337,15 @@ describe('xml generation for transfer documents', () => {
336337

337338
describe('xml generation for direct debit documents', () => {
338339
const PAIN_FOR_DIRECT_DEBIT = 'pain.008.001.08';
339-
function validDirectDebitDocument({creditorId=A_VALID_CREDITOR_ID}) {
340+
function validDirectDebitDocument({creditorId=A_VALID_CREDITOR_ID, originalCreditorId=null}) {
340341
var doc = new SEPA.Document(PAIN_FOR_DIRECT_DEBIT);
341342
doc.grpHdr.created = new Date();
342343

343344
var info = doc.createPaymentInfo();
344345
info.collectionDate = new Date();
345346
info.creditorIBAN = A_VALID_IBAN;
346347
info.creditorId = creditorId;
348+
info.originalCreditorId = originalCreditorId;
347349
doc.addPaymentInfo(info);
348350

349351
var tx = info.createTransaction();
@@ -388,6 +390,39 @@ describe('xml generation for direct debit documents', () => {
388390
expect(creditorId).toBeUndefined();
389391
});
390392

393+
test('includes original creditor id when set', () => {
394+
// GIVEN
395+
const doc = validDirectDebitDocument({originalCreditorId: ANOTHER_VALID_CREDITOR_ID});
396+
397+
// WHEN
398+
const dom = doc.toXML();
399+
400+
// THEN
401+
const select = xpath.useNamespaces({
402+
p: `urn:iso:std:iso:20022:tech:xsd:${PAIN_FOR_DIRECT_DEBIT}`,
403+
});
404+
405+
const originalCreditorId = select('/p:Document/p:CstmrDrctDbtInitn/p:PmtInf/p:OrgnlCdtrSchmeId/p:Id/p:PrvtId/p:Othr/p:Id', dom, true);
406+
expect(originalCreditorId).not.toBeUndefined();
407+
expect(originalCreditorId.textContent).toBe(ANOTHER_VALID_CREDITOR_ID);
408+
});
409+
410+
test('works without setting original creditor id', () => {
411+
// GIVEN
412+
const doc = validDirectDebitDocument({originalCreditorId: null});
413+
414+
// WHEN
415+
const dom = doc.toXML();
416+
417+
// THEN
418+
const select = xpath.useNamespaces({
419+
p: `urn:iso:std:iso:20022:tech:xsd:${PAIN_FOR_DIRECT_DEBIT}`,
420+
});
421+
422+
const originalCreditorId = select('/p:Document/p:CstmrDrctDbtInitn/p:PmtInf/p:OrgnlCdtrSchmeId', dom, true);
423+
expect(originalCreditorId).toBeUndefined();
424+
});
425+
391426
test('serialized document starts with proper xml declaration', () => {
392427
// GIVEN
393428
const doc = validDirectDebitDocument({});

types/sepa.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ declare module "sepa" {
168168

169169
/** Id assigned to the creditor */
170170
creditorId: string;
171+
/** Original creditor id (optional, for creditor id migrations) */
172+
originalCreditorId: string | null;
171173
/** Name of the creditor */
172174
creditorName: string;
173175
/** Street of the creditor */

0 commit comments

Comments
 (0)