Making a reservation purchase with associated items as ssrs

Making a purchase with associated (paid_in) items involves several steps.

Please make sure you read the Conventions before continuing with this guide.

Prerequisites

You will need an X-API-KEY and a Basic Access Authentication token generated from your username and password.

Steps to complete a purchase

1) Select a product

Get the list of configured products, select one, and remember its _id. The product that you select will determine which Fares (and Fare Classes, if in use) are available when performing a Trip Search and making a purchase.

If you have configured Fare Classes for your passengers, you must select a product with pricingType = "journey" to make use of Fare Classes in the following steps.

2) Get the information of the (paid in) items you want to associate to the reservation purchase

Notice that:

  • associatedProductId is the id of the product we selected on point #1,
  • disabled, it filters items if they are disabled or not,
  • type the only value possible here is "paid_in",
  • providerIds is the id of the provider to get products for

This will return an array of items

As a result you should select the list of items you want to associate to the reservation purchase, taking into account we only need those having attachToTicket set as true, since they will have an associatedProductId set too. You will need to add the _id of the selected items to the cart later.

3) Select fares

Get available fares for the product that you have selected, using your product's _id as a filter parameter.

Take note of the ids of the fares you need for the purchase.

4) Select an origin station

Get all possible origin stations for your selected product.

Select an origin station, and remember its _id.

5) Select a destination station

After selecting an 'origin' station, get all possible destination stations that can be reached from that starting point.

This endpoint does not guarantee that there are schedules available between the origin and destination stations - this can only be determined by performing a Trip Search.

Select a destination station, and remember its _id - this will be needed when searching for Trips.

6) Select trips

Find trips that are available for your selected product, fares, origin, destination, and travel date(s).

From the results, select a single departure trip. If searching for a round-trip, also select a return trip. Remember each trip id, a long hash that will look something like this:

{
  "id": "eyJhY2NvdW50SWQiOiI1OTEwY2ZiYWZhMWI5MDRkMGMwMDAwMTUiLCJwcm9kdWN0SWQiOiI1OTEwY2ZiYWZhMWI5MDRkMGMwMDAwMTYiLCJvcmlnaW5JZCI6IjU5MjQ1OTBlOTk4MmNmMjA3YzBkZjQwMCIsImRlc3RpbmF0aW9uSWQiOiI1OTI0NTkyODk5ODJjZjIwN2MwZGY0MDEiLCJmYXJlSWRzIjoiNTkyNDViNTc5OTgyY2YyMDdjMGRmNDAyOjEiLCJkZXBhcnR1cmVEYXRlIjoiMjAxNy0xMC0yOCIsImRlcGFydHVyZVRpbWUiOiIwOTowMCIsImNoYW5uZWwiOiJ3ZWJzYWxlcyIsInNlZ21lbnRzIjpbeyJyb3V0ZUlkIjoiNTkyNDU5NDE1MDJjYzcxMDcyMDAwMDFlIiwic2NoZWR1bGVJZCI6IjU0MGZkNWQ5LThiZDEtNGIxNS05ZDZlLTJiNzk3ZmFhYWM1NyIsIm9yaWdpbiI6IkJlcmxpbiBDZW50cmFsIGJ1cyBzdGF0aW9uIChaT0IpIiwiZGVzdGluYXRpb24iOiJXYXJzYXcgV2VzdCBidXMgc3RhdGlvbiJ9XSwidGlja2V0VHlwZSI6Im9uZXdheSJ9"
}

If Fare Classes are being used, you will need to select the passenger's desired Fare Class for their outbound and return trip. Select one Fare Class from the departure trip, and remember it's id. If you searched for a round trip, also select a Fare Class from the return trip, and remember its id. These Fare Class ids will need to be specified when adding the item to the shopping cart. (You can learn more about working with fare classes here).

7) Authenticate

You are almost ready to add the trip into the shopping cart. First, you must authenticate.

Store the shortToken from the authentication response, so that you can use it in subsequent API calls.

8) Add an item to the cart

Add the selected trip to the shopping cart. Check the section Adding an item with associated (paid-in) items as SSRs in order to fill the items array of the passengers properly, according to the list of associated (paid-in) items we selected on point #2.

Remember the cartId and the total from the response. You will need this information to complete the order.

(At this point you may want to apply a promo).

9) Select a payment type

To complete the order, first retrieve the available payment types and select one. Remember the method field.

10) Select country and province info for the customer

Get our list of country and province information, and remember the result.

You will need a valid ISO code of a country and a province (if it applies) to complete the customer information when paying for the order, in the next step.

11) Create the order

Create an order (pay for the items in the cart) using the information from the previous steps. The Postman collection below contain an optional example of how to make a purchase using a saved customer credit card.

Once the payment is accepted, the booking is complete. Take note of the transactionIds if you need to perform further actions, like downloading the tickets.

12) (Optional) Download tickets

In some cases you may want to download tickets for the booking. The tickets are downloaded as PDF files.

Postman resources

If you would like to use Postman to test the API, we have included a collection you can use as a starting point below.

This collection is designed to allow you to purchase a reservation, by following the steps above.
In order to use it successfully, you will need your X-API-KEY and data (like stations, routes, payment types and so on) set up for your account.

After importing the collection, and the environment, make sure your collection is using the new environment, and that you have set the initial values. On each step, you should manually add the missing environmental values with the values you get from the previous steps.

If you are going to be using our API in sandbox, please change the {{basePath}} environment variable to https://sandbox-api.betterez.com.

Postman Collection

Postman Environment