Making an open return purchase

Making a purchase 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.

For this particular scenario the product that you will select has to be configured with pricingType = "journey", openReturn = true and openReturnBundleId: bundle-id-of-bundle-configured-as-open-return.

2) 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.

3) Select an origin station

Get all possible origin stations for your selected product.

Select an origin station, and remember its _id.

4) 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.

5) Select trips

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

In this case we only need to search for one way trips, meaning you should send departureDate with some valid value, but returnDate without any value.

From the results, select a single departure 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).

6) 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.

7) Add an item to the cart

Add the selected trip to the shopping cart.

The reservation item for the cart will have a pair openReturn: true in the payload.

This will generate a cart with two items, one reservation ticket and one redeemable item that you will be able to download once the payment is done.

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).

8) Retrieve payment types

To complete the order, first retrieve the available payment types and select one. Remember, these must be the payment types for the main provider, "Provider A" in our example.

9) Complete the order

Create an order (pay for the items in the cart) using one of the available payment types.

Once the payment is accepted, the booking is complete.

10) Download tickets

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

You will receive an asociate redeemable item for the return, to get a new ticket you will need to redeem it.

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