mts-booking-library 1.4.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/SubscriptionBooking.d.ts +0 -0
 - package/lib/SubscriptionBooking.js +148 -0
 - package/lib/booking/booking.d.ts +12 -9
 - package/lib/booking/booking.js +44 -9
 - package/lib/booking/journeyBooking.d.ts +8 -21
 - package/lib/booking/journeyBooking.js +21 -58
 - package/lib/booking/serviceBooking.d.ts +9 -22
 - package/lib/booking/serviceBooking.js +23 -58
 - package/lib/booking/subscriptionBooking.d.ts +8 -21
 - package/lib/booking/subscriptionBooking.js +20 -55
 - package/lib/booking/tplBooking.d.ts +13 -31
 - package/lib/booking/tplBooking.js +29 -68
 - package/lib/index.d.ts +8 -7
 - package/lib/index.js +3 -3
 - package/lib/mtsStorage.d.ts +1 -3
 - package/lib/mtsStorage.js +4 -5
 - package/lib/types/common/Cart.d.ts +0 -5
 - package/lib/types/common/Payment.d.ts +3 -3
 - package/lib/types/common/Payment.js +1 -1
 - package/lib/types/common/Person.d.ts +8 -8
 - package/lib/types/common/Person.js +3 -3
 - package/lib/types/journeys/JourneyCart.d.ts +14 -9
 - package/lib/types/journeys/JourneyCart.js +1 -1
 - package/lib/types/services/ServiceCart.d.ts +4 -0
 - package/lib/types/tpl/SuperArea.d.ts +6 -0
 - package/lib/types/tpl/TplCart.d.ts +19 -0
 - package/lib/utils/apiCall.js +2 -2
 - package/lib/utils/testUtils.d.ts +8 -0
 - package/lib/utils/testUtils.js +19 -0
 - package/package.json +6 -6
 
| 
         
            File without changes
         
     | 
| 
         @@ -0,0 +1,148 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            "use strict";
         
     | 
| 
      
 2 
     | 
    
         
            +
            // import { MTSEnvs } from "../config";
         
     | 
| 
      
 3 
     | 
    
         
            +
            // import { ServiceBooking } from "../booking/serviceBooking";
         
     | 
| 
      
 4 
     | 
    
         
            +
            // import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
         
     | 
| 
      
 5 
     | 
    
         
            +
            // import { Service, ServiceTripsResponse } from "../types/services/Service";
         
     | 
| 
      
 6 
     | 
    
         
            +
            // import { GetBuyerPassengersDetailsResponse } from "../types/common/Person";
         
     | 
| 
      
 7 
     | 
    
         
            +
            // import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
         
     | 
| 
      
 8 
     | 
    
         
            +
            // import { useTestState } from "../mtsStorage";
         
     | 
| 
      
 9 
     | 
    
         
            +
            // import { SubscriptionBooking } from "../booking/subscriptionBooking";
         
     | 
| 
      
 10 
     | 
    
         
            +
            // // Load .env file
         
     | 
| 
      
 11 
     | 
    
         
            +
            // require('dotenv').config();
         
     | 
| 
      
 12 
     | 
    
         
            +
            // // How to run the test: npm run test -- SubscriptionBooking.test.ts
         
     | 
| 
      
 13 
     | 
    
         
            +
            // describe("SubscriptionBooking", () => {
         
     | 
| 
      
 14 
     | 
    
         
            +
            //   const timeOut = 120000;
         
     | 
| 
      
 15 
     | 
    
         
            +
            //   const sub_key = process.env.OCP_SUB_KEY_MTS;
         
     | 
| 
      
 16 
     | 
    
         
            +
            //   const access_token = process.env.ACCESS_TOKEN;
         
     | 
| 
      
 17 
     | 
    
         
            +
            //   const sellerId = 8; // ATV
         
     | 
| 
      
 18 
     | 
    
         
            +
            //   // Define localStorage for local testing
         
     | 
| 
      
 19 
     | 
    
         
            +
            //   if (typeof localStorage === "undefined" || localStorage === null) {
         
     | 
| 
      
 20 
     | 
    
         
            +
            //     var LocalStorage = require("node-localstorage").LocalStorage;
         
     | 
| 
      
 21 
     | 
    
         
            +
            //     global.localStorage = new LocalStorage("./scratch");
         
     | 
| 
      
 22 
     | 
    
         
            +
            //   }
         
     | 
| 
      
 23 
     | 
    
         
            +
            //   test("search_tpl", async () => {
         
     | 
| 
      
 24 
     | 
    
         
            +
            //     const booking = new SubscriptionBooking(MTSEnvs.TEST, sub_key!, true, SubscriptionBooking.Languages.EN, access_token, sellerId);
         
     | 
| 
      
 25 
     | 
    
         
            +
            //     // First, get the departures and destinations
         
     | 
| 
      
 26 
     | 
    
         
            +
            //     const departures = await booking.getSubscriptionsDepartures() as string[];
         
     | 
| 
      
 27 
     | 
    
         
            +
            //     expect(departures.length).toBeGreaterThan(0);
         
     | 
| 
      
 28 
     | 
    
         
            +
            //     expect(departures).toContain("BARDOLINO AUTOSTAZIONE");
         
     | 
| 
      
 29 
     | 
    
         
            +
            //     const selectedDeparture = "BARDOLINO AUTOSTAZIONE";
         
     | 
| 
      
 30 
     | 
    
         
            +
            //     const destinations = await booking.getSubscriptionsDestinations(selectedDeparture) as string[];
         
     | 
| 
      
 31 
     | 
    
         
            +
            //     expect(destinations.length).toBeGreaterThan(0);
         
     | 
| 
      
 32 
     | 
    
         
            +
            //     expect(destinations).toContain("GARDA AUTOSTAZIONE");
         
     | 
| 
      
 33 
     | 
    
         
            +
            //     const selectedDestination = "GARDA AUTOSTAZIONE";
         
     | 
| 
      
 34 
     | 
    
         
            +
            //     // Then get the validity types
         
     | 
| 
      
 35 
     | 
    
         
            +
            //     const validityTypes = await booking.getSubscriptionsValidityTypes(selectedDeparture, selectedDestination) as SubscriptionBooking.ValidityTypes[];
         
     | 
| 
      
 36 
     | 
    
         
            +
            //     expect(validityTypes.length).toBeGreaterThan(0);
         
     | 
| 
      
 37 
     | 
    
         
            +
            //     for (const validityType of validityTypes) {
         
     | 
| 
      
 38 
     | 
    
         
            +
            //       // Check that all returned validity types are valid
         
     | 
| 
      
 39 
     | 
    
         
            +
            //       expect(Object.values(SubscriptionBooking.ValidityTypes).includes(validityType)).toBe(true);
         
     | 
| 
      
 40 
     | 
    
         
            +
            //     }
         
     | 
| 
      
 41 
     | 
    
         
            +
            //   }, timeOut);
         
     | 
| 
      
 42 
     | 
    
         
            +
            //   const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
         
     | 
| 
      
 43 
     | 
    
         
            +
            //     const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
         
     | 
| 
      
 44 
     | 
    
         
            +
            //     const services = servicesResponse as Service[];
         
     | 
| 
      
 45 
     | 
    
         
            +
            //     // Build create cart request
         
     | 
| 
      
 46 
     | 
    
         
            +
            //     let tariffsMatrix = services[0].tariffsMatrix;
         
     | 
