wallee
Version:
TypeScript/JavaScript client for wallee
995 lines (994 loc) • 48.5 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscriptionService = 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 SubscriptionService {
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';
}
}
/**
* This operation allows to apply changes on a subscription.
* @summary apply changes
* @param spaceId
* @param request
* @param {*} [options] Override http request options.
*/
applyChanges(spaceId, request, options = {}) {
const url = '/subscription/applyChanges';
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 applyChanges.');
}
// 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 applyChanges.');
}
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, "SubscriptionVersion");
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);
});
});
}
;
/**
* Counts the number of items in the database as restricted by the given filter.
* @summary Count
* @param spaceId
* @param filter The filter which restricts the entities which are used to calculate the count.
* @param {*} [options] Override http request options.
*/
count(spaceId, filter, options = {}) {
const url = '/subscription/count';
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 count.');
}
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: filter,
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, "number");
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);
});
});
}
;
/**
* The create operation creates a new subscription and a corresponding subscription version.
* @summary Create
* @param spaceId
* @param createRequest
* @param {*} [options] Override http request options.
*/
create(spaceId, createRequest, options = {}) {
const url = '/subscription/create';
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 create.');
}
// verify required parameter 'createRequest' is not null or undefined
if (createRequest === null || createRequest === undefined) {
throw new Error('Required parameter createRequest was null or undefined when calling create.');
}
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: createRequest,
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, "SubscriptionVersion");
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);
});
});
}
;
/**
* The initialize operation initializes a subscription. This method uses charge flows to carry out the transaction.
* @summary initialize
* @param spaceId
* @param subscriptionId The provided subscription id will be used to lookup the subscription which should be initialized.
* @param {*} [options] Override http request options.
*/
initialize(spaceId, subscriptionId, options = {}) {
const url = '/subscription/initialize';
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 initialize.');
}
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling initialize.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
if (subscriptionId !== undefined) {
queryParams['subscriptionId'] = ObjectSerializer_1.ObjectSerializer.serialize(subscriptionId, "number");
}
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, "SubscriptionCharge");
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);
});
});
}
;
/**
* The initialize operation initializes a subscription when the subscriber is present. The method will initialize a transaction which has to be completed by using the transaction service.
* @summary initializeSubscriberPresent
* @param spaceId
* @param subscriptionId
* @param successUrl The subscriber will be redirected to the success URL when the transaction is successful.
* @param failedUrl The subscriber will be redirected to the fail URL when the transaction fails.
* @param {*} [options] Override http request options.
*/
initializeSubscriberPresent(spaceId, subscriptionId, successUrl, failedUrl, options = {}) {
const url = '/subscription/initializeSubscriberPresent';
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 initializeSubscriberPresent.');
}
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling initializeSubscriberPresent.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
if (subscriptionId !== undefined) {
queryParams['subscriptionId'] = ObjectSerializer_1.ObjectSerializer.serialize(subscriptionId, "number");
}
if (successUrl !== undefined) {
queryParams['successUrl'] = ObjectSerializer_1.ObjectSerializer.serialize(successUrl, "string");
}
if (failedUrl !== undefined) {
queryParams['failedUrl'] = ObjectSerializer_1.ObjectSerializer.serialize(failedUrl, "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, "SubscriptionCharge");
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);
});
});
}
;
/**
* Reads the entity with the given 'id' and returns it.
* @summary Read
* @param spaceId
* @param id The id of the subscription which should be returned.
* @param {*} [options] Override http request options.
*/
read(spaceId, id, options = {}) {
const url = '/subscription/read';
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 read.');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling read.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
if (id !== undefined) {
queryParams['id'] = ObjectSerializer_1.ObjectSerializer.serialize(id, "number");
}
headers['Content-Type'] = '*/*';
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: 'GET',
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, "Subscription");
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);
});
});
}
;
/**
* Searches for the entities as specified by the given query.
* @summary Search
* @param spaceId
* @param query The query restricts the subscriptions which are returned by the search.
* @param {*} [options] Override http request options.
*/
search(spaceId, query, options = {}) {
const url = '/subscription/search';
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 search.');
}
// verify required parameter 'query' is not null or undefined
if (query === null || query === undefined) {
throw new Error('Required parameter query was null or undefined when calling search.');
}
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: query,
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<Subscription>");
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 allows to search for subscription invoices.
* @summary Search Subscription Invoices
* @param spaceId
* @param subscriptionId The id of the subscription for which the invoices should be searched for.
* @param query The query restricts the invoices which are returned by the search.
* @param {*} [options] Override http request options.
*/
searchSubscriptionInvoices(spaceId, subscriptionId, query, options = {}) {
const url = '/subscription/searchSubscriptionInvoices';
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 searchSubscriptionInvoices.');
}
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling searchSubscriptionInvoices.');
}
// verify required parameter 'query' is not null or undefined
if (query === null || query === undefined) {
throw new Error('Required parameter query was null or undefined when calling searchSubscriptionInvoices.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
if (subscriptionId !== undefined) {
queryParams['subscriptionId'] = ObjectSerializer_1.ObjectSerializer.serialize(subscriptionId, "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: query,
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<TransactionInvoice>");
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 allows to terminate a subscription.
* @summary terminate
* @param spaceId
* @param subscriptionId The subscription id identifies the subscription which should be terminated.
* @param respectTerminationPeriod The respect termination period controls whether the termination period configured on the product version should be respected or if the operation should take effect immediately.
* @param {*} [options] Override http request options.
*/
terminate(spaceId, subscriptionId, respectTerminationPeriod, options = {}) {
const url = '/subscription/terminate';
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 terminate.');
}
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling terminate.');
}
// verify required parameter 'respectTerminationPeriod' is not null or undefined
if (respectTerminationPeriod === null || respectTerminationPeriod === undefined) {
throw new Error('Required parameter respectTerminationPeriod was null or undefined when calling terminate.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
if (subscriptionId !== undefined) {
queryParams['subscriptionId'] = ObjectSerializer_1.ObjectSerializer.serialize(subscriptionId, "number");
}
if (respectTerminationPeriod !== undefined) {
queryParams['respectTerminationPeriod'] = ObjectSerializer_1.ObjectSerializer.serialize(respectTerminationPeriod, "boolean");
}
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;
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 allows to update the subscription.
* @summary update
* @param spaceId
* @param subscriptionId
* @param request
* @param {*} [options] Override http request options.
*/
update(spaceId, subscriptionId, request, options = {}) {
const url = '/subscription/update';
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 update.');
}
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling update.');
}
// 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 update.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
if (subscriptionId !== undefined) {
queryParams['subscriptionId'] = ObjectSerializer_1.ObjectSerializer.serialize(subscriptionId, "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, "Subscription");
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);
});
});
}
;
/**
* The update product version operation updates the product version of the subscription to the latest active product version.
* @summary update product version
* @param spaceId
* @param subscriptionId The subscription id identifies the subscription which should be updated to the latest version.
* @param respectTerminationPeriod The subscription version may be retired. The respect termination period controls whether the termination period configured on the product version should be respected or if the operation should take effect immediately.
* @param {*} [options] Override http request options.
*/
updateProductVersion(spaceId, subscriptionId, respectTerminationPeriod, options = {}) {
const url = '/subscription/updateProductVersion';
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 updateProductVersion.');
}
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling updateProductVersion.');
}
// verify required parameter 'respectTerminationPeriod' is not null or undefined
if (respectTerminationPeriod === null || respectTerminationPeriod === undefined) {
throw new Error('Required parameter respectTerminationPeriod was null or undefined when calling updateProductVersion.');
}
if (spaceId !== undefined) {
queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number");
}
if (subscriptionId !== undefined) {
queryParams['subscriptionId'] = ObjectSerializer_1.ObjectSerializer.serialize(subscriptionId, "number");
}
if (respectTerminationPeriod !== undefined) {
queryParams['respectTerminationPeriod'] = ObjectSerializer_1.ObjectSerializer.serialize(respectTerminationPeriod, "boolean");
}
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, "SubscriptionVersion");
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.SubscriptionService = SubscriptionService;