mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2025-12-15 16:21:26 +00:00
client and order optimization
This commit is contained in:
@@ -8,7 +8,7 @@ const Crypto = require('../../../crypto/Crypto');
|
||||
|
||||
const genericSerializer = require('./generic');
|
||||
|
||||
const keySignature = (ebicsData, key, xmlOptions) => {
|
||||
const keySignature = (ebicsAccount, key, xmlOptions) => {
|
||||
const xmlOrderData = {
|
||||
'@': {
|
||||
'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
|
||||
@@ -24,13 +24,13 @@ const keySignature = (ebicsData, key, xmlOptions) => {
|
||||
},
|
||||
SignatureVersion: 'A006',
|
||||
},
|
||||
PartnerID: ebicsData.partnerId,
|
||||
UserID: ebicsData.userId,
|
||||
PartnerID: ebicsAccount.partnerId,
|
||||
UserID: ebicsAccount.userId,
|
||||
};
|
||||
|
||||
return js2xmlparser.parse('SignaturePubKeyOrderData', xmlOrderData, xmlOptions);
|
||||
};
|
||||
const orderData = (ebicsData, keys, xmlOptions) => {
|
||||
const orderData = (ebicsAccount, keys, xmlOptions) => {
|
||||
const xmlOrderData = {
|
||||
'@': {
|
||||
'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
|
||||
@@ -54,20 +54,20 @@ const orderData = (ebicsData, keys, xmlOptions) => {
|
||||
},
|
||||
EncryptionVersion: 'E002',
|
||||
},
|
||||
PartnerID: ebicsData.partnerId,
|
||||
UserID: ebicsData.userId,
|
||||
PartnerID: ebicsAccount.partnerId,
|
||||
UserID: ebicsAccount.userId,
|
||||
};
|
||||
|
||||
return js2xmlparser.parse('HIARequestOrderData', xmlOrderData, xmlOptions);
|
||||
};
|
||||
const commonHeader = (ebicsData, orderDetails, productString) => ({
|
||||
const commonHeader = (ebicsAccount, orderDetails, productString) => ({
|
||||
'@': { authenticate: true },
|
||||
static: {
|
||||
HostID: ebicsData.hostId,
|
||||
HostID: ebicsAccount.hostId,
|
||||
Nonce: Crypto.nonce(),
|
||||
Timestamp: Crypto.timestamp(),
|
||||
PartnerID: ebicsData.partnerId,
|
||||
UserID: ebicsData.userId,
|
||||
PartnerID: ebicsAccount.partnerId,
|
||||
UserID: ebicsAccount.userId,
|
||||
Product: {
|
||||
'@': { Language: 'en' },
|
||||
'#': productString,
|
||||
@@ -80,57 +80,61 @@ const commonHeader = (ebicsData, orderDetails, productString) => ({
|
||||
const process = {
|
||||
INI: {
|
||||
rootName: 'ebicsUnsecuredRequest',
|
||||
header: (ebicsData, orderDetails, productString) => {
|
||||
const ch = commonHeader(ebicsData, orderDetails, productString);
|
||||
header: (ebicsAccount, orderDetails, productString) => {
|
||||
const ch = commonHeader(ebicsAccount, orderDetails, productString);
|
||||
|
||||
delete ch.static.Nonce;
|
||||
delete ch.static.Timestamp;
|
||||
|
||||
return ch;
|
||||
},
|
||||
body: (ebicsData, keys, xmlOptions) => ({
|
||||
body: (ebicsAccount, keys, xmlOptions) => ({
|
||||
DataTransfer: {
|
||||
OrderData: Buffer.from(zlib.deflateSync(keySignature(ebicsData, keys.a(), xmlOptions))).toString('base64'),
|
||||
OrderData: Buffer.from(zlib.deflateSync(keySignature(ebicsAccount, keys.a(), xmlOptions))).toString('base64'),
|
||||
},
|
||||
}),
|
||||
},
|
||||
HIA: {
|
||||
rootName: 'ebicsUnsecuredRequest',
|
||||
header: (ebicsData, orderDetails, productString) => {
|
||||
const ch = commonHeader(ebicsData, orderDetails, productString);
|
||||
header: (ebicsAccount, orderDetails, productString) => {
|
||||
const ch = commonHeader(ebicsAccount, orderDetails, productString);
|
||||
|
||||
delete ch.static.Nonce;
|
||||
delete ch.static.Timestamp;
|
||||
|
||||
return ch;
|
||||
},
|
||||
body: (ebicsData, keys, xmlOptions) => ({
|
||||
body: (ebicsAccount, keys, xmlOptions) => ({
|
||||
DataTransfer: {
|
||||
OrderData: Buffer.from(zlib.deflateSync(orderData(ebicsData, keys, xmlOptions))).toString('base64'),
|
||||
OrderData: Buffer.from(zlib.deflateSync(orderData(ebicsAccount, keys, xmlOptions))).toString('base64'),
|
||||
},
|
||||
}),
|
||||
},
|
||||
HPB: {
|
||||
rootName: 'ebicsNoPubKeyDigestsRequest',
|
||||
header: (ebicsData, orderDetails, productString) => commonHeader(ebicsData, orderDetails, productString),
|
||||
header: (ebicsAccount, orderDetails, productString) => commonHeader(ebicsAccount, orderDetails, productString),
|
||||
body: () => ({}),
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
use(orderBuilder) {
|
||||
const { xmlOptions, xmlSchema } = genericSerializer(orderBuilder);
|
||||
const {
|
||||
ebicsData, orderDetails, keys, productString,
|
||||
} = orderBuilder;
|
||||
use(order, client) {
|
||||
const keys = client.keys();
|
||||
const { orderDetails, transactionId } = order;
|
||||
const { xmlOptions, xmlSchema, productString } = genericSerializer(client.host, transactionId);
|
||||
const orderType = orderDetails.OrderType.toUpperCase();
|
||||
const ebicsAccount = {
|
||||
partnerId: client.partnerId,
|
||||
userId: client.userId,
|
||||
hostId: client.hostId,
|
||||
};
|
||||
|
||||
this.rootName = process[orderType].rootName;
|
||||
this.xmlOptions = xmlOptions;
|
||||
this.xmlSchema = xmlSchema;
|
||||
|
||||
this.xmlSchema.header = process[orderType].header(ebicsData, orderDetails, productString);
|
||||
this.xmlSchema.body = process[orderType].body(ebicsData, keys, this.xmlOptions);
|
||||
this.xmlSchema.header = process[orderType].header(ebicsAccount, orderDetails, productString);
|
||||
this.xmlSchema.body = process[orderType].body(ebicsAccount, keys, this.xmlOptions);
|
||||
|
||||
if (orderType !== 'HPB' && Object.prototype.hasOwnProperty.call(this.xmlSchema, 'AuthSignature'))
|
||||
delete this.xmlSchema.AuthSignature;
|
||||
|
||||
Reference in New Issue
Block a user