| 
      
 47 
     | 
    
         
            +
            //     tariffsMatrix[0][0].quantity = 1;
         
     | 
| 
      
 48 
     | 
    
         
            +
            //     const createServiceCartRequest: CreateServiceCartRequest = {
         
     | 
| 
      
 49 
     | 
    
         
            +
            //         currency: ServiceBooking.Currencies.EUR,
         
     | 
| 
      
 50 
     | 
    
         
            +
            //         service: {
         
     | 
| 
      
 51 
     | 
    
         
            +
            //           serviceId: services[0].id,
         
     | 
| 
      
 52 
     | 
    
         
            +
            //           tariffsMatrix:  tariffsMatrix
         
     | 
| 
      
 53 
     | 
    
         
            +
            //       }
         
     | 
| 
      
 54 
     | 
    
         
            +
            //     };
         
     | 
| 
      
 55 
     | 
    
         
            +
            //     // Create cart
         
     | 
| 
      
 56 
     | 
    
         
            +
            //     const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
         
     | 
| 
      
 57 
     | 
    
         
            +
            //     return cart;
         
     | 
| 
      
 58 
     | 
    
         
            +
            //   }
         
     | 
| 
      
 59 
     | 
    
         
            +
            //   test("create_service_cart", async () => {
         
     | 
| 
      
 60 
     | 
    
         
            +
            //     const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
         
     | 
| 
      
 61 
     | 
    
         
            +
            //     const cart = await createCart(booking);
         
     | 
| 
      
 62 
     | 
    
         
            +
            //     // Check that the cartId was saved to the local storage
         
     | 
| 
      
 63 
     | 
    
         
            +
            //     expect(useTestState().getState().cartId).toBe(cart.id);
         
     | 
| 
      
 64 
     | 
    
         
            +
            //     expect(booking.cartId).toBe(cart.id);
         
     | 
| 
      
 65 
     | 
    
         
            +
            //     // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
         
     | 
| 
      
 66 
     | 
    
         
            +
            //     expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
         
     | 
| 
      
 67 
     | 
    
         
            +
            //     expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
         
     | 
| 
      
 68 
     | 
    
         
            +
            //     // Test booking due date
         
     | 
| 
      
 69 
     | 
    
         
            +
            //     expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
         
     | 
| 
      
 70 
     | 
    
         
            +
            //     // Test expired tickets
         
     | 
| 
      
 71 
     | 
    
         
            +
            //     expect(cart.hasIssuedTickets).toBe(false);
         
     | 
| 
      
 72 
     | 
    
         
            +
            //     // Test seller data
         
     | 
| 
      
 73 
     | 
    
         
            +
            //     expect(booking.getSellerId()).toBe(cart.sellerId);
         
     | 
| 
      
 74 
     | 
    
         
            +
            //     expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
         
     | 
| 
      
 75 
     | 
    
         
            +
            //     expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
         
     | 
| 
      
 76 
     | 
    
         
            +
            //     // Now try to get the cart
         
     | 
| 
      
 77 
     | 
    
         
            +
            //     const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
         
     | 
| 
      
 78 
     | 
    
         
            +
            //     expect(newBooking.cartId).toBe(cart.id);
         
     | 
| 
      
 79 
     | 
    
         
            +
            //     expect(newBooking.getCart()?.id).toBe(cart.id)
         
     | 
| 
      
 80 
     | 
    
         
            +
            //     expect(newBooking.getSellerId()).toBe(cart.sellerId);
         
     | 
| 
      
 81 
     | 
    
         
            +
            //     // Finally try to delete the cart
         
     | 
| 
      
 82 
     | 
    
         
            +
            //     await booking.deleteCart();
         
     | 
| 
      
 83 
     | 
    
         
            +
            //     expect(booking.getCart()).toBe(undefined);
         
     | 
| 
      
 84 
     | 
    
         
            +
            //     expect(useTestState().getState().cartId).toBe(undefined);
         
     | 
| 
      
 85 
     | 
    
         
            +
            //   }, timeOut);
         
     | 
| 
      
 86 
     | 
    
         
            +
            //   test("get_edit_buyer_data", async () => {
         
     | 
| 
      
 87 
     | 
    
         
            +
            //     const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
         
     | 
| 
      
 88 
     | 
    
         
            +
            //     const cart = await createCart(booking);
         
     | 
| 
      
 89 
     | 
    
         
            +
            //     // First, try to get the buyer data
         
     | 
| 
      
 90 
     | 
    
         
            +
            //     let buyerDataResponse = await booking.getBuyerPassengersDetails();
         
     | 
| 
      
 91 
     | 
    
         
            +
            //     expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
         
     | 
| 
      
 92 
     | 
    
         
            +
            //     let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
         
     | 
| 
      
 93 
     | 
    
         
            +
            //     expect(buyer).toBe(null);
         
     | 
| 
      
 94 
     | 
    
         
            +
            //     // Now try to edit the buyer data
         
     | 
| 
      
 95 
     | 
    
         
            +
            //     buyer = {
         
     | 
| 
      
 96 
     | 
    
         
            +
            //       id: 0,
         
     | 
| 
      
 97 
     | 
    
         
            +
            //       name: "TestName",
         
     | 
| 
      
 98 
     | 
    
         
            +
            //       lastName: "TestSurname",
         
     | 
| 
      
 99 
     | 
    
         
            +
            //       email: "testBookingLib@infos.it",
         
     | 
| 
      
 100 
     | 
    
         
            +
            //       phoneNumber: "+391234567890"
         
     | 
| 
      
 101 
     | 
    
         
            +
            //     }
         
     | 
| 
      
 102 
     | 
    
         
            +
            //     await booking.updateBuyerPassengersDetails(buyer);
         
     | 
| 
      
 103 
     | 
    
         
            +
            //     // Finally, get the buyer data again and check that the data was updated
         
     | 
| 
      
 104 
     | 
    
         
            +
            //     buyerDataResponse = await booking.getBuyerPassengersDetails();
         
     | 
| 
      
 105 
     | 
    
         
            +
            //     const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
         
     | 
| 
      
 106 
     | 
    
         
            +
            //     expect(updatedBuyer.id).toBeGreaterThan(0);
         
     | 
| 
      
 107 
     | 
    
         
            +
            //     expect(updatedBuyer.name).toBe(buyer.name);
         
     | 
| 
      
 108 
     | 
    
         
            +
            //     expect(updatedBuyer.lastName).toBe(buyer.lastName);
         
     | 
| 
      
 109 
     | 
    
         
            +
            //     expect(updatedBuyer.email).toBe(buyer.email);
         
     | 
| 
      
 110 
     | 
    
         
            +
            //     expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
         
     | 
| 
      
 111 
     | 
    
         
            +
            //     // Finally try to delete the cart
         
     | 
| 
      
 112 
     | 
    
         
            +
            //     await booking.deleteCart();
         
     | 
| 
      
 113 
     | 
    
         
            +
            //     expect(booking.getCart()).toBe(undefined);
         
     | 
| 
      
 114 
     | 
    
         
            +
            //     expect(useTestState().getState().cartId).toBe(undefined);
         
     | 
| 
      
 115 
     | 
    
         
            +
            //   }, timeOut);
         
     | 
| 
      
 116 
     | 
    
         
            +
            //   test("get_gateway_info", async () => {
         
     | 
| 
      
 117 
     | 
    
         
            +
            //     const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
         
     | 
