mts-booking-library 1.2.25 → 1.2.27
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +2 -3
- package/lib/booking/booking.js +2 -4
- package/lib/booking/journeyBooking.d.ts +5 -7
- package/lib/booking/journeyBooking.js +37 -45
- package/lib/booking/serviceBooking.d.ts +5 -7
- package/lib/booking/serviceBooking.js +37 -43
- package/lib/booking/subscriptionBooking.d.ts +5 -7
- package/lib/booking/subscriptionBooking.js +37 -52
- package/lib/index.d.ts +3 -3
- package/lib/types/common/Cart.d.ts +2 -1
- package/lib/types/common/Person.d.ts +7 -0
- package/lib/types/journeys/JourneyCart.d.ts +10 -0
- package/lib/types/services/ServiceCart.d.ts +10 -0
- package/lib/types/subscriptions/SubscriptionCart.d.ts +10 -0
- package/package.json +1 -1
package/lib/booking/booking.d.ts
CHANGED
@@ -21,12 +21,10 @@ export declare abstract class Booking {
|
|
21
21
|
bookingStepsToStatus: Map<string, boolean[]>;
|
22
22
|
cartId: number | undefined;
|
23
23
|
bookingDueDate: Date | undefined;
|
24
|
-
onCartExpiration: () => void;
|
25
24
|
/**
|
26
25
|
* This is the constructor of the Booking class.
|
27
26
|
* @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
28
27
|
* @param {string} sub_key The subscription key for using the APIs
|
29
|
-
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
30
28
|
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
31
29
|
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
32
30
|
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
@@ -34,7 +32,7 @@ export declare abstract class Booking {
|
|
34
32
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
35
33
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
36
34
|
*/
|
37
|
-
constructor(env: MTSEnvs, sub_key: string,
|
35
|
+
constructor(env: MTSEnvs, sub_key: string, bookingType: Booking.BookingTypes, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
38
36
|
/**
|
39
37
|
* This method allows to update the sellerId. It is mostly important for Linkavel, as we start with sellerId = 0
|
40
38
|
* but then it changes to the actual sellerId once the cart is created.
|
@@ -60,6 +58,7 @@ export declare abstract class Booking {
|
|
60
58
|
*/
|
61
59
|
markBookingStepCompleted(bookingStep: Booking.BookingSteps): Promise<ErrorResponse | boolean>;
|
62
60
|
abstract deleteCart(): Promise<ErrorResponse | any>;
|
61
|
+
abstract resetBooking(): void;
|
63
62
|
abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
64
63
|
abstract getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
|
65
64
|
abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse | boolean>;
|
package/lib/booking/booking.js
CHANGED
@@ -58,7 +58,6 @@ var Booking = /** @class */ (function () {
|
|
58
58
|
* This is the constructor of the Booking class.
|
59
59
|
* @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
60
60
|
* @param {string} sub_key The subscription key for using the APIs
|
61
|
-
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
62
61
|
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
63
62
|
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
64
63
|
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
@@ -66,7 +65,7 @@ var Booking = /** @class */ (function () {
|
|
66
65
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
67
66
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
68
67
|
*/
|
69
|
-
function Booking(env, sub_key,
|
68
|
+
function Booking(env, sub_key, bookingType, debug, language, access_token, sellerId, resellerId) {
|
70
69
|
if (debug === void 0) { debug = false; }
|
71
70
|
if (language === void 0) { language = Booking.Languages.EN; }
|
72
71
|
this.language = Booking.Languages.EN;
|
@@ -84,7 +83,6 @@ var Booking = /** @class */ (function () {
|
|
84
83
|
this.resellerId = resellerId || undefined;
|
85
84
|
this.config = (0, config_1.setConfig)(env, sub_key, debug, access_token);
|
86
85
|
this.bookingType = bookingType;
|
87
|
-
this.onCartExpiration = onCartExpiration;
|
88
86
|
this.changeLanguage(language);
|
89
87
|
}
|
90
88
|
/**
|
@@ -329,7 +327,7 @@ var Booking = /** @class */ (function () {
|
|
329
327
|
return [3 /*break*/, 3];
|
330
328
|
case 6:
|
331
329
|
// Check again if the issue step is accessible
|
332
|
-
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.
|
330
|
+
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
|
333
331
|
if (!issueStep || !issueStep[0]) {
|
334
332
|
throw Error("The status of the cart does not allow to call this API");
|
335
333
|
}
|
@@ -3,7 +3,7 @@ import { ErrorResponse } from "../types/ErrorResponse";
|
|
3
3
|
import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
|
4
4
|
import { AddReductionRequest } from "../types/common/Reduction";
|
5
5
|
import { BusMatrix } from "../types/journeys/BusMatrix";
|
6
|
-
import { CreateJourneyCartRequest, JourneyCart } from "../types/journeys/JourneyCart";
|
6
|
+
import { CreateJourneyCartRequest, GetJourneyCartResponse, JourneyCart } from "../types/journeys/JourneyCart";
|
7
7
|
import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/JourneySearch";
|
8
8
|
import { ReductionTrip } from "../types/journeys/Trip";
|
9
9
|
import { Booking } from "./booking";
|
@@ -13,19 +13,17 @@ export declare class JourneyBooking extends Booking {
|
|
13
13
|
* This is the constructor of the ServiceBooking class.
|
14
14
|
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
15
15
|
* @param {string} sub_key The subscription key for using the APIs
|
16
|
-
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
17
|
-
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
18
16
|
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
19
17
|
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
20
18
|
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
21
19
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
22
20
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
23
21
|
*/
|
24
|
-
constructor(env: MTSEnvs, sub_key: string,
|
22
|
+
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
25
23
|
getCart(): JourneyCart | undefined;
|
24
|
+
resetBooking(): void;
|
26
25
|
fetchAndSetCart(cartId: number): Promise<void>;
|
27
|
-
|
28
|
-
fetchCart(cartId: number): Promise<JourneyCart>;
|
26
|
+
fetchCart(cartId: number): Promise<GetJourneyCartResponse>;
|
29
27
|
/**
|
30
28
|
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
31
29
|
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
@@ -138,5 +136,5 @@ export declare class JourneyBooking extends Booking {
|
|
138
136
|
useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
139
137
|
}
|
140
138
|
export declare namespace JourneyBooking {
|
141
|
-
const createBooking: (env: MTSEnvs, sub_key: string,
|
139
|
+
const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
|
142
140
|
}
|
@@ -82,19 +82,17 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
82
82
|
* This is the constructor of the ServiceBooking class.
|
83
83
|
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
84
84
|
* @param {string} sub_key The subscription key for using the APIs
|
85
|
-
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
86
|
-
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
87
85
|
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
88
86
|
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
89
87
|
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
90
88
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
91
89
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
92
90
|
*/
|
93
|
-
function JourneyBooking(env, sub_key,
|
91
|
+
function JourneyBooking(env, sub_key, debug, language, access_token, sellerId, resellerId) {
|
94
92
|
if (debug === void 0) { debug = false; }
|
95
93
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
96
94
|
// Call Booking constructor
|
97
|
-
var _this = _super.call(this, env, sub_key,
|
95
|
+
var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
|
98
96
|
// Set cartId
|
99
97
|
var cartId = localStorage.getItem("cartId");
|
100
98
|
if (cartId) {
|
@@ -105,20 +103,32 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
105
103
|
JourneyBooking.prototype.getCart = function () {
|
106
104
|
return this.cart;
|
107
105
|
};
|
106
|
+
JourneyBooking.prototype.resetBooking = function () {
|
107
|
+
this.cart = undefined;
|
108
|
+
this.cartId = undefined;
|
109
|
+
this.bookingStepsToStatus = new Map();
|
110
|
+
this.bookingDueDate = undefined;
|
111
|
+
localStorage.removeItem("cartId");
|
112
|
+
};
|
108
113
|
JourneyBooking.prototype.fetchAndSetCart = function (cartId) {
|
109
114
|
return __awaiter(this, void 0, void 0, function () {
|
110
115
|
var _this = this;
|
111
116
|
return __generator(this, function (_a) {
|
112
117
|
switch (_a.label) {
|
113
|
-
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
118
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (response) {
|
119
|
+
if (response.cart) {
|
120
|
+
var cartDate = new Date(response.cart.bookingDueDate);
|
121
|
+
if (cartDate > new Date()) {
|
122
|
+
_this.cart = response.cart;
|
123
|
+
_this.cartId = response.cart.id;
|
124
|
+
_this.bookingDueDate = cartDate; // See Booking class
|
125
|
+
// Fill the booking process status
|
126
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
127
|
+
}
|
128
|
+
else {
|
129
|
+
// This should never happen, but just in case
|
130
|
+
_this.resetBooking();
|
131
|
+
}
|
122
132
|
}
|
123
133
|
})];
|
124
134
|
case 1:
|
@@ -128,34 +138,22 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
128
138
|
});
|
129
139
|
});
|
130
140
|
};
|
131
|
-
JourneyBooking.prototype.createCartTimer = function (expiringDate) {
|
132
|
-
return __awaiter(this, void 0, void 0, function () {
|
133
|
-
var _this = this;
|
134
|
-
return __generator(this, function (_a) {
|
135
|
-
setTimeout(function () {
|
136
|
-
localStorage.removeItem("cartId");
|
137
|
-
// Put actions that have to be done when timer expires here
|
138
|
-
_this.bookingStepsToStatus = new Map();
|
139
|
-
_this.cart = undefined;
|
140
|
-
_this.cartId = undefined;
|
141
|
-
_this.bookingDueDate = undefined; // See Booking class
|
142
|
-
_this.onCartExpiration();
|
143
|
-
}, expiringDate.valueOf() - new Date().valueOf());
|
144
|
-
return [2 /*return*/];
|
145
|
-
});
|
146
|
-
});
|
147
|
-
};
|
148
141
|
JourneyBooking.prototype.fetchCart = function (cartId) {
|
149
142
|
return __awaiter(this, void 0, void 0, function () {
|
150
143
|
var url;
|
144
|
+
var _this = this;
|
151
145
|
return __generator(this, function (_a) {
|
152
146
|
url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
153
147
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
154
148
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
155
|
-
|
149
|
+
_this.resetBooking();
|
156
150
|
throw new Error(response);
|
157
151
|
}
|
158
|
-
|
152
|
+
// Check that the cart doe not have issued tickets
|
153
|
+
if (response.hasIssuedTickets) {
|
154
|
+
_this.resetBooking();
|
155
|
+
}
|
156
|
+
return response;
|
159
157
|
})];
|
160
158
|
});
|
161
159
|
});
|
@@ -171,17 +169,13 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
171
169
|
var _this = this;
|
172
170
|
return __generator(this, function (_a) {
|
173
171
|
// First check that it is possible to call this API
|
174
|
-
if (!this.cart) {
|
172
|
+
if (!this.cart || !this.cartId) {
|
175
173
|
throw Error("Cart is not initialized yet");
|
176
174
|
}
|
177
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
178
|
-
return [2 /*return*/, this.
|
175
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/carts?").concat(new URLSearchParams({ cartId: this.cartId.toString() }));
|
176
|
+
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
179
177
|
// Clear all data
|
180
|
-
|
181
|
-
_this.bookingStepsToStatus = new Map();
|
182
|
-
_this.cart = undefined;
|
183
|
-
_this.cartId = undefined;
|
184
|
-
_this.bookingDueDate = undefined; // See Booking class
|
178
|
+
_this.resetBooking();
|
185
179
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
186
180
|
})];
|
187
181
|
});
|
@@ -252,8 +246,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
252
246
|
// Check for errors
|
253
247
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
254
248
|
// If there was an error, reset cartId and remove it from the localStorage
|
255
|
-
_this.
|
256
|
-
localStorage.removeItem("cartId");
|
249
|
+
_this.resetBooking();
|
257
250
|
return response;
|
258
251
|
}
|
259
252
|
_this.cart = response.cart;
|
@@ -263,7 +256,6 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
263
256
|
// Fill the booking process status
|
264
257
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
265
258
|
_this.bookingDueDate = new Date(response.cart.bookingDueDate);
|
266
|
-
_this.createCartTimer(new Date(response.cart.bookingDueDate));
|
267
259
|
return response.cart;
|
268
260
|
})];
|
269
261
|
});
|
@@ -774,12 +766,12 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
774
766
|
exports.JourneyBooking = JourneyBooking;
|
775
767
|
(function (JourneyBooking) {
|
776
768
|
var _this = this;
|
777
|
-
JourneyBooking.createBooking = function (env, sub_key,
|
769
|
+
JourneyBooking.createBooking = function (env, sub_key, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
778
770
|
var booking, error_1;
|
779
771
|
return __generator(this, function (_a) {
|
780
772
|
switch (_a.label) {
|
781
773
|
case 0:
|
782
|
-
booking = new JourneyBooking(env, sub_key,
|
774
|
+
booking = new JourneyBooking(env, sub_key, debug, language, access_token, sellerId, resellerId);
|
783
775
|
_a.label = 1;
|
784
776
|
case 1:
|
785
777
|
_a.trys.push([1, 4, , 5]);
|
@@ -3,7 +3,7 @@ import { ErrorResponse } from "../types/ErrorResponse";
|
|
3
3
|
import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
|
4
4
|
import { AddReductionRequest } from "../types/common/Reduction";
|
5
5
|
import { Service, ServiceTrip } from "../types/services/Service";
|
6
|
-
import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
|
6
|
+
import { CreateServiceCartRequest, GetServiceCartResponse, ServiceCart } from "../types/services/ServiceCart";
|
7
7
|
import { Booking } from "./booking";
|
8
8
|
export declare class ServiceBooking extends Booking {
|
9
9
|
private cart?;
|
@@ -11,19 +11,17 @@ export declare class ServiceBooking extends Booking {
|
|
11
11
|
* This is the constructor of the ServiceBooking class.
|
12
12
|
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
13
13
|
* @param {string} sub_key The subscription key for using the APIs
|
14
|
-
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
15
|
-
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
16
14
|
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
17
15
|
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
18
16
|
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
19
17
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
20
18
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
21
19
|
*/
|
22
|
-
constructor(env: MTSEnvs, sub_key: string,
|
20
|
+
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
23
21
|
getCart(): ServiceCart | undefined;
|
22
|
+
resetBooking(): void;
|
24
23
|
fetchAndSetCart(cartId: number): Promise<void>;
|
25
|
-
|
26
|
-
fetchCart(cartId: number): Promise<ServiceCart>;
|
24
|
+
fetchCart(cartId: number): Promise<GetServiceCartResponse>;
|
27
25
|
/**
|
28
26
|
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
29
27
|
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
@@ -112,5 +110,5 @@ export declare class ServiceBooking extends Booking {
|
|
112
110
|
useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
113
111
|
}
|
114
112
|
export declare namespace ServiceBooking {
|
115
|
-
const createBooking: (env: MTSEnvs, sub_key: string,
|
113
|
+
const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
|
116
114
|
}
|
@@ -82,19 +82,17 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
82
82
|
* This is the constructor of the ServiceBooking class.
|
83
83
|
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
84
84
|
* @param {string} sub_key The subscription key for using the APIs
|
85
|
-
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
86
|
-
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
87
85
|
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
88
86
|
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
89
87
|
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
90
88
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
91
89
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
92
90
|
*/
|
93
|
-
function ServiceBooking(env, sub_key,
|
91
|
+
function ServiceBooking(env, sub_key, debug, language, access_token, sellerId, resellerId) {
|
94
92
|
if (debug === void 0) { debug = false; }
|
95
93
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
96
94
|
// Call Booking constructor
|
97
|
-
var _this = _super.call(this, env, sub_key,
|
95
|
+
var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
|
98
96
|
// Set cartId
|
99
97
|
var cartId = localStorage.getItem("cartId");
|
100
98
|
if (cartId) {
|
@@ -105,20 +103,33 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
105
103
|
ServiceBooking.prototype.getCart = function () {
|
106
104
|
return this.cart;
|
107
105
|
};
|
106
|
+
ServiceBooking.prototype.resetBooking = function () {
|
107
|
+
this.cart = undefined;
|
108
|
+
this.cartId = undefined;
|
109
|
+
this.bookingStepsToStatus = new Map();
|
110
|
+
this.bookingDueDate = undefined;
|
111
|
+
localStorage.removeItem("cartId");
|
112
|
+
};
|
108
113
|
ServiceBooking.prototype.fetchAndSetCart = function (cartId) {
|
109
114
|
return __awaiter(this, void 0, void 0, function () {
|
110
115
|
var _this = this;
|
111
116
|
return __generator(this, function (_a) {
|
112
117
|
switch (_a.label) {
|
113
|
-
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (
|
114
|
-
|
115
|
-
if (
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
118
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (response) {
|
119
|
+
console.log(response);
|
120
|
+
if (response.cart) {
|
121
|
+
var cartDate = new Date(response.cart.bookingDueDate);
|
122
|
+
if (cartDate > new Date()) {
|
123
|
+
_this.cart = response.cart;
|
124
|
+
_this.cartId = response.cart.id;
|
125
|
+
_this.bookingDueDate = cartDate; // See Booking class
|
126
|
+
// Fill the booking process status
|
127
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
// This should never happen, but just in case
|
131
|
+
_this.resetBooking();
|
132
|
+
}
|
122
133
|
}
|
123
134
|
})];
|
124
135
|
case 1:
|
@@ -128,25 +139,10 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
128
139
|
});
|
129
140
|
});
|
130
141
|
};
|
131
|
-
ServiceBooking.prototype.createCartTimer = function (expiringDate) {
|
132
|
-
return __awaiter(this, void 0, void 0, function () {
|
133
|
-
var _this = this;
|
134
|
-
return __generator(this, function (_a) {
|
135
|
-
setTimeout(function () {
|
136
|
-
localStorage.removeItem("cartId");
|
137
|
-
// Put actions that have to be done when timer expires here
|
138
|
-
_this.cart = undefined;
|
139
|
-
_this.cartId = undefined;
|
140
|
-
_this.bookingDueDate = undefined; // See Booking class
|
141
|
-
_this.onCartExpiration();
|
142
|
-
}, expiringDate.valueOf() - new Date().valueOf());
|
143
|
-
return [2 /*return*/];
|
144
|
-
});
|
145
|
-
});
|
146
|
-
};
|
147
142
|
ServiceBooking.prototype.fetchCart = function (cartId) {
|
148
143
|
return __awaiter(this, void 0, void 0, function () {
|
149
144
|
var url;
|
145
|
+
var _this = this;
|
150
146
|
return __generator(this, function (_a) {
|
151
147
|
url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
152
148
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
@@ -154,7 +150,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
154
150
|
localStorage.removeItem("cartId");
|
155
151
|
throw new Error(response);
|
156
152
|
}
|
157
|
-
|
153
|
+
// Check that the cart doe not have issued tickets
|
154
|
+
if (response.hasIssuedTickets) {
|
155
|
+
_this.resetBooking();
|
156
|
+
}
|
157
|
+
return response;
|
158
158
|
})];
|
159
159
|
});
|
160
160
|
});
|
@@ -170,17 +170,13 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
170
170
|
var _this = this;
|
171
171
|
return __generator(this, function (_a) {
|
172
172
|
// First check that it is possible to call this API
|
173
|
-
if (!this.cart) {
|
173
|
+
if (!this.cart || !this.cartId) {
|
174
174
|
throw Error("Cart is not initialized yet");
|
175
175
|
}
|
176
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
177
|
-
return [2 /*return*/, this.
|
176
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/carts?").concat(new URLSearchParams({ cartId: this.cartId.toString() }));
|
177
|
+
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
178
178
|
// Clear all data
|
179
|
-
|
180
|
-
_this.bookingStepsToStatus = new Map();
|
181
|
-
_this.cart = undefined;
|
182
|
-
_this.cartId = undefined;
|
183
|
-
_this.bookingDueDate = undefined; // See Booking class
|
179
|
+
_this.resetBooking();
|
184
180
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
185
181
|
})];
|
186
182
|
});
|
@@ -251,8 +247,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
251
247
|
// Check for errors
|
252
248
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
253
249
|
// If there was an error, reset cartId and remove it from the localStorage
|
254
|
-
_this.
|
255
|
-
localStorage.removeItem("cartId");
|
250
|
+
_this.resetBooking();
|
256
251
|
return response;
|
257
252
|
}
|
258
253
|
// Save the local data
|
@@ -263,7 +258,6 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
263
258
|
// Fill the booking process status
|
264
259
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
265
260
|
_this.bookingDueDate = new Date(response.cart.bookingDueDate);
|
266
|
-
_this.createCartTimer(new Date(response.cart.bookingDueDate));
|
267
261
|
return response.cart;
|
268
262
|
})];
|
269
263
|
});
|
@@ -645,12 +639,12 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
645
639
|
exports.ServiceBooking = ServiceBooking;
|
646
640
|
(function (ServiceBooking) {
|
647
641
|
var _this = this;
|
648
|
-
ServiceBooking.createBooking = function (env, sub_key,
|
642
|
+
ServiceBooking.createBooking = function (env, sub_key, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
649
643
|
var booking, error_1;
|
650
644
|
return __generator(this, function (_a) {
|
651
645
|
switch (_a.label) {
|
652
646
|
case 0:
|
653
|
-
booking = new ServiceBooking(env, sub_key,
|
647
|
+
booking = new ServiceBooking(env, sub_key, debug, language, access_token, sellerId, resellerId);
|
654
648
|
_a.label = 1;
|
655
649
|
case 1:
|
656
650
|
_a.trys.push([1, 4, , 5]);
|
@@ -3,7 +3,7 @@ import { ErrorResponse } from "../types/ErrorResponse";
|
|
3
3
|
import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
|
4
4
|
import { AddReductionRequest } from "../types/common/Reduction";
|
5
5
|
import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
|
6
|
-
import { CreateSubscriptionCartRequest, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
|
6
|
+
import { CreateSubscriptionCartRequest, GetSubscriptionCartResponse, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
|
7
7
|
import { Subscription } from "../types/subscriptions/Subscriptions";
|
8
8
|
import { Booking } from "./booking";
|
9
9
|
export declare class SubscriptionBooking extends Booking {
|
@@ -12,19 +12,17 @@ export declare class SubscriptionBooking extends Booking {
|
|
12
12
|
* This is the constructor of the ServiceBooking class.
|
13
13
|
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
14
14
|
* @param {string} sub_key The subscription key for using the APIs
|
15
|
-
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
16
|
-
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
17
15
|
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
18
16
|
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
19
17
|
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
20
18
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
21
19
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
22
20
|
*/
|
23
|
-
constructor(env: MTSEnvs, sub_key: string,
|
21
|
+
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
24
22
|
getCart(): SubscriptionCart | undefined;
|
23
|
+
resetBooking(): void;
|
25
24
|
fetchAndSetCart(cartId: number): Promise<void>;
|
26
|
-
|
27
|
-
fetchCart(cartId: number): Promise<SubscriptionCart>;
|
25
|
+
fetchCart(cartId: number): Promise<GetSubscriptionCartResponse>;
|
28
26
|
/**
|
29
27
|
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
30
28
|
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
@@ -130,7 +128,7 @@ export declare class SubscriptionBooking extends Booking {
|
|
130
128
|
useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
131
129
|
}
|
132
130
|
export declare namespace SubscriptionBooking {
|
133
|
-
const createBooking: (env: MTSEnvs, sub_key: string,
|
131
|
+
const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<SubscriptionBooking>;
|
134
132
|
enum ValidityTypes {
|
135
133
|
WORKING_WEEK = "WORKING_WEEK",
|
136
134
|
WEEKLY = "WEEKLY",
|
@@ -82,19 +82,17 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
82
82
|
* This is the constructor of the ServiceBooking class.
|
83
83
|
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
84
84
|
* @param {string} sub_key The subscription key for using the APIs
|
85
|
-
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
86
|
-
* @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
|
87
85
|
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
88
86
|
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
89
87
|
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
90
88
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
91
89
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
92
90
|
*/
|
93
|
-
function SubscriptionBooking(env, sub_key,
|
91
|
+
function SubscriptionBooking(env, sub_key, debug, language, access_token, sellerId, resellerId) {
|
94
92
|
if (debug === void 0) { debug = false; }
|
95
93
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
96
94
|
// Call Booking constructor
|
97
|
-
var _this = _super.call(this, env, sub_key,
|
95
|
+
var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
|
98
96
|
// Set cartId
|
99
97
|
var cartId = localStorage.getItem("cartId");
|
100
98
|
if (cartId) {
|
@@ -105,26 +103,32 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
105
103
|
SubscriptionBooking.prototype.getCart = function () {
|
106
104
|
return this.cart;
|
107
105
|
};
|
106
|
+
SubscriptionBooking.prototype.resetBooking = function () {
|
107
|
+
this.cart = undefined;
|
108
|
+
this.cartId = undefined;
|
109
|
+
this.bookingStepsToStatus = new Map();
|
110
|
+
this.bookingDueDate = undefined;
|
111
|
+
localStorage.removeItem("cartId");
|
112
|
+
};
|
108
113
|
SubscriptionBooking.prototype.fetchAndSetCart = function (cartId) {
|
109
114
|
return __awaiter(this, void 0, void 0, function () {
|
110
115
|
var _this = this;
|
111
116
|
return __generator(this, function (_a) {
|
112
117
|
switch (_a.label) {
|
113
|
-
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
}
|
127
|
-
_this.createCartTimer(cartDate);
|
118
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (response) {
|
119
|
+
if (response.cart) {
|
120
|
+
var cartDate = new Date(response.cart.bookingDueDate);
|
121
|
+
if (cartDate > new Date()) {
|
122
|
+
_this.cart = response.cart;
|
123
|
+
_this.cartId = response.cart.id;
|
124
|
+
_this.bookingDueDate = cartDate; // See Booking class
|
125
|
+
// Fill the booking process status
|
126
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
127
|
+
}
|
128
|
+
else {
|
129
|
+
// This should never happen, but just in case
|
130
|
+
_this.resetBooking();
|
131
|
+
}
|
128
132
|
}
|
129
133
|
})];
|
130
134
|
case 1:
|
@@ -134,34 +138,22 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
134
138
|
});
|
135
139
|
});
|
136
140
|
};
|
137
|
-
SubscriptionBooking.prototype.createCartTimer = function (expiringDate) {
|
138
|
-
return __awaiter(this, void 0, void 0, function () {
|
139
|
-
var _this = this;
|
140
|
-
return __generator(this, function (_a) {
|
141
|
-
setTimeout(function () {
|
142
|
-
localStorage.removeItem("cartId");
|
143
|
-
// Put actions that have to be done when timer expires here
|
144
|
-
_this.bookingStepsToStatus = new Map();
|
145
|
-
_this.cart = undefined;
|
146
|
-
_this.cartId = undefined;
|
147
|
-
_this.bookingDueDate = undefined; // See Booking class
|
148
|
-
_this.onCartExpiration();
|
149
|
-
}, expiringDate.valueOf() - new Date().valueOf());
|
150
|
-
return [2 /*return*/];
|
151
|
-
});
|
152
|
-
});
|
153
|
-
};
|
154
141
|
SubscriptionBooking.prototype.fetchCart = function (cartId) {
|
155
142
|
return __awaiter(this, void 0, void 0, function () {
|
156
143
|
var url;
|
144
|
+
var _this = this;
|
157
145
|
return __generator(this, function (_a) {
|
158
146
|
url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
159
147
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
160
148
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
161
|
-
|
149
|
+
_this.resetBooking();
|
162
150
|
throw new Error(response);
|
163
151
|
}
|
164
|
-
|
152
|
+
// Check that the cart doe not have issued tickets
|
153
|
+
if (response.hasIssuedTickets) {
|
154
|
+
_this.resetBooking();
|
155
|
+
}
|
156
|
+
return response;
|
165
157
|
})];
|
166
158
|
});
|
167
159
|
});
|
@@ -177,17 +169,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
177
169
|
var _this = this;
|
178
170
|
return __generator(this, function (_a) {
|
179
171
|
// First check that it is possible to call this API
|
180
|
-
if (!this.cart) {
|
172
|
+
if (!this.cart || !this.cartId) {
|
181
173
|
throw Error("Cart is not initialized yet");
|
182
174
|
}
|
183
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
184
|
-
return [2 /*return*/, this.
|
185
|
-
|
186
|
-
localStorage.removeItem("cartId");
|
187
|
-
_this.bookingStepsToStatus = new Map();
|
188
|
-
_this.cart = undefined;
|
189
|
-
_this.cartId = undefined;
|
190
|
-
_this.bookingDueDate = undefined; // See Booking class
|
175
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/carts?").concat(new URLSearchParams({ cartId: this.cartId.toString() }));
|
176
|
+
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
177
|
+
_this.resetBooking();
|
191
178
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
192
179
|
})];
|
193
180
|
});
|
@@ -314,8 +301,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
314
301
|
// Check for errors
|
315
302
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
316
303
|
// If there was an error, reset cartId and remove it from the localStorage
|
317
|
-
_this.
|
318
|
-
localStorage.removeItem("cartId");
|
304
|
+
_this.resetBooking();
|
319
305
|
return response;
|
320
306
|
}
|
321
307
|
_this.cart = response.cart;
|
@@ -325,7 +311,6 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
325
311
|
// Fill the booking process status
|
326
312
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
327
313
|
_this.bookingDueDate = new Date(response.cart.bookingDueDate);
|
328
|
-
_this.createCartTimer(new Date(response.cart.bookingDueDate));
|
329
314
|
return response.cart;
|
330
315
|
})];
|
331
316
|
});
|
@@ -728,12 +713,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
728
713
|
exports.SubscriptionBooking = SubscriptionBooking;
|
729
714
|
(function (SubscriptionBooking) {
|
730
715
|
var _this = this;
|
731
|
-
SubscriptionBooking.createBooking = function (env, sub_key,
|
716
|
+
SubscriptionBooking.createBooking = function (env, sub_key, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
732
717
|
var booking, error_1;
|
733
718
|
return __generator(this, function (_a) {
|
734
719
|
switch (_a.label) {
|
735
720
|
case 0:
|
736
|
-
booking = new SubscriptionBooking(env, sub_key,
|
721
|
+
booking = new SubscriptionBooking(env, sub_key, debug, language, access_token, sellerId, resellerId);
|
737
722
|
_a.label = 1;
|
738
723
|
case 1:
|
739
724
|
_a.trys.push([1, 4, , 5]);
|
package/lib/index.d.ts
CHANGED
@@ -10,15 +10,15 @@ export { Reduction, AddReductionRequest } from "./types/common/Reduction";
|
|
10
10
|
export { Gateway, GetSellerGatewaysResponse, GetPaymentInformationFromGatewayResponse, IssueTicketsResponse, GatewayTypes, PaymentMethods } from "./types/common/Payment";
|
11
11
|
export { ErrorResponse, objectIsMTSErrorResponse } from "./types/ErrorResponse";
|
12
12
|
export { BusLayoutCell, BusMatrix, BusCellTypes, SeatStatus } from "./types/journeys/BusMatrix";
|
13
|
-
export { JourneyCart, JourneyBookingType, CreateJourneyCartRequest, TripBookingInfo, DEFAULT_CREATE_JOURNEY_CART } from "./types/journeys/JourneyCart";
|
13
|
+
export { JourneyCart, GetJourneyCartResponse, JourneyBookingType, CreateJourneyCartRequest, TripBookingInfo, DEFAULT_CREATE_JOURNEY_CART } from "./types/journeys/JourneyCart";
|
14
14
|
export { JourneyInfo } from "./types/journeys/JourneyInfo";
|
15
15
|
export { JourneySearchRequest, JourneySearchResult, DEFAULT_JOURNEY_SEARCH } from "./types/journeys/JourneySearch";
|
16
16
|
export { Stop } from "./types/journeys/Stop";
|
17
17
|
export { Trip, CartTrip, ReductionTrip } from "./types/journeys/Trip";
|
18
18
|
export { Line } from "./types/services/Line";
|
19
19
|
export { Service, ServiceTrip } from "./types/services/Service";
|
20
|
-
export { ServiceCart, ServiceBookingType, CreateServiceCartRequest } from "./types/services/ServiceCart";
|
20
|
+
export { ServiceCart, GetServiceCartResponse, ServiceBookingType, CreateServiceCartRequest } from "./types/services/ServiceCart";
|
21
21
|
export { ServiceInfo } from "./types/services/ServiceInfo";
|
22
22
|
export { Subscription } from "./types/subscriptions/Subscriptions";
|
23
23
|
export { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse, SubscriptionCalendarDayPeriodInfo } from "./types/subscriptions/SubscriptionAvailabilities";
|
24
|
-
export { SubscriptionCart, SubscriptionBookingType, CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
|
24
|
+
export { SubscriptionCart, GetSubscriptionCartResponse, SubscriptionBookingType, CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
|
@@ -9,6 +9,7 @@ import { Extra } from "./Extra";
|
|
9
9
|
* - SubscriptionCart: {@link SubscriptionCart}
|
10
10
|
* @property {number} id The id of the cart
|
11
11
|
* @property {string} cartCode The code of the cart
|
12
|
+
* @property {number} sellerId The id of the seller of the tickets in the cart
|
12
13
|
* @property {Map<string, boolean[]>} stepsToStatus This data structure describes the steps of the booking process.
|
13
14
|
* The keys of this dictionary represent the booking steps. See ... for the list of possible steps. If the
|
14
15
|
* key is present, then the booking step shall be displayed. The value is a list of 3 booleans:
|
@@ -17,10 +18,10 @@ import { Extra } from "./Extra";
|
|
17
18
|
* - The third tells whether the section is required.
|
18
19
|
* @property {Booking.Currencies} currency The currency of the cart. See {@link Booking.Currencies}
|
19
20
|
* @property {string} bookingDueDate The date and time when the cart expires
|
20
|
-
* @property {number} buyerId The id of the buyer
|
21
21
|
*/
|
22
22
|
export type Cart = {
|
23
23
|
id: number;
|
24
|
+
sellerId: number;
|
24
25
|
cartCode: string;
|
25
26
|
stepsToStatus: Map<string, boolean[]>;
|
26
27
|
currency: Booking.Currencies;
|
@@ -23,13 +23,17 @@ export declare const initializePerson: (person?: Person | undefined | null) => P
|
|
23
23
|
* @description Represents a passenger in the response of the {@link getPassengersDetails} method. This type extends the {@link Person} type
|
24
24
|
* with the `outboundTariffs` and `returnTariffs` properties.
|
25
25
|
*
|
26
|
+
* @property {string} outboundNotes - The notes for the outbound trip.
|
26
27
|
* @property { Map<number, PassengerTariff>} outboundTariffs - A map containing the outbound tariffs for this passenger. The key is the trip id.
|
27
28
|
* For every trip, the first element the value is the suggested tariff. The other elements are the other tariffs, so that the user can adjust
|
28
29
|
* the tariff for the passenger.
|
30
|
+
* @property {string} returnNotes - The notes for the return trip.
|
29
31
|
* @property { Map<number, PassengerTariff>} returnTariffs - Same of `outboundTariffs`, but for the return trip.
|
30
32
|
*/
|
31
33
|
export type GetPassenger = Person & {
|
34
|
+
outboundNotes: string | null;
|
32
35
|
outboundTariffs: Map<number, PassengerTariff[]>;
|
36
|
+
returnNotes: string | null;
|
33
37
|
returnTariffs: Map<number, PassengerTariff[]> | null;
|
34
38
|
};
|
35
39
|
export declare enum BuyerDataStatus {
|
@@ -54,9 +58,12 @@ export type GetBuyerPassengersDetailsResponse = {
|
|
54
58
|
};
|
55
59
|
/**
|
56
60
|
* @description Represents the type of the passengers array in {@link EditPassengersDetailsRequest}.
|
61
|
+
* @property {Map<number, number>} tripsToTariffs A dictionary containg the selected tariff for each trip (both outbound and return).
|
57
62
|
* Note that in the `tripsToTariffs` map, the key is the trip id and the value is the chosen tariff id.
|
58
63
|
*/
|
59
64
|
export type EditPassengerRequestType = Person & {
|
65
|
+
outboundNotes?: string | undefined;
|
66
|
+
returnNotes?: string | undefined;
|
60
67
|
tripsToTariffs: Map<number, number>;
|
61
68
|
};
|
62
69
|
/**
|
@@ -35,6 +35,16 @@ export type CreateJourneyCartRequest = {
|
|
35
35
|
returnJourney: TripBookingInfo[] | null;
|
36
36
|
};
|
37
37
|
export declare const DEFAULT_CREATE_JOURNEY_CART: CreateJourneyCartRequest;
|
38
|
+
/**
|
39
|
+
* This type represents the response of the {@link JourneyBooking.fetchCart} API.
|
40
|
+
* @property {JourneyCart} cart - The {@link JourneyCart} object representing the cart.
|
41
|
+
* @property {boolean} hasIssuedTickets - A boolean telling whether the cart has issued tickets. Note that if this is the case,
|
42
|
+
* the cart will be null because it is not possible to add tickets to an issued cart. Thus, all data should be reset.
|
43
|
+
*/
|
44
|
+
export type GetJourneyCartResponse = {
|
45
|
+
cart: JourneyCart | null;
|
46
|
+
hasIssuedTickets: boolean;
|
47
|
+
};
|
38
48
|
/**
|
39
49
|
* @description Represents a `JourneyCart`, which extends the {@link Cart} type by including additional
|
40
50
|
* information about the bookings
|
@@ -31,6 +31,16 @@ export type CreateServiceCartRequest = {
|
|
31
31
|
export type ServiceCart = Cart & {
|
32
32
|
bookings: ServiceBookingType[];
|
33
33
|
};
|
34
|
+
/**
|
35
|
+
* This type represents the response of the {@link ServiceBooking.fetchCart} API.
|
36
|
+
* @property {JourneyCart} cart - The {@link ServiceCart} object representing the cart.
|
37
|
+
* @property {boolean} hasIssuedTickets - A boolean telling whether the cart has issued tickets. Note that if this is the case,
|
38
|
+
* the cart will be null because it is not possible to add tickets to an issued cart. Thus, all data should be reset.
|
39
|
+
*/
|
40
|
+
export type GetServiceCartResponse = {
|
41
|
+
cart: ServiceCart | null;
|
42
|
+
hasIssuedTickets: boolean;
|
43
|
+
};
|
34
44
|
/**
|
35
45
|
* @description Represents a `ServiceBooking`, which contains information about a service booking.
|
36
46
|
*
|
@@ -48,6 +48,16 @@ export type SubscriptionPeriod = {
|
|
48
48
|
export type SubscriptionCart = Cart & {
|
49
49
|
bookings: SubscriptionBookingType[];
|
50
50
|
};
|
51
|
+
/**
|
52
|
+
* This type represents the response of the {@link SubscriptionBooking.fetchCart} API.
|
53
|
+
* @property {JourneyCart} cart - The {@link SubscriptionCart} object representing the cart.
|
54
|
+
* @property {boolean} hasIssuedTickets - A boolean telling whether the cart has issued tickets. Note that if this is the case,
|
55
|
+
* the cart will be null because it is not possible to add tickets to an issued cart. Thus, all data should be reset.
|
56
|
+
*/
|
57
|
+
export type GetSubscriptionCartResponse = {
|
58
|
+
cart: SubscriptionCart | null;
|
59
|
+
hasIssuedTickets: boolean;
|
60
|
+
};
|
51
61
|
/**
|
52
62
|
* @description Represents a `SubscriptionBooking`, which contains information about a subscription booking.
|
53
63
|
*
|