wallee
Version:
TypeScript/JavaScript client for wallee
235 lines (234 loc) • 10.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionTerminalService = void 0;
const Promise = require("bluebird");
const axios = require("axios");
const HMACAuthentication_1 = require("../auth/HMACAuthentication");
const ObjectSerializer_1 = require("../serializers/ObjectSerializer");
const ClientError_1 = require("../models/ClientError");
const ServerError_1 = require("../models/ServerError");
class TransactionTerminalService {
constructor(configuration) {
this._basePath = 'https://app-wallee.com:443/api';
this._defaultHeaders = {};
this._useQuerystring = false;
this._timeout = 25;
this._defaultAuthentication = new HMACAuthentication_1.HMACAuthentication(configuration).apply;
this._defaultHeaders = configuration.default_headers;
this.setTimeout(configuration.timeout);
}
/**
* Set timeout in seconds. Default timeout: 25 seconds
* @param {number} timeout
*/
set timeout(timeout) {
this.setTimeout(timeout);
}
setTimeout(timeout) {
if (timeout !== undefined) {
if (!Number.isInteger(timeout)) {
throw new Error('Timeout value has to be integer');
}
if (timeout) {
this._timeout = timeout;
}
else {
throw new Error('Timeout value has to be greater than 0');
}
}
}
set basePath(basePath) {
this._basePath = basePath;
}
get basePath() {
return this._basePath;
}
setDefaultAuthentication(auth) {
this._defaultAuthentication = auth;
}
getVersion() {
if (typeof (process) !== 'undefined' && process && process.version) {
return 'node ' + process.version;
}
else {
return 'unknown';
}
}
/**
* Returns all receipts for the requested terminal transaction.
* @summary Fetch Receipts
* @param spaceId
* @param request
* @param {*} [options] Override http request options.
*/
fetchReceipts(spaceId, request, options = {}) {
const url = '/transaction-terminal/fetch-receipts';
let queryParams = {};
let headers = Object.assign({}, this._defaultHeaders);
// verify required parameter 'spaceId' is not null or undefined
if (spaceId === null || spaceId === undefined) {
throw new Error('Required parameter spaceId was null or undefined when calling fetchReceipts.');
}
// verify required parameter 'request' is not null or undefined
if (request === null || request === undefined) {
throw new Error('Required parameter request was null or undefined when calling fetchReceipts.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
headers['Content-Type'] = 'application/json;charset=utf-8';
Object.assign(headers, options.headers);
let defaultHeaders = {
"x-meta-sdk-version": "4.7.0",
"x-meta-sdk-language": "typescript",
"x-meta-sdk-provider": "wallee",
"x-meta-sdk-language-version": this.getVersion(),
};
Object.assign(headers, defaultHeaders);
let requestConfig = {
url,
method: 'POST',
baseURL: this._basePath,
headers,
params: queryParams,
data: request,
timeout: this._timeout * 1000,
responseType: 'json',
};
const axiosInstance = axios.default.create();
axiosInstance.interceptors.request.use(this._defaultAuthentication);
return new Promise((resolve, reject) => {
axiosInstance.request(requestConfig)
.then(success => {
let body;
body = ObjectSerializer_1.ObjectSerializer.deserialize(success.data, "Array<RenderedTerminalReceipt>");
return resolve({ response: success.request.res, body: body });
}, failure => {
var _a, _b, _c, _d, _e;
let errorObject;
if ((_a = failure.response) === null || _a === void 0 ? void 0 : _a.status) {
if (failure.response.status >= 400 && failure.response.status <= 499) {
errorObject = new ClientError_1.ClientError();
}
else if (failure.response.status >= 500 && failure.response.status <= 599) {
errorObject = new ServerError_1.ServerError();
}
else {
errorObject = new Object();
}
}
else {
errorObject = new Object();
}
return reject({
errorType: errorObject.constructor.name,
date: (new Date()).toDateString(),
statusCode: ((_b = failure.response) === null || _b === void 0 ? void 0 : _b.status) && isNaN(failure.response.status) ? String(failure.response.status) : "Unknown",
statusMessage: ((_c = failure.response) === null || _c === void 0 ? void 0 : _c.statusText) != null ? failure.response.statusText : "Unknown",
body: (_d = failure.response) === null || _d === void 0 ? void 0 : _d.data,
response: (_e = failure.response) === null || _e === void 0 ? void 0 : _e.request.res
});
})
.catch(error => {
return reject(error);
});
});
}
;
/**
* This operation creates a set of credentials to use within the WebSocket.
* @summary Create Till Connection Credentials
* @param spaceId
* @param transactionId The ID of the transaction which is used to process with the terminal.
* @param terminalId The ID of the terminal which should be used to process the transaction.
* @param language The language in which the messages should be rendered in.
* @param {*} [options] Override http request options.
*/
tillConnectionCredentials(spaceId, transactionId, terminalId, language, options = {}) {
const url = '/transaction-terminal/till-connection-credentials';
let queryParams = {};
let headers = Object.assign({}, this._defaultHeaders);
// verify required parameter 'spaceId' is not null or undefined
if (spaceId === null || spaceId === undefined) {
throw new Error('Required parameter spaceId was null or undefined when calling tillConnectionCredentials.');
}
// verify required parameter 'transactionId' is not null or undefined
if (transactionId === null || transactionId === undefined) {
throw new Error('Required parameter transactionId was null or undefined when calling tillConnectionCredentials.');
}
// verify required parameter 'terminalId' is not null or undefined
if (terminalId === null || terminalId === undefined) {
throw new Error('Required parameter terminalId was null or undefined when calling tillConnectionCredentials.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
if (transactionId !== undefined) {
queryParams['transactionId'] = ObjectSerializer_1.ObjectSerializer.serialize(transactionId, "number");
}
if (terminalId !== undefined) {
queryParams['terminalId'] = ObjectSerializer_1.ObjectSerializer.serialize(terminalId, "number");
}
if (language !== undefined) {
queryParams['language'] = ObjectSerializer_1.ObjectSerializer.serialize(language, "string");
}
headers['Content-Type'] = 'application/json';
Object.assign(headers, options.headers);
let defaultHeaders = {
"x-meta-sdk-version": "4.7.0",
"x-meta-sdk-language": "typescript",
"x-meta-sdk-provider": "wallee",
"x-meta-sdk-language-version": this.getVersion(),
};
Object.assign(headers, defaultHeaders);
let requestConfig = {
url,
method: 'POST',
baseURL: this._basePath,
headers,
params: queryParams,
timeout: this._timeout * 1000,
responseType: 'json',
};
const axiosInstance = axios.default.create();
axiosInstance.interceptors.request.use(this._defaultAuthentication);
return new Promise((resolve, reject) => {
axiosInstance.request(requestConfig)
.then(success => {
let body;
body = ObjectSerializer_1.ObjectSerializer.deserialize(success.data, "string");
return resolve({ response: success.request.res, body: body });
}, failure => {
var _a, _b, _c, _d, _e;
let errorObject;
if ((_a = failure.response) === null || _a === void 0 ? void 0 : _a.status) {
if (failure.response.status >= 400 && failure.response.status <= 499) {
errorObject = new ClientError_1.ClientError();
}
else if (failure.response.status >= 500 && failure.response.status <= 599) {
errorObject = new ServerError_1.ServerError();
}
else {
errorObject = new Object();
}
}
else {
errorObject = new Object();
}
return reject({
errorType: errorObject.constructor.name,
date: (new Date()).toDateString(),
statusCode: ((_b = failure.response) === null || _b === void 0 ? void 0 : _b.status) && isNaN(failure.response.status) ? String(failure.response.status) : "Unknown",
statusMessage: ((_c = failure.response) === null || _c === void 0 ? void 0 : _c.statusText) != null ? failure.response.statusText : "Unknown",
body: (_d = failure.response) === null || _d === void 0 ? void 0 : _d.data,
response: (_e = failure.response) === null || _e === void 0 ? void 0 : _e.request.res
});
})
.catch(error => {
return reject(error);
});
});
}
;
}
exports.TransactionTerminalService = TransactionTerminalService;