| 
      
 118 
     | 
    
         
            +
            //     const cart = await createCart(booking);
         
     | 
| 
      
 119 
     | 
    
         
            +
            //     booking.updateSellerId(cart.sellerId);
         
     | 
| 
      
 120 
     | 
    
         
            +
            //     // First, try to get the buyer data
         
     | 
| 
      
 121 
     | 
    
         
            +
            //     let buyerDataResponse = await booking.getBuyerPassengersDetails();
         
     | 
| 
      
 122 
     | 
    
         
            +
            //     expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
         
     | 
| 
      
 123 
     | 
    
         
            +
            //     let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
         
     | 
| 
      
 124 
     | 
    
         
            +
            //     expect(buyer).toBe(null);
         
     | 
| 
      
 125 
     | 
    
         
            +
            //     // Now try to edit the buyer data
         
     | 
| 
      
 126 
     | 
    
         
            +
            //     buyer = {
         
     | 
| 
      
 127 
     | 
    
         
            +
            //       id: 0,
         
     | 
| 
      
 128 
     | 
    
         
            +
            //       name: "TestName",
         
     | 
| 
      
 129 
     | 
    
         
            +
            //       lastName: "TestSurname",
         
     | 
| 
      
 130 
     | 
    
         
            +
            //       email: "testBookingLib@infos.it",
         
     | 
| 
      
 131 
     | 
    
         
            +
            //       phoneNumber: "+391234567890"
         
     | 
| 
      
 132 
     | 
    
         
            +
            //     }
         
     | 
| 
      
 133 
     | 
    
         
            +
            //     await booking.updateBuyerPassengersDetails(buyer);
         
     | 
| 
      
 134 
     | 
    
         
            +
            //     // Try to get the gateways
         
     | 
| 
      
 135 
     | 
    
         
            +
            //     const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
         
     | 
| 
      
 136 
     | 
    
         
            +
            //     if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
         
     | 
| 
      
 137 
     | 
    
         
            +
            //       throw new Error("No gateways found");
         
     | 
| 
      
 138 
     | 
    
         
            +
            //     }
         
     | 
| 
      
 139 
     | 
    
         
            +
            //     const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
         
     | 
| 
      
 140 
     | 
    
         
            +
            //     expect(gateway?.id).toBeGreaterThan(0);
         
     | 
| 
      
 141 
     | 
    
         
            +
            //     // Now try to get the info
         
     | 
| 
      
 142 
     | 
    
         
            +
            //     const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
         
     | 
| 
      
 143 
     | 
    
         
            +
            //     // Finally try to delete the cart
         
     | 
| 
      
 144 
     | 
    
         
            +
            //     await booking.deleteCart();
         
     | 
| 
      
 145 
     | 
    
         
            +
            //     expect(booking.getCart()).toBe(undefined);
         
     | 
| 
      
 146 
     | 
    
         
            +
            //     expect(useTestState().getState().cartId).toBe(undefined);
         
     | 
| 
      
 147 
     | 
    
         
            +
            //   }, timeOut);
         
     | 
| 
      
 148 
     | 
    
         
            +
            // });
         
     | 
    
        package/lib/booking/booking.d.ts
    CHANGED
    
    | 
         @@ -2,8 +2,8 @@ import { MTSConfig, MTSEnvs } from "../config"; 
     | 
|
| 
       2 
2 
     | 
    
         
             
            import { ErrorResponse } from "../types/ErrorResponse";
         
     | 
| 
       3 
3 
     | 
    
         
             
            import { Cart, processedStepsToStatus } from "../types/common/Cart";
         
     | 
| 
       4 
4 
     | 
    
         
             
            import { GetExtrasForBookingResponse, GetExtrasResponse } from "../types/common/Extra";
         
     | 
| 
       5 
     | 
    
         
            -
            import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods,  
     | 
| 
       6 
     | 
    
         
            -
            import {  
     | 
| 
      
 5 
     | 
    
         
            +
            import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, IssueCartResponse } from "../types/common/Payment";
         
     | 
| 
      
 6 
     | 
    
         
            +
            import { PersonDetails, GetBuyerPassengersDetailsResponse, GetPersonRequest } from "../types/common/Person";
         
     | 
| 
       7 
7 
     | 
    
         
             
            import { AddReductionRequest } from "../types/common/Reduction";
         
     | 
| 
       8 
