Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for pain.001.001.09/pain.008.001.08 #68

Merged
merged 2 commits into from
Jul 22, 2024
Merged
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
187 changes: 97 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ omit the first line and include via script-tag or module loader instead.
```javascript
var SEPA = require("sepa");

var doc = new SEPA.Document('pain.008.001.02');
var doc = new SEPA.Document('pain.008.001.08');
doc.grpHdr.id = "XMPL.20140201.TR0";
doc.grpHdr.created = new Date();
doc.grpHdr.initiatorName = "Example LLC";
Expand Down Expand Up @@ -89,7 +89,7 @@ Creating an XML Transfer Document
```javascript
var SEPA = require("sepa");

var doc = new SEPA.Document('pain.001.001.03');
var doc = new SEPA.Document('pain.001.001.09');
doc.grpHdr.id = "XMPL.20140201.TR0";
doc.grpHdr.created = new Date();
doc.grpHdr.initiatorName = "Example LLC";
Expand All @@ -99,15 +99,12 @@ info.requestedExecutionDate = new Date();
info.debtorIBAN = "DE87123456781234567890";
info.debtorBIC = "XMPLDEM0XXX";
info.debtorName = "Example LLC";
info.debtorId = "DE98ZZZ09999999999";
doc.addPaymentInfo(info);

var tx = info.createTransaction();
tx.creditorName = "Example Customer";
tx.creditorIBAN = "DE40987654329876543210";
tx.creditorBIC = "CUSTDEM0XXX";
tx.mandateId = "XMPL.CUST487.2014";
tx.mandateSignatureDate = new Date("2014-02-01");
tx.amount = 50.23;
tx.remittanceInfo = "INVOICE 54";
tx.end2endId = "XMPL.CUST487.INVOICE.54";
Expand All @@ -118,90 +115,100 @@ console.log(doc.toString());

### XML Result
```xml
<?xml version="1.0"?>
<Document schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.008.003.02 pain.008.003.02.xsd">
<CstmrDrctDbtInitn>
<GrpHdr>
<MsgId>XMPL.20140201.TR0</MsgId>
<CreDtTm>2014-01-23T19:16:10.285Z</CreDtTm>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>50.23</CtrlSum>
<InitgPty>
<Nm>Example LLC</Nm>
</InitgPty>
</GrpHdr>
<PmtInf>
<PmtInfId>XMPL.20140201.TR0.0</PmtInfId>
<PmtMtd>DD</PmtMtd>
<BtchBookg>true</BtchBookg>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>50.23</CtrlSum>
<PmtTpInf>
<SvcLvl>
<Cd>SEPA</Cd>
</SvcLvl>
<LclInstrm>
<Cd>CORE</Cd>
</LclInstrm>
<SeqTp>FRST</SeqTp>
</PmtTpInf>
<ReqdColltnDt>2014-01-23</ReqdColltnDt>
<Cdtr>
<Nm>Example LLC</Nm>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>DE87123456781234567890</IBAN>
</Id>
</CdtrAcct>
<CdtrAgt>
<FinInstnId>
<BIC>XMPLDEM0XXX</BIC>
</FinInstnId>
</CdtrAgt>
<ChrgBr>SLEV</ChrgBr>
<CdtrSchmeId>
<Id>
<PrvtId>
<Othr>
<Id>DE98ZZZ09999999999</Id>
<SchmeNm>
<Prtry>SEPA</Prtry>
</SchmeNm>
</Othr>
</PrvtId>
</Id>
</CdtrSchmeId>
<DrctDbtTxInf>
<PmtId>
<EndToEndId>XMPL.CUST487.INVOICE.54</EndToEndId>
</PmtId>
<InstdAmt Ccy="EUR">50.23</InstdAmt>
<DrctDbtTx>
<MndtRltdInf>
<MndtId>XMPL.CUST487.2014</MndtId>
<DtOfSgntr>2014-02-01</DtOfSgntr>
<AmdmntInd>false</AmdmntInd>
</MndtRltdInf>
</DrctDbtTx>
<DbtrAgt>
<FinInstnId>
<BIC>CUSTDEM0XXX</BIC>
</FinInstnId>
</DbtrAgt>
<Dbtr>
<Nm>Example Customer</Nm>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>DE40987654329876543210</IBAN>
</Id>
</DbtrAcct>
<RmtInf>
<Ustrd>INVOICE 54</Ustrd>
</RmtInf>
</DrctDbtTxInf>
</PmtInf>
</CstmrDrctDbtInitn>
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.008.001.08 pain.008.001.08.xsd"
xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.08">
<CstmrDrctDbtInitn>
<GrpHdr>
<MsgId>XMPL.20140201.TR0</MsgId>
<CreDtTm>2024-07-05T11:44:23</CreDtTm>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>50.23</CtrlSum>
<InitgPty>
<Nm>Example LLC</Nm>
</InitgPty>
</GrpHdr>
<PmtInf>
<PmtInfId>XMPL.20140201.TR0.0</PmtInfId>
<PmtMtd>DD</PmtMtd>
<BtchBookg>true</BtchBookg>
<NbOfTxs>1</NbOfTxs>
<CtrlSum>50.23</CtrlSum>
<PmtTpInf>
<SvcLvl>
<Cd>SEPA</Cd>
</SvcLvl>
<LclInstrm>
<Cd>CORE</Cd>
</LclInstrm>
<SeqTp>FRST</SeqTp>
</PmtTpInf>
<ReqdColltnDt>2024-07-05</ReqdColltnDt>
<Cdtr>
<Nm>Example LLC</Nm>
<Id>
<PrvtId>
<Othr>
<Id>DE98ZZZ09999999999</Id>
</Othr>
</PrvtId>
</Id>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>DE87123456781234567890</IBAN>
</Id>
</CdtrAcct>
<CdtrAgt>
<FinInstnId>
<BICFI>XMPLDEM0XXX</BICFI>
</FinInstnId>
</CdtrAgt>
<ChrgBr>SLEV</ChrgBr>
<CdtrSchmeId>
<Id>
<PrvtId>
<Othr>
<Id>DE98ZZZ09999999999</Id>
<SchmeNm>
<Prtry>SEPA</Prtry>
</SchmeNm>
</Othr>
</PrvtId>
</Id>
</CdtrSchmeId>
<DrctDbtTxInf>
<PmtId>
<InstrId>XMPL.20140201.TR0.0.0</InstrId>
<EndToEndId>XMPL.CUST487.INVOICE.54</EndToEndId>
</PmtId>
<InstdAmt Ccy="EUR">50.23</InstdAmt>
<DrctDbtTx>
<MndtRltdInf>
<MndtId>XMPL.CUST487.2014</MndtId>
<DtOfSgntr>2014-02-01</DtOfSgntr>
<AmdmntInd>false</AmdmntInd>
</MndtRltdInf>
</DrctDbtTx>
<DbtrAgt>
<FinInstnId>
<BICFI>CUSTDEM0XXX</BICFI>
</FinInstnId>
</DbtrAgt>
<Dbtr>
<Nm>Example Customer</Nm>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>DE40987654329876543210</IBAN>
</Id>
</DbtrAcct>
<RmtInf>
<Ustrd>INVOICE 54</Ustrd>
</RmtInf>
</DrctDbtTxInf>
</PmtInf>
</CstmrDrctDbtInitn>
</Document>
```
96 changes: 96 additions & 0 deletions lib/schema.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
var fs = require('fs');
var SEPA = require('./sepa.js');
var validateSchema = require('xsd-validator').default;

