vista-co
Version:
110 lines (109 loc) • 5.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RESTTicketing = void 0;
//RESTData.ts
const axios_master_1 = require("axios-master");
const RESTTicketing = (config) => {
return {
/**
* Cancels the order associated with the UserSessionId.
Associated cinema order will also be cancelled and any reserved seats will be released as will any other associated resources including 3rd Party Member tickets.
Orders may also be cancelled by cleanup-tasks in the background so attempting to cancel an already cancelled order will result in a successful result (the OrderNotFound response property can be used to check for this scenario).
Loyalty sessions associated with the UserSessionId will NOT be disconnected, subsequent calls re-using the UserSessionID will retain the member's context.
*
* @param {string} userSessionId - The user's session ID.
* @returns {Promise<{ success: boolean; message: string; data?: OrderCancelResponse }>}
*/
orderCancel: async (UserSessionId) => {
var _a, _b, _c;
try {
// Construct the request URL
const url = `${config.host}/WSVistaWebClient/RESTTicketing.svc/order/cancel`;
// Make the API request
const response = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url,
headers: {
connectapitoken: config.token, // API token
"Content-Type": "application/json",
"Connect-Region-Code": config.regionCode, // Localization
},
data: { UserSessionId },
}, {
name: "orderCancel",
timeout: 20000,
logger(data) {
if (config.logger)
console.log(data);
},
});
// Return success response
return {
success: true,
message: "Order Cancel successfully",
data: response,
};
}
catch (error) {
// Handle errors
console.error("CompleteOrder failed:", ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
return {
success: false,
message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "Failed to complete order",
};
}
},
/**
* Completes an order with payment details.
*
* @param {string} userSessionId - The user's session ID.
* @param {CompleteOrderRequest} paymentDetails - The payment details and order information.
* @returns {Promise<{ success: boolean; message: string; data?: CompleteOrderResponse }>}
*/
completeOrder: async (paymentDetails) => {
try {
// Construct the request URL
const url = `${config.host}/WSVistaWebClient/RESTTicketing.svc/order/payment`;
// Make the API request
const response = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url,
headers: {
connectapitoken: config.token, // API token
"Content-Type": "application/json",
"Connect-Region-Code": config.regionCode, // Localization
},
data: paymentDetails,
}, {
name: "completeOrder",
timeout: 80000,
logger(data) {
if (config.logger)
console.log(data);
},
});
// Return success response
return {
success: true,
message: "Order completed successfully",
data: response,
};
}
catch (error) {
// Handle errors
console.error("CompleteOrder failed:", (error === null || error === void 0 ? void 0 : error.data) || error);
const axiosError = error;
return {
success: false,
message: `${axiosError === null || axiosError === void 0 ? void 0 : axiosError.statusText} ${axiosError === null || axiosError === void 0 ? void 0 : axiosError.status}`,
data: {
error: (axiosError === null || axiosError === void 0 ? void 0 : axiosError.statusText) || axiosError.status,
errorCode: axiosError === null || axiosError === void 0 ? void 0 : axiosError.status,
...axiosError === null || axiosError === void 0 ? void 0 : axiosError.data,
},
};
}
},
};
};
exports.RESTTicketing = RESTTicketing;