# Templates (/docs/products/ussd-flows/developers/templates/overview)

Templates are built-in steps you add to a flow as a page. They do work that would otherwise need your own exchange endpoint.

## Available Templates

| Template                                                                                        | What it does                                                                  |
| ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [`collect_payment`](/docs/products/ussd-flows/developers/templates/collect-payment)             | Asks the subscriber to approve a mobile money payment with their PIN          |
| [`get_subscriber_msisdn`](/docs/products/ussd-flows/developers/templates/get-subscriber-msisdn) | Asks the subscriber for permission to use their phone number                  |
| [`get_provider_kyc_name`](/docs/products/ussd-flows/developers/templates/get-provider-kyc-name) | Gets the name the subscriber's account is registered under with their network |
| [`get_server_time`](/docs/products/ussd-flows/developers/templates/get-server-time)             | Gets the current time                                                         |

## Page Structure

```json
{
  "id": "page_id",
  "component": {
    "type": "template",
    "label": "Text shown to the subscriber",
    "template_name": "collect_payment",
    "template_data": {
      "payment_target_ref": "7150001234"
    }
  }
}
```

| Property        | Type   | Required              | Description                                                                                                                                                           |
| --------------- | ------ | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type`          | string | Yes                   | Must be `"template"`                                                                                                                                                  |
| `template_name` | string | Yes                   | Which template to run                                                                                                                                                 |
| `label`         | string | For `collect_payment` | The question on screen. Only `collect_payment` (the PIN prompt) and `get_subscriber_msisdn` (the permission question) show a label. The other templates show nothing. |
| `template_data` | object | For `collect_payment` | Settings for the template. Templates that take none can leave it out.                                                                                                 |

## What a Template Returns

Each template sets its page value. Read it with `$(page.PAGE_ID.value)`:

| Template                | Page value                                            |
| ----------------------- | ----------------------------------------------------- |
| `collect_payment`       | The transaction ID                                    |
| `get_subscriber_msisdn` | The phone number, or empty if the subscriber said no  |
| `get_provider_kyc_name` | The registered name, or empty if the network has none |
| `get_server_time`       | The current time in UTC                               |

There are no other keys. A reference like `$(page.pay.payment_status)` stops the flow with an error.

## Example

This flow asks for an amount, takes the payment, and shows the transaction ID:

```json
{
  "version": "1.0",
  "pages": [
    {
      "id": "enter_amount",
      "component": {
        "type": "prompt",
        "label": "Enter amount (SLE 100 to 10,000):",
        "data_type": "integer",
        "min_value": 100,
        "max_value": 10000
      }
    },
    {
      "id": "process_payment",
      "component": {
        "type": "template",
        "label": "Enter your $(session.network_provider_name) PIN to pay {{amount}} to Kroo Bay Clinic.",
        "template_name": "collect_payment",
        "template_data": {
          "payment_target_ref": "7150001234",
          "amount": "$(page.enter_amount.value)",
          "reference": "CLINIC-FEE",
          "receipt_name": "Kroo Bay Clinic fee"
        }
      }
    },
    {
      "id": "payment_done",
      "component": {
        "type": "display",
        "label": "Paid SLE $(page.enter_amount.value).\nRef: $(page.process_payment.value)"
      }
    }
  ]
}
```