8 
     | 
    
         
             
            export declare abstract class Booking {
         
     | 
| 
       9 
9 
     | 
    
         
             
                private sellerId?;
         
     | 
| 
         @@ -21,8 +21,6 @@ export declare abstract class Booking { 
     | 
|
| 
       21 
21 
     | 
    
         
             
                 * - The third tells whether the section is required. <br/>
         
     | 
| 
       22 
22 
     | 
    
         
             
                 */
         
     | 
| 
       23 
23 
     | 
    
         
             
                bookingStepsToStatus: processedStepsToStatus;
         
     | 
| 
       24 
     | 
    
         
            -
                /** @deprecated Please use {@link cartGuid} instead */
         
     | 
| 
       25 
     | 
    
         
            -
                cartId: number | undefined;
         
     | 
| 
       26 
24 
     | 
    
         
             
                cartGuid: string | undefined;
         
     | 
| 
       27 
25 
     | 
    
         
             
                bookingDueDate: Date | undefined;
         
     | 
| 
       28 
26 
     | 
    
         
             
                /**
         
     | 
| 
         @@ -57,8 +55,13 @@ export declare abstract class Booking { 
     | 
|
| 
       57 
55 
     | 
    
         
             
                abstract deleteCart(): Promise<ErrorResponse | any>;
         
     | 
| 
       58 
56 
     | 
    
         
             
                abstract resetBooking(): void;
         
     | 
| 
       59 
57 
     | 
    
         
             
                abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
         
     | 
| 
       60 
     | 
    
         
            -
                abstract getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
         
     | 
| 
       61 
58 
     | 
    
         
             
                abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse | boolean>;
         
     | 
| 
      
 59 
     | 
    
         
            +
                /**
         
     | 
| 
      
 60 
     | 
    
         
            +
                 * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
         
     | 
| 
      
 61 
     | 
    
         
            +
                 * @param {GetPersonRequest} request The object containing the parameters to search the buyer.
         
     | 
| 
      
 62 
     | 
    
         
            +
                 * @returns An object of type {@link PersonDetails} containing the buyer information, or an {@link ErrorResponse} object in case of error.
         
     | 
| 
      
 63 
     | 
    
         
            +
                 */
         
     | 
| 
      
 64 
     | 
    
         
            +
                getPerson(request: GetPersonRequest): Promise<ErrorResponse | PersonDetails>;
         
     | 
| 
       62 
65 
     | 
    
         
             
                abstract addReduction(request: AddReductionRequest): Promise<ErrorResponse | boolean>;
         
     | 
| 
       63 
66 
     | 
    
         
             
                abstract removeReduction(tripId: number): Promise<ErrorResponse | boolean>;
         
     | 
| 
       64 
67 
     | 
    
         
             
                abstract useWallet(): Promise<ErrorResponse | boolean>;
         
     | 
| 
         @@ -81,9 +84,9 @@ export declare abstract class Booking { 
     | 
|
| 
       81 
84 
     | 
    
         
             
                 * @description This method shall be used to issue the tickets. It must be called after the payment was successful.
         
     | 
| 
       82 
85 
     | 
    
         
             
                 * @param {PaymentMethods} paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
         
     | 
| 
       83 
86 
     | 
    
         
             
                 * first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
         
     | 
| 
       84 
     | 
    
         
            -
                 * @returns An {@link  
     | 
| 
      
 87 
     | 
    
         
            +
                 * @returns An {@link IssueCartResponse} object.
         
     | 
| 
       85 
88 
     | 
    
         
             
                 */
         
     | 
| 
       86 
     | 
    
         
            -
                 
     | 
| 
      
 89 
     | 
    
         
            +
                issueCart(paymentMethod: PaymentMethods): Promise<ErrorResponse | IssueCartResponse>;
         
     | 
| 
       87 
90 
     | 
    
         
             
                getExtras({ extraId, tariffPlanId }?: {
         
     | 
| 
       88 
91 
     | 
    
         
             
                    /** The extra object identifier. By default, all the extras of the seller are returned. */
         
     | 
| 
       89 
92 
     | 
    
         
             
                    extraId?: number;
         
     | 
| 
         @@ -146,8 +149,8 @@ export declare namespace Booking { 
     | 
|
| 
       146 
149 
     | 
    
         
             
                    /** The language in which the app is running. Can be "it", "en", "fr", "de" */
         
     | 
| 
       147 
150 
     | 
    
         
             
                    language: Booking.Languages;
         
     | 
| 
       148 
151 
     | 
    
         
             
                    /**
         
     | 
| 
       149 
     | 
    
         
            -
                     * If true, the app will try to restore the state of the booking, reading the  
     | 
| 
       150 
     | 
    
         
            -
                     * After reading the  
     | 
| 
      
 152 
     | 
    
         
            +
                     * If true, the app will try to restore the state of the booking, reading the cartGuid from the mts-storage.
         
     | 
| 
      
 153 
     | 
    
         
            +
                     * After reading the cartGuid, the BE will be called to retrieve the status of the cart.
         
     | 
| 
       151 
154 
     | 
    
         
             
                     * E.g. set this to `true` if you want your booking to be preserved after a page refresh.
         
     | 
| 
       152 
155 
     | 
    
         
             
                     */
         
     | 
| 
       153 
156 
     | 
    
         
             
                    restoreState: boolean;
         
     | 
    
        package/lib/booking/booking.js
    CHANGED
    
    | 
         @@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 
     | 
|
| 
       20 
20 
     | 
    
         
             
                });
         
     | 
| 
       21 
21 
     | 
    
         
             
            };
         
     | 
| 
       22 
22 
     | 
    
         
             
            var __generator = (this && this.__generator) || function (thisArg, body) {
         
     | 
| 
       23 
     | 
    
         
            -
                var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
         
     | 
| 
       24 
     | 
    
         
            -
                return g =  
     | 
| 
      
 23 
     | 
    
         
            +
                var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
         
     | 
| 
      
 24 
     | 
    
         
            +
                return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
         
     | 
| 
       25 
25 
     | 
    
         
             
                function verb(n) { return function (v) { return step([n, v]); }; }
         
     | 
| 
       26 
26 
     | 
    
         
             
                function step(op) {
         
     | 
| 
       27 
27 
     | 
    
         
             
                    if (f) throw new TypeError("Generator is already executing.");
         
     | 
| 
         @@ -157,6 +157,7 @@ var Booking = /** @class */ (function () { 
     | 
|
| 
       157 
157 
     | 
    
         
             
                        this.language = Booking.Languages.EN;
         
     | 
| 
       158 
158 
     | 
    
         
             
                    }
         
     | 
| 
       159 
159 
     | 
    
         
             
                };
         
     | 
| 
      
 160 
     | 
    
         
            +
                // TODO: Add a test for this API once Extras are available on LinkAvel
         
     | 
| 
       160 
161 
     | 
    
         
             
                /**
         
     | 
| 
       161 
162 
     | 
    
         
             
                 * This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
         
     | 
| 
       162 
163 
     | 
    
         
             
                 * @param bookingStep The booking step to mark as completed
         
     | 
| 
         @@ -180,10 +181,10 @@ var Booking = /** @class */ (function () { 
     | 
|
| 
       180 
181 
     | 
    
         
             
                                throw Error("The step ".concat(bookingStep, " cannot be marked as completed because it is required"));
         
     | 
| 
       181 
182 
     | 
    
         
             
                            }
         
     | 
| 
       182 
183 
     | 
    
         
             
                            // Booking step is already completed, no need to call the API
         
     | 
| 
       183 
     | 
    
         
            -
                            if (currentStepStatus[ 
     | 
| 
      
 184 
     | 
    
         
            +
                            if (currentStepStatus[1])
         
     | 
| 
       184 
185 
     | 
    
         
             
                                return [2 /*return*/, true];
         
     | 
| 
       185 
186 
     | 
    
         
             
                            url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/bookingSteps");
         
     | 
| 
       186 
     | 
    
         
            -
                            return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep }).then(function (response) {
         
     | 
| 
      
 187 
     | 
    
         
            +
                            return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep, cartGuid: this.cartGuid }).then(function (response) {
         
     | 
| 
       187 
188 
     | 
    
         
             
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         
     | 
| 
       188 
189 
     | 
    
         
             
                                        return response;
         
     | 
| 
       189 
190 
     | 
    
         
             
                                    }
         
     | 
| 
         @@ -194,6 +195,41 @@ var Booking = /** @class */ (function () { 
     | 
|
| 
       194 
195 
     | 
    
         
             
                        });
         
     | 
| 
       195 
196 
     | 
    
         
             
                    });
         
     | 
| 
       196 
197 
     | 
    
         
             
                };
         
     | 
| 
      
 198 
     | 
    
         
            +
                /**
         
     | 
| 
      
 199 
     | 
    
         
            +
                 * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
         
     | 
| 
      
 200 
     | 
    
         
            +
                 * @param {GetPersonRequest} request The object containing the parameters to search the buyer.
         
     | 
| 
      
 201 
     | 
    
         
            +
                 * @returns An object of type {@link PersonDetails} containing the buyer information, or an {@link ErrorResponse} object in case of error.
         
     | 
| 
      
 202 
     | 
    
         
            +
                 */
         
     | 
| 
      
 203 
     | 
    
         
            +
                Booking.prototype.getPerson = function (request) {
         
     | 
| 
      
 204 
     | 
    
         
            +
                    return __awaiter(this, void 0, void 0, function () {
         
     | 
| 
      
 205 
     | 
    
         
            +
                        var buyerPassengersDetails, searchParams, url;
         
     | 
| 
      
 206 
     | 
    
         
            +
                        var _a;
         
     | 
| 
      
 207 
     | 
    
         
            +
                        return __generator(this, function (_b) {
         
     | 
| 
      
 208 
     | 
    
         
            +
                            // First check that it is possible to call this API
         
     | 
| 
      
 209 
     | 
    
         
            +
                            if ((0, utils_1.isNullOrWhiteSpace)(this.cartGuid)) {
         
     | 
| 
      
 210 
     | 
    
         
            +
                                throw Error("Cart is not initialized yet");
         
     | 
| 
      
 211 
     | 
    
         
            +
                            }
         
     | 
| 
      
 212 
     | 
    
         
            +
                            buyerPassengersDetails = this.bookingStepsToStatus.get(Booking.BookingSteps.BUYER_PASSENGERS);
         
     | 
| 
      
 213 
     | 
    
         
            +
                            if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
         
     | 
| 
      
 214 
     | 
    
         
            +
                                throw Error("The status of the cart does not allow to call this API");
         
     | 
| 
      
 215 
     | 
    
         
            +
                            }
         
     | 
| 
      
 216 
     | 
    
         
            +
                            if (!request.personId && !request.personCode && !request.phoneNumber) {
         
     | 
| 
      
 217 
     | 
    
         
            +
                                throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
         
     | 
| 
      
 218 
     | 
    
         
            +
                            }
         
     | 
| 
      
 219 
     | 
    
         
            +
                            searchParams = new URLSearchParams(__assign(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })), { includeSSN: "true" }));
         
     | 
| 
      
 220 
     | 
    
         
            +
                            url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
         
     | 
| 
      
 221 
     | 
    
         
            +
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         
     | 
| 
      
 222 
     | 
    
         
            +
                                    // Check for errors
         
     | 
| 
      
 223 
     | 
    
         
            +
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         
     | 
| 
      
 224 
     | 
    
         
            +
                                        return response;
         
     | 
| 
      
 225 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 226 
     | 
    
         
            +
                                    // Return the person details
         
     | 
| 
      
 227 
     | 
    
         
            +
                                    var person = __assign(__assign({}, response.persons[0]), { socialSecurityNumber: response.persons[0].personDetails.socialSecurityNumber });
         
     | 
| 
      
 228 
     | 
    
         
            +
                                    return person;
         
     | 
| 
      
 229 
     | 
    
         
            +
                                })];
         
     | 
| 
      
 230 
     | 
    
         
            +
                        });
         
     | 
| 
      
 231 
     | 
    
         
            +
                    });
         
     | 
