2018-05-17 15:03:59 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// const randHex = require('../../lib/utils').randHex;
|
2018-06-01 13:16:43 +00:00
|
|
|
const crypto = require('crypto');
|
2018-05-17 15:03:59 +00:00
|
|
|
const js2xmlparser = require('js2xmlparser');
|
2018-06-01 13:16:43 +00:00
|
|
|
const consts = require('../consts');
|
|
|
|
|
|
|
|
const authSignature = () => {
|
|
|
|
return {
|
|
|
|
'ds:SignedInfo': {
|
|
|
|
'ds:CanonicalizationMethod': {
|
|
|
|
'@': {
|
|
|
|
Algorithm:
|
|
|
|
'http://www.w3.org/TR/2001/REC-xml-c14n-20010315',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'ds:SignatureMethod': {
|
|
|
|
'@': {
|
|
|
|
Algorithm:
|
|
|
|
'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'ds:Reference': {
|
|
|
|
'@': { URI: "#xpointer(//*[@authenticate='true'])" },
|
|
|
|
'ds:Transforms': {
|
|
|
|
'ds:Transform': {
|
|
|
|
'@': {
|
|
|
|
Algorithm:
|
|
|
|
'http://www.w3.org/TR/2001/REC-xml-c14n-20010315',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'ds:DigestMethod': {
|
|
|
|
'@': {
|
|
|
|
Algorithm:
|
|
|
|
'http://www.w3.org/2001/04/xmlenc#sha256',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'ds:DigestValue': {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'ds:SignatureValue': {},
|
|
|
|
};
|
|
|
|
};
|
2018-05-17 15:03:59 +00:00
|
|
|
module.exports = class GenericOrder {
|
|
|
|
constructor(client) {
|
|
|
|
this.client = client;
|
|
|
|
|
|
|
|
this.hostId = client.hostId;
|
|
|
|
this.userId = client.userId;
|
|
|
|
this.partnerId = client.partnerId;
|
|
|
|
|
|
|
|
this.transactionId = '';
|
|
|
|
|
|
|
|
this.xmlOptions = {
|
|
|
|
declaration: {
|
|
|
|
include: true,
|
2018-06-01 13:16:43 +00:00
|
|
|
encoding: 'utf-8',
|
2018-05-17 15:03:59 +00:00
|
|
|
},
|
|
|
|
format: {
|
|
|
|
doubleQuotes: true,
|
|
|
|
indent: '',
|
|
|
|
newline: '',
|
2018-06-01 13:16:43 +00:00
|
|
|
pretty: true,
|
|
|
|
},
|
2018-05-17 15:03:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this._schema = {
|
2018-06-01 13:16:43 +00:00
|
|
|
'@': {
|
|
|
|
'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
|
|
|
|
xmlns: 'urn:org:ebics:H004',
|
|
|
|
Version: 'H004',
|
|
|
|
Revision: '1',
|
2018-05-17 15:03:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
header: {},
|
|
|
|
|
2018-06-01 13:16:43 +00:00
|
|
|
AuthSignature: authSignature(),
|
2018-05-17 15:03:59 +00:00
|
|
|
|
2018-06-01 13:16:43 +00:00
|
|
|
body: {},
|
2018-05-17 15:03:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get schema() {
|
|
|
|
return this._schema;
|
|
|
|
}
|
|
|
|
|
2018-06-01 13:16:43 +00:00
|
|
|
static get productString() {
|
2018-05-17 15:03:59 +00:00
|
|
|
return consts.productString;
|
|
|
|
}
|
|
|
|
|
2018-06-01 13:16:43 +00:00
|
|
|
static nonce() {
|
2018-05-17 15:03:59 +00:00
|
|
|
return crypto.randomBytes(16).toString('hex');
|
|
|
|
}
|
|
|
|
|
2018-06-01 13:16:43 +00:00
|
|
|
// TODO: remove eslint-disable-line
|
|
|
|
timestamp() { // eslint-disable-line
|
2018-05-17 15:03:59 +00:00
|
|
|
return new Date().toISOString();
|
|
|
|
}
|
|
|
|
|
2018-06-01 13:16:43 +00:00
|
|
|
root() { // eslint-disable-line class-methods-use-this
|
|
|
|
return 'ebicsRequest';
|
2018-05-17 15:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toReceiptXML() {
|
|
|
|
const xmlObj = {
|
2018-06-01 13:16:43 +00:00
|
|
|
'@': {
|
|
|
|
'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
|
|
|
|
xmlns: 'urn:org:ebics:H004',
|
|
|
|
Version: 'H004',
|
|
|
|
Revision: '1',
|
2018-05-17 15:03:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
header: {
|
2018-06-01 13:16:43 +00:00
|
|
|
'@': { authenticate: true },
|
2018-05-17 15:03:59 +00:00
|
|
|
static: {
|
|
|
|
HostID: this.hostId,
|
2018-06-01 13:16:43 +00:00
|
|
|
TransactionID: this.transactionId,
|
2018-05-17 15:03:59 +00:00
|
|
|
},
|
|
|
|
mutable: {
|
|
|
|
TransactionPhase: 'Receipt',
|
2018-06-01 13:16:43 +00:00
|
|
|
},
|
2018-05-17 15:03:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
AuthSignature: this.authSignature(),
|
|
|
|
|
|
|
|
body: {
|
|
|
|
TransferReceipt: {
|
2018-06-01 13:16:43 +00:00
|
|
|
'@': { authenticate: true },
|
|
|
|
ReceiptCode: 0,
|
|
|
|
},
|
|
|
|
},
|
2018-05-17 15:03:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return js2xmlparser.parse(this.root(), xmlObj, this.xmlOptions);
|
|
|
|
}
|
|
|
|
|
2018-06-01 13:16:43 +00:00
|
|
|
toTransferXML() {
|
2018-05-31 09:01:21 +00:00
|
|
|
const xmlObj = {
|
2018-06-01 13:16:43 +00:00
|
|
|
'@': {
|
|
|
|
'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
|
|
|
|
xmlns: 'urn:org:ebics:H004',
|
|
|
|
Version: 'H004',
|
|
|
|
Revision: '1',
|
2018-05-31 09:01:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
header: {
|
2018-06-01 13:16:43 +00:00
|
|
|
'@': { authenticate: true },
|
2018-05-31 09:01:21 +00:00
|
|
|
static: {
|
|
|
|
HostID: this.hostId,
|
2018-06-01 13:16:43 +00:00
|
|
|
TransactionID: this.transactionId,
|
2018-05-31 09:01:21 +00:00
|
|
|
},
|
|
|
|
mutable: {
|
|
|
|
TransactionPhase: 'Transfer',
|
|
|
|
SegmentNumber: {
|
2018-06-01 13:16:43 +00:00
|
|
|
'@': { lastSegment: true },
|
|
|
|
'#': 1,
|
|
|
|
},
|
|
|
|
},
|
2018-05-31 09:01:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
AuthSignature: this.authSignature(),
|
|
|
|
|
|
|
|
body: {
|
|
|
|
DataTransfer: {
|
2018-06-01 13:16:43 +00:00
|
|
|
OrderData: this.encryptedOrderData(),
|
|
|
|
},
|
|
|
|
},
|
2018-05-31 09:01:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return js2xmlparser.parse(this.root(), xmlObj, this.xmlOptions);
|
|
|
|
}
|
|
|
|
|
2018-06-01 13:16:43 +00:00
|
|
|
encryptedOrderData() { // eslint-disable-line class-methods-use-this
|
|
|
|
return null;
|
2018-05-31 09:01:21 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 15:03:59 +00:00
|
|
|
toXML() {
|
|
|
|
return js2xmlparser.parse(this.root(), this._schema, this.xmlOptions);
|
|
|
|
}
|
|
|
|
};
|