# URL Templates For Payment Redirect

Upon booking an availability slot with a specific price, the user will be
redirected to your booking page using a URL that's defined by you. The steps
provided will show you how to do the following:

1. Define your URL Template.
2. Set your URL Template in your feeds.
3. Enable linkout per availability slot.
4. Verify fields in the Action Center.

## 1. Defining Your URL Template.

The uri template follows the Internet Engineering Task Force (IETF) RFC6570
Level 2 Uri Template specification, more details at [datatracker.ietf.org](https://datatrackietf.org/doc/html/rfc6570).
The URL is set by you with parameters that are dynamically populated with
information pertaining to that reservation. The following table includes
required and optional parameters available for your uri template.

    `https://reservation-provider.com/examplerestaurant/book?date={availability_slot_start_seconds}&num_guests={resources_party_size}`

### Available Values for URL Template

| **Template Parameters** | **Required / Optional** | **Feed** | **Field** | **Example Value** |
|---|---|---|---|---|
| availability_slot_start_seconds | Required | availability | start_sec | 4152695841 |
| resources_party_size | Required | availability.resources | party_size | 2 |
| availability_slot_availability_tag | Optional | availability | availability_tag | res-123 |
| availability_slot_duration_seconds | Optional | availability | duration_sec | 3600 |

> [!IMPORTANT]
> **Important:** It's recommended you start only with required parameters then add the rest as needed. If an optional parameter is in your uri_template but it's not defined in your feeds (and Availability RTUs, if applicable), the linkout experience won't appear for that slot.

## 2. Set your URI Template in your feed.

The following section assumes you have a live E2E integration with an existing
[Service Feed](https://developers.google.com/actions-center/verticals/reservations/e2e/reference/feeds/services-feed#Service-definition). The URL that you've defined will be set in the
Service feed, the following include the definition for that field.

    message Service {
      // ..
      UriTemplate uri_template = 38;
    }

> [!NOTE]
> **Note:** A Uri Template is defined for all availability slots tied to a service. If you need to set different parameters for a restaurant, you can do so by submitting different services with unique uri templates for each.

### Uri Template definition

```protobuf
// A template specifying how Google should generate URLs to external site.
message UriTemplate {
  // The uri template must follow the RFC6570, see
  // https://datatracker.ietf.org/doc/html/rfc6570.
  // Supports Level 2 templates.
  // These parameters will be resolved to their values specified in their
  // respective entities.
  //
  // Available parameters for Dining Reservation Linkout:
  // 1) (required) {availability_slot_start_seconds} :: populated from start_sec
  //   field in availability feed
  // 2) (required) {resources_party_size} :: populated from party_size field in
  //   availability feed
  // 3) (optional) {availability_slot_duration_seconds} :: populated from
  //   duration_sec field in availability feed
  // 4) (optional) {availability_slot_availability_tag} :: populated from
  //   availability_tag field in availability feed
  //
  // Example usage:
  // http://example.com/book/restaurant?start={availability_slot_start_seconds}
  // &num_guests={resources_party_size}
  // * start_sec = 123456
  // * party_size = 2
  // https://example.com/book/restaurant?start=123456&num_guests=2
  string uri_template = 1;
}
```

### Service Sample Definition

```json
{
  "metadata": {
    "processing_instruction": "PROCESS_AS_COMPLETE",
    "shard_number": 0,
    "total_shards": 1,
    "nonce": "12484913",
    "generation_timestamp": 1530432018
  },
  "service": [
    {
      "merchant_id": "dining-A",
      "service_id": "reservation",
      "uri_template": {
        "uri_template": "https://reservation-provider.com/examplerestaurant/book?date={availability_slot_start_seconds}&num_guests={resources_party_size}"
      },
      "localized_service_name": {
        "value": "Reservation",
        "localized_value": [
          {
            "locale": "en",
            "value": "Reservation"
          }
        ]
      }
    }
  ]
}
```

## 3. Enable linkout per availability slot.

The following section assumes you have a live E2E integration with an existing
[Availability Feed](https://developers.google.com/actions-center/verticals/reservations/e2e/reference/feeds/availability-feed#availability-definition). Once you've set the URL template in your
service feed, you will need to specify which of your availability slots will be
required to linkout.

You can do so by adding the `linkout_required_reason` field with a value of
`PAYMENT_REQUIRED`.

### Linkout Reason Definition

    message Availability {
      // ..
      LinkoutRequiredReason linkout_required_reason = 19;
    }

```protobuf
  // The reason why a slot requires a linkout. Currently only used for Dining
  // Reservations Payment Redirect Partners.
  enum LinkoutRequiredReason {
    // Default value: Do not use, equates to unknown.
    LINKOUT_REQUIRED_REASON_UNSPECIFIED = 0;
    // Slot requires payment in the partner platform to be booked.
    PAYMENT_REQUIRED = 1;
  }
```

### Linkout Reason Sample Definition

```json
{
  "metadata": {
    "processing_instruction": "PROCESS_AS_COMPLETE",
    "shard_number": 0,
    "total_shards": 1,
    "nonce": "11203880",
    "generation_timestamp": 1543875200
  },
  "service_availability": [
    {
      "availability": [
        {
          "merchant_id": "dining-A",
          "service_id": "reservation",
          "linkout_required_reason": "PAYMENT_REQUIRED",
          "start_sec": 1535853600,
          "duration_sec": 2700,
          "spots_total": 2,
          "spots_open": 2,
          "resources": {
            "room_id": "A-dining-room",
            "room_name": "Dining Room",
            "party_size": 2
          }
        }
      ]
    }
  ]
}
```

> [!IMPORTANT]
> **Important:** Once you've completed this step, the payment redirect slots will only appear if that slot has a payment configuration, more details in [Specifying Payment Types](https://developers.google.com/actions-center/verticals/reservations/e2e/add-ons/add-payments-redirect/specifying-payment-types)

## 4. Verify Fields in the Action Center

Once your feeds are successfully submitted and no errors are in the feed
history, you can verify the fields using the following steps.

> [!NOTE]
> **Note:** Keep in mind that feed processing can take between 4-8 hours. If you're not seeing the fields right away, you may need to wait longer.

### URL Template in the Inventory Viewer

You can find the URL Template definition in the Services section of a merchant's
inventory view. You'll find the template under the "feed snippet" section.
Refer to [Inventory View](https://developers.google.com/actions-center/verticals/reservations/e2e/partner-portal/inventory/inventory-view) for more details on the Merchant and
Service View.
![Figure 1: Example of finding a URL within the action center](https://developers.google.com/static/actions-center/images/reservations_debug_payments_url.png) **Figure 1:**Location of URL Template within the Action Center.

### Linkout Reason in the Availability Viewer

You can find the `linkout_required_reason` field when you view the specific
availability slot in [Availability View](https://developers.google.com/actions-center/verticals/reservations/e2e/partner-portal/inventory/availability-view).
![Figure 1: Example of finding a URL within the action center](https://developers.google.com/static/actions-center/images/reservations_debug_payments_linkout.png) **Figure 1:**Location of URL Template within the Action Center.