node-ebics-client/lib/orders/H004/serializers/download.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

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,
};
const { orderDetails, transactionId } = 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;
if (transactionId) return this.receipt();
this.xmlSchema.header = {
'@': { authenticate: true },
static: {
2018-06-20 09:20:03 +00:00
HostID: ebicsAccount.hostId,
2018-06-15 06:33:41 +00:00
Nonce: Crypto.nonce(),
Timestamp: Crypto.timestamp(),
2018-06-20 09:20:03 +00:00
PartnerID: ebicsAccount.partnerId,
UserID: ebicsAccount.userId,
2018-06-15 06:33:41 +00:00
Product: {
'@': { Language: 'en' },
'#': productString,
},
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()),
},
},
SecurityMedium: '0000',
},
mutable: {
TransactionPhase: 'Initialisation',
},
};
return this;
},
toXML() {
return js2xmlparser.parse(this.rootName, this.xmlSchema, this.xmlOptions);
},
};