GetTripOptions 方法

此方法可为指定行程提供高级别的票务组。这些对象包含一组具有所选服务舱位的航段,这些航段可使用同一张机票预订,还包含机票的整体票价和供应情况信息。请注意:

GetTripOptionsRequest

Proto 定义

// Request sent to partners.
message GetTripOptionsRequest {
  // All segments together should form a single trip for which a ticket can be
  // booked.
  repeated ext.travel.transport.partner.SegmentKey segment_keys = 1;
}

JSON 示例

{
  "segment_keys": [
    {
      "ticketing_trip_id": "123456",
      "from_ticketing_stop_time_id": "ZRH-1234",
      "to_ticketing_stop_time_id": "LUZ-1235",
      "service_date": {
        "year": 2022,
        "month": 4,
        "day": 6
      },
      "boarding_time": {
        "year": 2022,
        "month": 4,
        "day": 6,
        "hours": 14,
        "minutes": 25,
        "seconds": 0,
        "nanos": 0,
        "utc_offset": "0s"
      },
      "arrival_time": {
        "year": 2022,
        "month": 4,
        "day": 6,
        "hours": 16,
        "minutes": 25,
        "seconds": 0,
        "nanos": 0,
        "utc_offset": "0s"
      }
    },
    {
      "ticketing_trip_id": "234567",
      "from_ticketing_stop_time_id": "LUZ-2759",
      "to_ticketing_stop_time_id": "WOL-2455",
      "service_date": {
        "year": 2022,
        "month": 4,
        "day": 6
      },
      "boarding_time": {
        "year": 2022,
        "month": 4,
        "day": 6,
        "hours": 18,
        "minutes": 13,
        "seconds": 0,
        "nanos": 0,
        "utc_offset": "0s"
      },
      "arrival_time": {
        "year": 2022,
        "month": 4,
        "day": 6,
        "hours": 20,
        "minutes": 13,
        "seconds": 0,
        "nanos": 0,
        "utc_offset": "0s"
      }
    }
  ]
}

GetTripOptionsResponse

Proto 定义

// Response received from partners.
message GetTripOptionsResponse {
  oneof response {
    TripOptionsResult trip_options_result = 1;
    TripOptionsError trip_options_error = 2;
  }
}

// A successful partner response.
message TripOptionsResult {
  // Note:
  // - A TripOption represents the fare for a combination of available service
  //   classes for the segments in the request.
  // - If the seats within a service class are sold at different fares of
  //   limited availability, a different TripOption instance with the same
  //   sequence of segments can be returned for each fare.

  // Partners should also include options that are unavailable because they are
  // fully booked, using the appropriate Unavailable message below.
  repeated TripOption trip_options = 1;
}


// A travel option for users covering the whole end-to-end journey with the
// partner.
message TripOption {
  // A series of Segments that cover the whole trip option, one for each
  // SegmentKey in the request.
  repeated Segment segments = 1;

  // This is the lowest standard fare of all seats with the specified segments.
  // This field is optional if the series of segments is unavailable.
  // This "standard fare" should be the lowest seat price where no age or other
  // booking restrictions apply. The currency should be the local currency of
  // the origin of the first segment.
  Fare lowest_standard_fare = 2;

  // The availability status for bookings of this trip option at the
  // lowest_standard_fare.
  Availability availability = 3;

  // This is used to receive optional extra data via the Travel Transport API
  // and pass it into the ticketing deep link.
  // Booking links should still work without the booking token, but the token
  // can be used to ensure price consistency between Google Search results and
  // the partner booking page.
  string booking_token = 4 [features.field_presence = EXPLICIT];
}

// A segment traveled on a single vehicle in a given Service Class.
message Segment {
  SegmentKey segment_key = 1;

  // The service class used on this segment.
  ServiceClass service_class = 2;
}

JSON 示例

