chore(download): Add support for segmented download

This commit is contained in:
Vlad Gramuzov
2021-05-14 01:16:50 +03:00
parent fe0f585b27
commit 59515f21e3
4 changed files with 70 additions and 29 deletions

View File

@@ -13,7 +13,7 @@ module.exports = {
userId: client.userId,
hostId: client.hostId,
};
const { orderDetails, transactionId } = order;
const { orderDetails, transactionId, segmentNumber } = order;
const {
rootName, xmlOptions, xmlSchema, receipt, transfer, productString,
} = genericSerializer(client.hostId, transactionId);
@@ -25,35 +25,46 @@ module.exports = {
this.receipt = receipt;
this.transfer = transfer;
if (transactionId) return this.receipt();
if (!segmentNumber && transactionId) return this.receipt();
this.xmlSchema.header = {
'@': { authenticate: true },
static: {
HostID: ebicsAccount.hostId,
Nonce: Crypto.nonce(),
Timestamp: Crypto.timestamp(),
PartnerID: ebicsAccount.partnerId,
UserID: ebicsAccount.userId,
Product: {
'@': { Language: 'en' },
'#': productString,
},
OrderDetails: orderDetails,
BankPubKeyDigests: {
Authentication: {
'@': { Version: 'X002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256' },
'#': Crypto.digestPublicKey(keys.bankX()),
...!transactionId && {
Nonce: Crypto.nonce(),
Timestamp: Crypto.timestamp(),
PartnerID: ebicsAccount.partnerId,
UserID: ebicsAccount.userId,
Product: {
'@': { Language: 'en' },
'#': productString,
},
Encryption: {
'@': { Version: 'E002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256' },
'#': Crypto.digestPublicKey(keys.bankE()),
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',
},
...transactionId && {
TransactionID: transactionId,
},
SecurityMedium: '0000',
},
mutable: {
TransactionPhase: 'Initialisation',
TransactionPhase: segmentNumber ? 'Transfer' : 'Initialisation',
...segmentNumber && {
SegmentNumber: {
'@': { lastSegment: false },
'#': segmentNumber,
},
},
},
};