node-ebics-client/lib/OrderBuilder.js

81 lines
1.7 KiB
JavaScript
Raw Normal View History

'use strict';
const crypto = require('crypto');
// const orderTypes = ['ini', 'download', 'upload', 'zip'];
module.exports = class OrderBuilder {
constructor() {
this._transactionKey = crypto.randomBytes(16);
2018-06-11 12:25:07 +00:00
this._root = {};
this._body = {};
}
details(data) {
this._data = data;
this._data.transactionId = null;
return this;
}
2018-06-11 12:25:07 +00:00
payment() {
this._type = 'payment';
2018-06-11 12:25:07 +00:00
return this;
}
2018-06-11 12:25:07 +00:00
status() {
this._type = 'status';
2018-06-11 12:25:07 +00:00
return this;
}
2018-06-11 12:25:07 +00:00
ini() {
this._type = 'ini';
this._root.nodeName = 'ebicsUnsecuredRequest';
return this;
}
2018-06-11 12:25:07 +00:00
static h004() {
const builder = new OrderBuilder();
2018-06-11 12:25:07 +00:00
builder._version = 'H004';
builder._root.nodeName = 'ebicsRequest';
builder._root.nodeAttributes = {
'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
xmlns: 'urn:org:ebics:H004',
Version: 'H004',
Revision: '1',
};
return builder;
}
/**
* Getters
*/
get type() { return this._type; }
get root() { return this._root; }
get body() { return this._body; }
get data() { return this._data; }
get orderDetails() { return this._data.orderDetails; }
get transactionId() { return this._data.transactionId; }
get document() { return this._data.document; }
get transactionKey() { return this._transactionKey; }
get ebicsData() { return this._data.ebicsData; }
get hostId() { return this._data.ebicsData.hostId; }
get partnerId() { return this._data.ebicsData.partnerId; }
get userId() { return this._data.ebicsData.userId; }
get keys() { return this._data.ebicsData.keysManager.keys(); }
2018-06-11 12:25:07 +00:00
get version() { return this._version; }
set transactionId(tid) {
this._data.transactionId = tid === '' ? null : tid;
}
hasTransactionId() {
return this.transactionId !== null;
}
};