{
  "trip_options_result": {
    "trip_options": [
      {
        "segments": [
          {
            "segment_key": {
              "ticketing_trip_id": "123456",
              "from_ticketing_stop_time_id": "ZRH-1234",
              "to_ticketing_stop_time_id": "LUZ-1235",
              "service_date": {
                "year": 2022,
                "month": 4,
                "day": 6
              },
              "boarding_time": {
                "year": 2022,
                "month": 4,
                "day": 6,
                "hours": 14,
                "minutes": 25,
                "seconds": 0,
                "utc_offset": "0s"
              },
              "arrival_time": {
                "year": 2022,
                "month": 4,
                "day": 6,
                "hours": 16,
                "minutes": 25,
                "seconds": 0,
                "utc_offset": "0s"
              }
            },
            "service_class": {
              "type": "FIRST_CLASS"
            }
          },
          {
            "segment_key": {
              "ticketing_trip_id": "234567",
              "from_ticketing_stop_time_id": "LUZ-2759",
              "to_ticketing_stop_time_id": "WOL-2455",
              "service_date": {
                "year": 2022,
                "month": 4,
                "day": 6
              },
              "boarding_time": {
                "year": 2022,
                "month": 4,
                "day": 6,
                "hours": 18,
                "minutes": 13,
                "seconds": 0,
                "utc_offset": "0s"
              },
              "arrival_time": {
                "year": 2022,
                "month": 4,
                "day": 6,
                "hours": 20,
                "minutes": 13,
                "seconds": 0,
                "utc_offset": "0s"
              }
            },
            "service_class": {
              "type": "FIRST_CLASS"
            }
          }
        ],
        "lowest_standard_fare": {
          "total_amount": {
            "units": 15,
            "nanos": 0,
            "currency_code": "CHF"
          },
          "line_items": [
            {
              "line_item_type": "BASE_FARE",
              "amount": {
                "units": 13,
                "nanos": 950000000,
                "currency_code": "CHF"
              }
            },
            {
              "line_item_type": "SERVICE_CHARGE",
              "amount": {
                "units": 1,
                "nanos": 50000000,
                "currency_code": "CHF"
              }
            }
          ]
        },
        "availability": {
          "available": {
            "available_seat_count": 10,
            "total_seat_count": 30
          }
        }
      },
      {
        "segments": [
          {
            "segment_key": {
              "ticketing_trip_id": "123456",
              "from_ticketing_stop_time_id": "ZRH-1234",
              "to_ticketing_stop_time_id": "LUZ-1235",
              "service_date": {
                "year": 2022,
                "month": 4,
                "day": 6
              },
              "boarding_time": {
                "year": 2022,
                "month": 4,
                "day": 6,
                "hours": 14,
                "minutes": 25,
                "seconds": 0,
                "utc_offset": "0s"
              },
              "arrival_time": {
                "year": 2022,
                "month": 4,
                "day": 6,
                "hours": 16,
                "minutes": 25,
                "seconds": 0,
                "utc_offset": "0s"
              }
            },
            "service_class": {
              "type": "SECOND_CLASS"
            }
          },
          {
            "segment_key": {
              "ticketing_trip_id": "234567",
              "from_ticketing_stop_time_id": "LUZ-2759",
              "to_ticketing_stop_time_id": "WOL-2455",
              "service_date": {
                "year": 2022,
                "month": 4,
                "day": 6
              },
              "boarding_time": {
                "year": 2022,
                "month": 4,
                "day": 6,
                "hours": 18,
                "minutes": 13,
                "seconds": 0,
                "utc_offset": "0s"
              },
              "arrival_time": {
                "year": 2022,
                "month": 4,
                "day": 6,
                "hours": 20,
                "minutes": 13,
                "seconds": 0,
                "utc_offset": "0s"
              }
            },
            "service_class": {
              "type": "SECOND_CLASS"
            }
          }
        ],
        "lowest_standard_fare": {
          "total_amount": {
            "units": 10,
            "nanos": 0,
            "currency_code": "CHF"
          },
          "line_items": [
            {
              "line_item_type": "BASE_FARE",
              "amount": {
                "units": 9,
                "nanos": 750000000,
                "currency_code": "CHF"
              }
            },
            {
              "line_item_type": "SERVICE_CHARGE",
              "amount": {
                "units": 0,
                "nanos": 250000000,
                "currency_code": "CHF"
              }
            }
          ]
        },
        "availability": {
          "available": {
            "available_seat_count": 44,
            "total_seat_count": 200
          }
        }
      }
    ]
  }
}

JSON 错误示例

{
  "trip_options_error": {
    "error_type": "SEGMENT_KEY_NOT_FOUND",
    "error_message": "No matching segments found, no departures at 14:25"
  }
}

API 实现备注:

为了实现与潜在更改的向前兼容性,如果在段键中遇到其他参数,请务必在响应中返回这些参数。否则,请忽略这些参数,并将请求视为没有这些参数,直到您实现对这些参数的特定支持。

错误响应

下表介绍了此方法的错误报告预期:

错误类型 可重试 HTTP 状态代码 说明
SEGMENT_KEY_NOT_FOUND 404 找不到与所提供的某个 SegmentKey 对应的细分。
TRIP_OPTION_CACHE_STALE 404 所请求的行程选项的数据在合作伙伴处不是最新数据,需要刷新才能提供给 Google。
INTERNAL_ERROR 500 在检索此行程期间发生了意外错误。这表示存在需要合作伙伴修复的 bug。
SUBOPTIMAL_ITINERARY 404 系统找到了相应行程,但合作伙伴认为该行程不是最佳选择,因此选择不销售该行程的机票。
TICKETING_PROHIBITED 404 我们找到了相应行程,但由于运营商或铁路部门施加了一般售票限制,合作伙伴无法销售该行程的车票。
BOOKING_WINDOW_NOT_SUPPORTED 404 合作伙伴不支持所请求日期的行程价格。

如需了解详情,请参阅 TripOptionsErrorType

如需了解 HTTP 响应中的状态代码返回,请参阅状态代码和错误处理