2018-06-15 06:33:41 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const js2xmlparser = require('js2xmlparser');
|
|
|
|
|
|
|
|
const Crypto = require('../../../crypto/Crypto');
|
|
|
|
const genericSerializer = require('./generic');
|
|
|
|
|
|
|
|
module.exports = {
|
2018-06-27 14:59:35 +00:00
|
|
|
async use(order, client) {
|
|
|
|
const keys = await client.keys();
|
2018-06-20 09:20:03 +00:00
|
|
|
const ebicsAccount = {
|
|
|
|
partnerId: client.partnerId,
|
|
|
|
userId: client.userId,
|
|
|
|
hostId: client.hostId,
|
|
|
|
};
|
2021-05-13 22:16:50 +00:00
|
|
|
const { orderDetails, transactionId, segmentNumber } = order;
|
2018-06-15 06:33:41 +00:00
|
|
|
const {
|
2018-06-20 09:20:03 +00:00
|
|
|
rootName, xmlOptions, xmlSchema, receipt, transfer, productString,
|
|
|
|
} = genericSerializer(client.hostId, transactionId);
|
2018-06-15 06:33:41 +00:00
|
|
|
|
2018-06-20 09:20:03 +00:00
|
|
|
this.productString = productString;
|
2018-06-15 06:33:41 +00:00
|
|
|
this.rootName = rootName;
|
|
|
|
this.xmlOptions = xmlOptions;
|
|
|
|
this.xmlSchema = xmlSchema;
|
|
|
|
this.receipt = receipt;
|
|
|
|
this.transfer = transfer;
|
|
|
|
|
2021-05-13 22:16:50 +00:00
|
|
|
if (!segmentNumber && transactionId) return this.receipt();
|
2018-06-15 06:33:41 +00:00
|
|
|
|
|
|
|
this.xmlSchema.header = {
|
|
|
|
'@': { authenticate: true },
|
|
|
|
static: {
|
2018-06-20 09:20:03 +00:00
|
|
|
HostID: ebicsAccount.hostId,
|
2021-05-13 22:16:50 +00:00
|
|
|
...!transactionId && {
|
|
|
|
Nonce: Crypto.nonce(),
|
|
|
|
Timestamp: Crypto.timestamp(),
|
|
|
|
PartnerID: ebicsAccount.partnerId,
|
|
|
|
UserID: ebicsAccount.userId,
|
|
|
|
Product: {
|
|
|
|
'@': { Language: 'en' },
|
|
|
|
'#': productString,
|
2018-06-15 06:33:41 +00:00
|
|
|
},
|
2021-05-13 22:16:50 +00:00
|
|
|
OrderDetails: orderDetails,
|
|
|
|
BankPubKeyDigests: {
|
|
|
|
Authentication: {
|
|
|
|
'@': { Version: 'X002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256' },
|
|
|
|
'#': Crypto.digestPublicKey(keys.bankX()),
|
|
|
|
},
|
|
|
|
Encryption: {
|
|
|
|
'@': { Version: 'E002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256' },
|
|
|
|
'#': Crypto.digestPublicKey(keys.bankE()),
|
|
|
|
},
|
2018-06-15 06:33:41 +00:00
|
|
|
},
|
2021-05-13 22:16:50 +00:00
|
|
|
SecurityMedium: '0000',
|
|
|
|
},
|
|
|
|
...transactionId && {
|
|
|
|
TransactionID: transactionId,
|
2018-06-15 06:33:41 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
mutable: {
|
2021-05-13 22:16:50 +00:00
|
|
|
TransactionPhase: segmentNumber ? 'Transfer' : 'Initialisation',
|
|
|
|
...segmentNumber && {
|
|
|
|
SegmentNumber: {
|
|
|
|
'@': { lastSegment: false },
|
|
|
|
'#': segmentNumber,
|
|
|
|
},
|
|
|
|
},
|
2018-06-15 06:33:41 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
toXML() {
|
|
|
|
return js2xmlparser.parse(this.rootName, this.xmlSchema, this.xmlOptions);
|
|
|
|
},
|
|
|
|
};
|