| 
      
 232 
     | 
    
         
            +
                };
         
     | 
| 
       197 
233 
     | 
    
         
             
                //#endregion
         
     | 
| 
       198 
234 
     | 
    
         
             
                //#region Payment APIs
         
     | 
| 
       199 
235 
     | 
    
         
             
                /**
         
     | 
| 
         @@ -240,9 +276,9 @@ var Booking = /** @class */ (function () { 
     | 
|
| 
       240 
276 
     | 
    
         
             
                                    }
         
     | 
| 
       241 
277 
     | 
    
         
             
                                    _c.label = 5;
         
     | 
| 
       242 
278 
     | 
    
         
             
                                case 5:
         
     | 
| 
       243 
     | 
    
         
            -
                                    url = "".concat(this.config.API_ENDPOINT, "/v3_resources/sellers/ 
     | 
| 
      
 279 
     | 
    
         
            +
                                    url = "".concat(this.config.API_ENDPOINT, "/v3_resources/sellers/gateways?");
         
     | 
| 
       244 
280 
     | 
    
         
             
                                    // We use directly makeGet because we don't want to add sellerId to the query string (it is already present in the url)
         
     | 
| 
       245 
     | 
    
         
            -
                                    return [2 /*return*/,  
     | 
| 
      
 281 
     | 
    
         
            +
                                    return [2 /*return*/, this.callGetApi(url).then(function (response) {
         
     | 
| 
       246 
282 
     | 
    
         
             
                                            return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
         
     | 
| 
       247 
283 
     | 
    
         
             
                                                ? response
         
     | 
| 
       248 
284 
     | 
    
         
             
                                                : response;
         
     | 
| 
         @@ -280,14 +316,13 @@ var Booking = /** @class */ (function () { 
     | 
|
| 
       280 
316 
     | 
    
         
             
                        });
         
     | 
| 
       281 
317 
     | 
    
         
             
                    });
         
     | 
| 
       282 
318 
     | 
    
         
             
                };
         
     | 
| 
       283 
     | 
    
         
            -
                // TODO: Rename this as issueCart
         
     | 
| 
       284 
319 
     | 
    
         
             
                /**
         
     | 
| 
       285 
320 
     | 
    
         
             
                 * @description This method shall be used to issue the tickets. It must be called after the payment was successful.
         
     | 
| 
       286 
321 
     | 
    
         
             
                 * @param {PaymentMethods} paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
         
     | 
| 
       287 
322 
     | 
    
         
             
                 * first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
         
     | 
| 
       288 
     | 
    
         
            -
                 * @returns An {@link  
     | 
| 
      
 323 
     | 
    
         
            +
                 * @returns An {@link IssueCartResponse} object.
         
     | 
| 
       289 
324 
     | 
    
         
             
                 */
         
     | 
| 
       290 
     | 
    
         
            -
                Booking.prototype. 
     | 
| 
      
 325 
     | 
    
         
            +
                Booking.prototype.issueCart = function (paymentMethod) {
         
     | 
| 
       291 
326 
     | 
    
         
             
                    return __awaiter(this, void 0, void 0, function () {
         
     | 
| 
       292 
327 
     | 
    
         
             
                        var paymentMethodToSet, issueStep, _i, _a, step, url, body;
         
     | 
| 
       293 
328 
     | 
    
         
             
                        var _b;
         
     | 
| 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { ErrorResponse } from "../types/ErrorResponse";
         
     | 
| 
       2 
     | 
    
         
            -
            import {  
     | 
| 
      
 2 
     | 
    
         
            +
            import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
         
     | 
| 
       3 
3 
     | 
    
         
             
            import { AddReductionRequest } from "../types/common/Reduction";
         
     | 
| 
       4 
4 
     | 
    
         
             
            import { BusMatrix } from "../types/journeys/BusMatrix";
         
     | 
| 
       5 
5 
     | 
    
         
             
            import { CreateJourneyCartRequest, JourneyCart } from "../types/journeys/JourneyCart";
         
     | 
| 
         @@ -14,54 +14,47 @@ export declare class JourneyBooking extends Booking { 
     | 
|
| 
       14 
14 
     | 
    
         
             
                constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
         
     | 
| 
       15 
15 
     | 
    
         
             
                getCart(): JourneyCart | undefined;
         
     | 
| 
       16 
16 
     | 
    
         
             
                getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
         
     | 
| 
       17 
     | 
    
         
            -
                    cartId: number | undefined;
         
     | 
| 
       18 
17 
     | 
    
         
             
                    cartGuid: string | undefined;
         
     | 
| 
       19 
18 
     | 
    
         
             
                } & {
         
     | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
      
 19 
     | 
    
         
            +
                    updateCartGuid: (cartGuid: string | undefined) => void;
         
     | 
| 
       21 
20 
     | 
    
         
             
                    resetState: () => void;
         
     | 
| 
       22 
21 
     | 
    
         
             
                }>, "persist"> & {
         
     | 
| 
       23 
22 
     | 
    
         
             
                    persist: {
         
     | 
| 
       24 
23 
     | 
    
         
             
                        setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
         
     | 
| 
       25 
     | 
    
         
            -
                            cartId: number | undefined;
         
     | 
| 
       26 
24 
     | 
    
         
             
                            cartGuid: string | undefined;
         
     | 
| 
       27 
25 
     | 
    
         
             
                        } & {
         
     | 
| 
       28 
     | 
    
         
            -
                             
     | 
| 
      
 26 
     | 
    
         
            +
                            updateCartGuid: (cartGuid: string | undefined) => void;
         
     | 
| 
       29 
27 
     | 
    
         
             
                            resetState: () => void;
         
     | 
| 
       30 
28 
     | 
    
         
             
                        }, {
         
     | 
| 
       31 
     | 
    
         
            -
                            cartId: number | undefined;
         
     | 
| 
       32 
29 
     | 
    
         
             
                            cartGuid: string | undefined;
         
     | 
| 
       33 
30 
     | 
    
         
             
                        } & {
         
     | 
| 
       34 
     | 
    
         
            -
                             
     | 
| 
      
 31 
     | 
    
         
            +
                            updateCartGuid: (cartGuid: string | undefined) => void;
         
     | 
| 
       35 
32 
     | 
    
         
             
                            resetState: () => void;
         
     | 
| 
       36 
33 
     | 
    
         
             
                        }>>) => void;
         
     | 
| 
       37 
34 
     | 
    
         
             
                        clearStorage: () => void;
         
     | 
| 
       38 
35 
     | 
    
         
             
                        rehydrate: () => Promise<void> | void;
         
     | 
| 
       39 
36 
     | 
    
         
             
                        hasHydrated: () => boolean;
         
     | 
| 
       40 
37 
     | 
    
         
             
                        onHydrate: (fn: (state: {
         
     | 
| 
       41 
     | 
    
         
            -
                            cartId: number | undefined;
         
     | 
| 
       42 
38 
     | 
    
         
             
                            cartGuid: string | undefined;
         
     | 
| 
       43 
39 
     | 
    
         
             
                        } & {
         
     | 
| 
       44 
     | 
    
         
            -
                             
     | 
| 
      
 40 
     | 
    
         
            +
                            updateCartGuid: (cartGuid: string | undefined) => void;
         
     | 
| 
       45 
41 
     | 
    
         
             
                            resetState: () => void;
         
     | 
| 
       46 
42 
     | 
    
         
             
                        }) => void) => () => void;
         
     | 
| 
       47 
43 
     | 
    
         
             
                        onFinishHydration: (fn: (state: {
         
     | 
| 
       48 
     | 
    
         
            -
                            cartId: number | undefined;
         
     | 
| 
       49 
44 
     | 
    
         
             
                            cartGuid: string | undefined;
         
     | 
| 
       50 
45 
     | 
    
         
             
                        } & {
         
     | 
| 
       51 
     | 
    
         
            -
                             
     | 
| 
      
 46 
     | 
    
         
            +
                            updateCartGuid: (cartGuid: string | undefined) => void;
         
     | 
| 
       52 
47 
     | 
    
         
             
                            resetState: () => void;
         
     | 
| 
       53 
48 
     | 
    
         
             
                        }) => void) => () => void;
         
     | 
| 
       54 
49 
     | 
    
         
             
                        getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
         
     | 
| 
       55 
     | 
    
         
            -
                            cartId: number | undefined;
         
     | 
| 
       56 
50 
     | 
    
         
             
                            cartGuid: string | undefined;
         
     | 
| 
       57 
51 
     | 
    
         
             
                        } & {
         
     | 
| 
       58 
     | 
    
         
            -
                             
     | 
| 
      
 52 
     | 
    
         
            +
                            updateCartGuid: (cartGuid: string | undefined) => void;
         
     | 
| 
       59 
53 
     | 
    
         
             
                            resetState: () => void;
         
     | 
| 
       60 
54 
     | 
    
         
             
                        }, {
         
     | 
| 
       61 
     | 
    
         
            -
                            cartId: number | undefined;
         
     | 
| 
       62 
55 
     | 
    
         
             
                            cartGuid: string | undefined;
         
     | 
| 
       63 
56 
     | 
    
         
             
                        } & {
         
     | 
| 
       64 
     | 
    
         
            -
                             
     | 
| 
      
 57 
     | 
    
         
            +
                            updateCartGuid: (cartGuid: string | undefined) => void;
         
     | 
| 
       65 
58 
     | 
    
         
             
                            resetState: () => void;
         
     | 
| 
       66 
59 
     | 
    
         
             
                        }>>;
         
     | 
| 
       67 
60 
     | 
    
         
             
                    };
         
     | 
| 
         @@ -101,12 +94,6 @@ export declare class JourneyBooking extends Booking { 
     | 
|
| 
       101 
94 
     | 
    
         
             
                 * as well as a list of the available tariffs for each trip.
         
     | 
| 
       102 
95 
     | 
    
         
             
                 */
         
     | 
| 
       103 
96 
     | 
    
         
             
                getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
         
     | 
| 
       104 
     | 
    
         
            -
                /**
         
     | 
| 
       105 
     | 
    
         
            -
                 * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
         
     | 
| 
       106 
     | 
    
         
            -
                 * @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
         
     | 
| 
       107 
     | 
    
         
            -
                 * @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
         
     | 
| 
       108 
     | 
    
         
            -
                 */
         
     | 
| 
       109 
     | 
    
         
            -
                getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
         
     | 
| 
       110 
97 
     | 
    
         
             
                /**
         
     | 
| 
       111 
98 
     | 
    
         
             
                 * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
         
     | 
| 
       112 
99 
     | 
    
         
             
                 * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
         
     | 
| 
         @@ -35,8 +35,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 
     | 
|
| 
       35 
35 
     | 
    
         
             
                });
         
     | 
| 
       36 
36 
     | 
    
         
             
            };
         
     | 
| 
       37 
37 
     | 
    
         
             
            var __generator = (this && this.__generator) || function (thisArg, body) {
         
     | 
| 
       38 
     | 
    
         
            -
                var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
         
     | 
| 
       39 
     | 
    
         
            -
                return g =  
     | 
| 
      
 38 
     | 
    
         
            +
                var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
         
     | 
| 
      
 39 
     | 
    
         
            +
                return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
         
     | 
| 
       40 
40 
     | 
    
         
             
                function verb(n) { return function (v) { return step([n, v]); }; }
         
     | 
| 
       41 
41 
     | 
    
         
             
                function step(op) {
         
     | 
| 
       42 
42 
     | 
    
         
             
                    if (f) throw new TypeError("Generator is already executing.");
         
     | 
| 
         @@ -99,11 +99,8 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       99 
99 
     | 
    
         
             
                        resellerId: resellerId,
         
     | 
| 
       100 
100 
     | 
    
         
             
                        dbType: dbType
         
     | 
| 
       101 
101 
     | 
    
         
             
                    }) || this;
         
     | 
| 
       102 
     | 
    
         
            -
                    // Set  
     | 
| 
       103 
     | 
    
         
            -
                    var  
     | 
| 
       104 
     | 
    
         
            -
                    if (cartId && restoreState) {
         
     | 
| 
       105 
     | 
    
         
            -
                        _this.cartId = cartId;
         
     | 
| 
       106 
     | 
    
         
            -
                    }
         
     | 
| 
      
 102 
     | 
    
         
            +
                    // Set cartGuid
         
     | 
| 
      
 103 
     | 
    
         
            +
                    var cartGuid = _this.getStorage().getState().cartGuid;
         
     | 
| 
       107 
104 
     | 
    
         
             
                    if (cartGuid && restoreState) {
         
     | 
| 
       108 
105 
     | 
    
         
             
                        _this.cartGuid = cartGuid;
         
     | 
| 
       109 
106 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -120,16 +117,15 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       120 
117 
     | 
    
         
             
                };
         
     | 
| 
       121 
118 
     | 
    
         
             
                JourneyBooking.prototype.resetBooking = function () {
         
     | 
| 
       122 
119 
     | 
    
         
             
                    this.cart = undefined;
         
     | 
| 
       123 
     | 
    
         
            -
                    this.cartId = undefined;
         
     | 
| 
       124 
120 
     | 
    
         
             
                    this.cartGuid = undefined;
         
     | 
| 
       125 
121 
     | 
    
         
             
                    this.bookingStepsToStatus = new Map();
         
     | 
| 
       126 
122 
     | 
    
         
             
                    this.bookingDueDate = undefined;
         
     | 
| 
       127 
123 
     | 
    
         
             
                    try {
         
     | 
| 
       128 
     | 
    
         
            -
                        this.getStorage().getState(). 
     | 
| 
      
 124 
     | 
    
         
            +
                        this.getStorage().getState().updateCartGuid(undefined);
         
     | 
| 
       129 
125 
     | 
    
         
             
                    }
         
     | 
| 
       130 
126 
     | 
    
         
             
                    catch (e) {
         
     | 
| 
       131 
127 
     | 
    
         
             
                        if (this.config.ENV !== config_1.MTSEnvs.TEST) {
         
     | 
| 
       132 
     | 
    
         
            -
                            throw new Error("Error while deleting  
     | 
| 
      
 128 
     | 
    
         
            +
                            throw new Error("Error while deleting cartGuid from storage.");
         
     | 
| 
       133 
129 
     | 
    
         
             
                        }
         
     | 
| 
       134 
130 
     | 
    
         
             
                        console.log(e);
         
     | 
| 
       135 
131 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -145,7 +141,6 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       145 
141 
     | 
    
         
             
                                            cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
         
     | 
| 
       146 
142 
     | 
    
         
             
                                            if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
         
     | 
| 
       147 
143 
     | 
    
         
             
                                                _this.cart = cart;
         
     | 
| 
       148 
     | 
    
         
            -
                                                _this.cartId = cart.id;
         
     | 
| 
       149 
144 
     | 
    
         
             
                                                _this.cartGuid = cart.guid;
         
     | 
| 
       150 
145 
     | 
    
         
             
                                                _this.bookingDueDate = cartDueDate; // See Booking class
         
     | 
| 
       151 
146 
     | 
    
         
             
                                                // Update the sellerId. This is particularly important in Linkavel
         
     | 
| 
         @@ -259,7 +254,7 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       259 
254 
     | 
    
         
             
                            if (request.departureStopName === undefined || request.destinationStopName === undefined) {
         
     | 
| 
       260 
255 
     | 
    
         
             
                                throw Error("Fields departureStopName and destinationStopName are required");
         
     | 
| 
       261 
256 
     | 
    
         
             
                            }
         
     | 
| 
       262 
     | 
    
         
            -
                            searchParams = new URLSearchParams(__assign( 
     | 
| 
      
 257 
     | 
    
         
            +
                            searchParams = new URLSearchParams(__assign({ departureStopName: request.departureStopName, destinationStopName: request.destinationStopName, passengersNumber: request.passengersNumber.toString(), date: request.date, roundTripDate: request.roundTripDate ? request.roundTripDate : "null", currency: request.currency }, (this.cartGuid && { cartGuid: this.cartGuid })));
         
     | 
| 
       263 
258 
     | 
    
         
             
                            url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys?").concat(searchParams);
         
     | 
| 
       264 
259 
     | 
    
         
             
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         
     | 
| 
       265 
260 
     | 
    
         
             
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
         
     | 
| 
         @@ -279,15 +274,14 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       279 
274 
     | 
    
         
             
                            return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
         
     | 
| 
       280 
275 
     | 
    
         
             
                                    // Check for errors
         
     | 
| 
       281 
276 
     | 
    
         
             
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         
     | 
| 
       282 
     | 
    
         
            -
                                        // If there was an error, reset  
     | 
| 
      
 277 
     | 
    
         
            +
                                        // If there was an error, reset cartGuid and remove it from the mts-storage
         
     | 
| 
       283 
278 
     | 
    
         
             
                                        _this.resetBooking();
         
     | 
| 
       284 
279 
     | 
    
         
             
                                        return response;
         
     | 
| 
       285 
280 
     | 
    
         
             
                                    }
         
     | 
| 
       286 
281 
     | 
    
         
             
                                    _this.cart = response.cart;
         
     | 
| 
       287 
     | 
    
         
            -
                                    _this.cartId = response.cart.id;
         
     | 
| 
       288 
282 
     | 
    
         
             
                                    _this.cartGuid = response.cart.guid;
         
     | 
| 
       289 
     | 
    
         
            -
                                    // Save the  
     | 
| 
       290 
     | 
    
         
            -
                                    _this.getStorage().getState(). 
     | 
| 
      
 283 
     | 
    
         
            +
                                    // Save the cartGuid in the storage
         
     | 
| 
      
 284 
     | 
    
         
            +
                                    _this.getStorage().getState().updateCartGuid(response.cart.guid);
         
     | 
| 
       291 
285 
     | 
    
         
             
                                    // Fill the booking process status
         
     | 
| 
       292 
286 
     | 
    
         
             
                                    _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
         
     | 
| 
       293 
287 
     | 
    
         
             
                                    var cartDueDate = new Date();
         
     | 
| 
         @@ -355,40 +349,6 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       355 
349 
     | 
    
         
             
                        });
         
     | 
| 
       356 
350 
     | 
    
         
             
                    });
         
     | 
| 
       357 
351 
     | 
    
         
             
                };
         
     | 
| 
       358 
     | 
    
         
            -
                // TODO: rename this as getPerson and use personDetails as return type
         
     | 
| 
       359 
     | 
    
         
            -
                /**
         
     | 
| 
       360 
     | 
    
         
            -
                 * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
         
     | 
| 
       361 
     | 
    
         
            -
                 * @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
         
     | 
| 
       362 
     | 
    
         
            -
                 * @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
         
     | 
| 
       363 
     | 
    
         
            -
                 */
         
     | 
| 
       364 
     | 
    
         
            -
                JourneyBooking.prototype.getBuyer = function (request) {
         
     | 
| 
       365 
     | 
    
         
            -
                    return __awaiter(this, void 0, void 0, function () {
         
     | 
| 
       366 
     | 
    
         
            -
                        var buyerPassengersDetails, searchParams, url;
         
     | 
| 
       367 
     | 
    
         
            -
                        var _a;
         
     | 
| 
       368 
     | 
    
         
            -
                        return __generator(this, function (_b) {
         
     | 
| 
       369 
     | 
    
         
            -
                            // First check that it is possible to call this API
         
     | 
| 
       370 
     | 
    
         
            -
                            if (!this.cart) {
         
     | 
| 
       371 
     | 
    
         
            -
                                throw Error("Cart is not initialized yet");
         
     | 
| 
       372 
     | 
    
         
            -
                            }
         
     | 
| 
       373 
     | 
    
         
            -
                            buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
         
     | 
| 
       374 
     | 
    
         
            -
                            if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
         
     | 
| 
       375 
     | 
    
         
            -
                                throw Error("The status of the cart does not allow to call this API");
         
     | 
| 
       376 
     | 
    
         
            -
                            }
         
     | 
| 
       377 
     | 
    
         
            -
                            if (!request.personId && !request.personCode && !request.phoneNumber) {
         
     | 
| 
       378 
     | 
    
         
            -
                                throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
         
     | 
| 
       379 
     | 
    
         
            -
                            }
         
     | 
| 
       380 
     | 
    
         
            -
                            searchParams = new URLSearchParams(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })));
         
     | 
| 
       381 
     | 
    
         
            -
                            url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
         
     | 
| 
       382 
     | 
    
         
            -
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         
     | 
| 
       383 
     | 
    
         
            -
                                    // Check for errors
         
     | 
| 
       384 
     | 
    
         
            -
                                    if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         
     | 
| 
       385 
     | 
    
         
            -
                                        return response;
         
     | 
| 
       386 
     | 
    
         
            -
                                    }
         
     | 
| 
       387 
     | 
    
         
            -
                                    return response.persons[0];
         
     | 
| 
       388 
     | 
    
         
            -
                                })];
         
     | 
| 
       389 
     | 
    
         
            -
                        });
         
     | 
| 
       390 
     | 
    
         
            -
                    });
         
     | 