expect.extend({
toMatchSchema(xml, format) {
const schema = fs.readFileSync('schema/' + format + '.xsd');

const res = validateSchema(xml, schema);

if (res === true) {
return {
message: () =>
'expected to match schema for ' + format,
pass: true,
};
} else {
return {
message: () =>
'expected to match schema for ' + format + ': \n' + res.join('\n'),
pass: false,
};
}
},
});

describe('transfer schema validation tests',
() => {
test.each([
'pain.001.001.02',
'pain.001.001.03',
'pain.001.001.08',
'pain.001.001.09',
])('%p schema matches', (format) => {
var doc = new SEPA.Document(format);
doc.grpHdr.id = 'XMPL.20140201.TR0';
doc.grpHdr.created = new Date();
doc.grpHdr.initiatorName = 'Example LLC';

var info = doc.createPaymentInfo();
info.requestedExecutionDate = new Date();
info.debtorIBAN = 'DE87123456781234567890';
info.debtorBIC = 'CUSTDEM0XXX';
info.debtorName = 'Example LLC';
doc.addPaymentInfo(info);

var tx = info.createTransaction();
tx.creditorName = 'Example Customer';
tx.creditorIBAN = 'DE40987654329876543210';
tx.creditorBIC = 'CUSTDEM0XXX';
tx.amount = 50.23;
tx.remittanceInfo = 'INVOICE 54';
tx.end2endId = 'XMPL.CUST487.INVOICE.54';
info.addTransaction(tx);

const validation = validateSchema(doc.toString(), fs.readFileSync('schema/' + format + '.xsd'));
expect(validation).toBe(true);
});
});

describe('direct debit validation tests',
() => {
test.each([
'pain.008.001.02',
'pain.008.001.08',
])('%p schema matches', (format) => {
var doc = new SEPA.Document(format);
doc.grpHdr.id = 'XMPL.20140201.TR0';
doc.grpHdr.created = new Date();
doc.grpHdr.initiatorName = 'Example LLC';

var info = doc.createPaymentInfo();
info.collectionDate = new Date();
info.creditorIBAN = 'DE87123456781234567890';
info.creditorBIC = 'XMPLDEM0XXX';
info.creditorName = 'Example LLC';
info.creditorId = 'DE98ZZZ09999999999';
info.batchBooking = true; //optional
doc.addPaymentInfo(info);

var tx = info.createTransaction();
tx.debtorName = 'Example Customer';
tx.debtorIBAN = 'DE40987654329876543210';
tx.debtorBIC = 'CUSTDEM0XXX';
tx.mandateId = 'XMPL.CUST487.2014';
tx.mandateSignatureDate = new Date('2014-02-01');
tx.amount = 50.23;
tx.currency = 'EUR'; //optional
tx.remittanceInfo = 'INVOICE 54';
tx.end2endId = 'XMPL.CUST487.INVOICE.54';
info.addTransaction(tx);

const validation = validateSchema(doc.toString(), fs.readFileSync('schema/' + format + '.xsd'));
expect(validation).toBe(true);
});
});
Loading
Loading