Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/sepa.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,11 @@
if (this[pullFrom + 'BIC']) {
r(txInf, recieverNodeName + 'Agt', 'FinInstnId', getPainXMLVersion(this._painFormat) >= 8 ? 'BICFI' : 'BIC', this[pullFrom + 'BIC']);
} else {
r(txInf, recieverNodeName + 'Agt', 'FinInstnId', 'Othr', 'Id', 'NOTPROVIDED');
// If no BIC is provided and we have a DirectDebit document, we must set Othr/Id to NOTPROVIDED
// If we have a Transfer document, we must skip the agent element (cf. https://github.com/kewisch/sepa.js/issues/207)
if (this._type === TransactionTypes.DirectDebit) {
r(txInf, recieverNodeName + 'Agt', 'FinInstnId', 'Othr', 'Id', 'NOTPROVIDED');
}
}

var reciever = n(txInf, recieverNodeName);
Expand Down
150 changes: 150 additions & 0 deletions lib/sepa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,153 @@ describe('xml generation for direct debit documents', () => {
expect(xmlString).toMatch(/^<\?xml version="1.0" encoding="UTF-8"\?>/);
});
});

describe('DbtrAgt and CdtrAgt without BIC', () => {
// cf. https://github.com/kewisch/sepa.js/issues/207
test('pain.001: transaction WITHOUT creditor BIC should NOT include CdtrAgt', () => {
const PAIN = 'pain.001.001.09';
const doc = new SEPA.Document(PAIN);
doc.grpHdr.created = new Date();

const info = doc.createPaymentInfo();
info.requestedExecutionDate = new Date();
info.debtorIBAN = 'DE43500105178994141576';
info.debtorName = 'Debtor';
doc.addPaymentInfo(info);

const tx = info.createTransaction();
tx.creditorName = 'Creditor';
tx.creditorIBAN = 'DE43500105178994141576';
tx.amount = 1.23;
// no creditorBIC set
info.addTransaction(tx);

const dom = doc.toXML();
const select = xpath.useNamespaces({
p: `urn:iso:std:iso:20022:tech:xsd:${PAIN}`,
});

const cdtrAgt = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:CdtTrfTxInf[1]/p:CdtrAgt', dom, true);
expect(cdtrAgt).toBeUndefined();
});

test('pain.001: transaction WITH creditor BIC should include CdtrAgt/BIC', () => {
const PAIN = 'pain.001.001.09';
const doc = new SEPA.Document(PAIN);
doc.grpHdr.created = new Date();

const info = doc.createPaymentInfo();
info.requestedExecutionDate = new Date();
info.debtorIBAN = 'DE43500105178994141576';
info.debtorName = 'Debtor';
doc.addPaymentInfo(info);

const tx = info.createTransaction();
tx.creditorName = 'Creditor';
tx.creditorIBAN = 'DE43500105178994141576';
// use a realistic DE BIC so validation passes
tx.creditorBIC = 'DEUTDEFF';
tx.amount = 1.23;
info.addTransaction(tx);

const dom = doc.toXML();
const select = xpath.useNamespaces({
p: `urn:iso:std:iso:20022:tech:xsd:${PAIN}`,
});

const bic = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:CdtTrfTxInf[1]/p:CdtrAgt/p:FinInstnId/p:BICFI', dom, true);
expect(bic).not.toBeUndefined();
expect(bic.textContent).toBe('DEUTDEFF');
});

test('pain.001: DbtrAgt WITHOUT debtor BIC should include Othr/Id=NOTPROVIDED', () => {
const PAIN = 'pain.001.001.09';
const doc = new SEPA.Document(PAIN);
doc.grpHdr.created = new Date();

const info = doc.createPaymentInfo();
info.requestedExecutionDate = new Date();
info.debtorIBAN = 'DE43500105178994141576';
info.debtorName = 'Debtor';
// no debtorBIC set on payment info
doc.addPaymentInfo(info);

const tx = info.createTransaction();
tx.creditorName = 'Creditor';
tx.creditorIBAN = 'DE43500105178994141576';
tx.amount = 1.23;
info.addTransaction(tx);

const dom = doc.toXML();
const select = xpath.useNamespaces({
p: `urn:iso:std:iso:20022:tech:xsd:${PAIN}`,
});

const id = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:DbtrAgt/p:FinInstnId/p:Othr/p:Id', dom, true);
expect(id).not.toBeUndefined();
expect(id.textContent).toBe('NOTPROVIDED');
});

test('pain.008: transaction WITHOUT debtor BIC should include DbtrAgt Othr/Id=NOTPROVIDED', () => {
const PAIN = 'pain.008.001.08';
const doc = new SEPA.Document(PAIN);
doc.grpHdr.created = new Date();

const info = doc.createPaymentInfo();
info.collectionDate = new Date();
info.creditorIBAN = 'DE43500105178994141576';
info.creditorName = 'Creditor';
doc.addPaymentInfo(info);

const tx = info.createTransaction();
tx.debtorName = 'Debtor';
tx.debtorIBAN = 'DE43500105178994141576';
// Direct debit transactions require mandate information
tx.mandateId = 'MANDATE.1';
tx.mandateSignatureDate = new Date('2020-01-01');
tx.amount = 2.34;
// no debtorBIC set
info.addTransaction(tx);

const dom = doc.toXML();
const select = xpath.useNamespaces({
p: `urn:iso:std:iso:20022:tech:xsd:${PAIN}`,
});

const id = select('/p:Document/p:CstmrDrctDbtInitn/p:PmtInf/p:DrctDbtTxInf[1]/p:DbtrAgt/p:FinInstnId/p:Othr/p:Id', dom, true);
expect(id).not.toBeUndefined();
expect(id.textContent).toBe('NOTPROVIDED');
});

test('pain.008: transaction WITH debtor BIC should include DbtrAgt/BIC', () => {
const PAIN = 'pain.008.001.08';
const doc = new SEPA.Document(PAIN);
doc.grpHdr.created = new Date();

const info = doc.createPaymentInfo();
info.collectionDate = new Date();
info.creditorIBAN = 'DE43500105178994141576';
info.creditorName = 'Creditor';
doc.addPaymentInfo(info);

const tx = info.createTransaction();
tx.debtorName = 'Debtor';
tx.debtorIBAN = 'DE43500105178994141576';
// Direct debit transactions require mandate information
tx.mandateId = 'MANDATE.1';
tx.mandateSignatureDate = new Date('2020-01-01');
// use a realistic DE BIC so validation passes
tx.debtorBIC = 'DEUTDEFF';
tx.amount = 2.34;
info.addTransaction(tx);

const dom = doc.toXML();
const select = xpath.useNamespaces({
p: `urn:iso:std:iso:20022:tech:xsd:${PAIN}`,
});

const bic = select('/p:Document/p:CstmrDrctDbtInitn/p:PmtInf/p:DrctDbtTxInf[1]/p:DbtrAgt/p:FinInstnId/p:BICFI', dom, true);
expect(bic).not.toBeUndefined();
expect(bic.textContent).toBe('DEUTDEFF');
});
});