| 
       391 
     | 
    
         
            -
                };
         
     | 
| 
       392 
352 
     | 
    
         
             
                /**
         
     | 
| 
       393 
353 
     | 
    
         
             
                 * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
         
     | 
| 
       394 
354 
     | 
    
         
             
                 * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
         
     | 
| 
         @@ -448,10 +408,11 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       448 
408 
     | 
    
         
             
                                throw Error("The status of the cart does not allow to call this API");
         
     | 
| 
       449 
409 
     | 
    
         
             
                            }
         
     | 
| 
       450 
410 
     | 
    
         
             
                            searchParams = new URLSearchParams({
         
     | 
| 
      
 411 
     | 
    
         
            +
                                tripId: tripId.toString(),
         
     | 
| 
       451 
412 
     | 
    
         
             
                                departureStopId: departureStopId.toString(),
         
     | 
| 
       452 
413 
     | 
    
         
             
                                destinationStopId: destinationStopId.toString()
         
     | 
| 
       453 
414 
     | 
    
         
             
                            });
         
     | 
| 
       454 
     | 
    
         
            -
                            url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/ 
     | 
| 
      
 415 
     | 
    
         
            +
                            url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/seats?").concat(searchParams);
         
     | 
| 
       455 
416 
     | 
    
         
             
                            return [2 /*return*/, this.callGetApi(url).then(function (response) {
         
     | 
| 
       456 
417 
     | 
    
         
             
                                    return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
         
     | 
| 
       457 
418 
     | 
    
         
             
                                        ? response
         
     | 
| 
         @@ -593,7 +554,7 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       593 
554 
     | 
    
         
             
                                    _c.label = 5;
         
     | 
| 
       594 
555 
     | 
    
         
             
                                case 5:
         
     | 
| 
       595 
556 
     | 
    
         
             
                                    url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
         
     | 
| 
       596 
     | 
    
         
            -
                                    return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), {  
     | 
| 
      
 557 
     | 
    
         
            +
                                    return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid })).then(function (response) {
         
     | 
| 
       597 
558 
     | 
    
         
             
                                            var _a, _b;
         
     | 
| 
       598 
559 
     | 
    
         
             
                                            if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         
     | 
| 
       599 
560 
     | 
    
         
             
                                                return response;
         
     | 
| 
         @@ -628,7 +589,10 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       628 
589 
     | 
    
         
             
                            if (!discountsStep || !discountsStep[0]) {
         
     | 
| 
       629 
590 
     | 
    
         
             
                                throw Error("The status of the cart does not allow to call this API");
         
     | 
| 
       630 
591 
     | 
    
         
             
                            }
         
     | 
| 
       631 
     | 
    
         
            -
                            queryParams = new URLSearchParams({ 
     | 
| 
      
 592 
     | 
    
         
            +
                            queryParams = new URLSearchParams({
         
     | 
| 
      
 593 
     | 
    
         
            +
                                tripId: tripId.toString(),
         
     | 
| 
      
 594 
     | 
    
         
            +
                                cartGuid: this.cartGuid
         
     | 
| 
      
 595 
     | 
    
         
            +
                            });
         
     | 
| 
       632 
596 
     | 
    
         
             
                            url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
         
     | 
| 
       633 
597 
     | 
    
         
             
                            return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
         
     | 
| 
       634 
598 
     | 
    
         
             
                                    var _a, _b, _c;
         
     | 
| 
         @@ -697,7 +661,7 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       697 
661 
     | 
    
         
             
                                    _c.label = 5;
         
     | 
| 
       698 
662 
     | 
    
         
             
                                case 5:
         
     | 
| 
       699 
663 
     | 
    
         
             
                                    url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
         
     | 
| 
       700 
     | 
    
         
            -
                                    return [2 /*return*/, this.callPostApi(url, {  
     | 
| 
      
 664 
     | 
    
         
            +
                                    return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }).then(function (response) {
         
     | 
| 
       701 
665 
     | 
    
         
             
                                            var _a, _b;
         
     | 
| 
       702 
666 
     | 
    
         
             
                                            if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
         
     | 
| 
       703 
667 
     | 
    
         
             
                                                return response;
         
     | 
| 
         @@ -727,7 +691,7 @@ var JourneyBooking = /** @class */ (function (_super) { 
     | 
|
| 
       727 
691 
     | 
    
         
             
                            if ((0, utils_1.isNullOrWhiteSpace)(this.cartGuid)) {
         
     | 
| 
       728 
692 
     | 
    
         
             
                                throw Error("Cart is not initialized yet");
         
     | 
| 
       729 
693 
     | 
    
         
             
                            }
         
     | 
| 
       730 
     | 
    
         
            -
                            queryParams = new URLSearchParams({  
     | 
| 
      
 694 
     | 
    
         
            +
                            queryParams = new URLSearchParams({ cartGuid: this.cartGuid });
         
     | 
| 
       731 
695 
     | 
    
         
             
                            url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
         
     | 
| 
       732 
696 
     | 
    
         
             
                            return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
         
     | 
| 
       733 
697 
     | 
    
         
             
                                    var _a, _b, _c;
         
     | 
| 
         @@ -839,11 +803,10 @@ exports.JourneyBooking = JourneyBooking; 
     | 
|
| 
       839 
803 
     | 
    
         
             
                            case 3: return [2 /*return*/, booking];
         
     | 
| 
       840 
804 
     | 
    
         
             
                            case 4:
         
     | 
| 
       841 
805 
     | 
    
         
             
                                error_1 = _c.sent();
         
     | 
| 
       842 
     | 
    
         
            -
                                // Check if the error is due to an expired cart. In this case, delete the  
     | 
| 
      
 806 
     | 
    
         
            +
                                // Check if the error is due to an expired cart. In this case, delete the cartGuid from the mts-storage
         
     | 
| 
       843 
807 
     | 
    
         
             
                                // This error can occur when the user refreshes the page and the cart has expired
         
     | 
| 
       844 
808 
     | 
    
         
             
                                if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
         
     | 
| 
       845 
     | 
    
         
            -
                                    booking.getStorage().getState(). 
     | 
| 
       846 
     | 
    
         
            -
                                    booking.cartId = undefined;
         
     | 
| 
      
 809 
     | 
    
         
            +
                                    booking.getStorage().getState().updateCartGuid(undefined);
         
     | 
| 
       847 
810 
     | 
    
         
             
                                    booking.cartGuid = undefined;
         
     | 
| 
       848 
811 
     | 
    
         
             
                                    return [2 /*return*/, booking];
         
     | 
| 
       849 
812 
     | 
    
         
             
                                }
         
     |