# Loyalty Gateway API

Connect Embed locations to 3rd party loyalty platforms to allow guests to redeem offers and earn loyalty points.

---

## Overview

The Embed Loyalty Gateway is a cloud-based synchronous proxy between Embed's internal services and an external Customer Integration Layer (CIL) for loyalty operations. It has two outbound HTTP integrations:

1. **CIL Proxy** — the main loyalty platform (configurable per operator)
2. **Identity Provider** — OAuth2 token exchange for client authentication

It allows a 3rd party loyalty platform to connect to Embed locations, either directly to the Loyalty Gateway or via a CIL.

When enabled, guest loyalty functionality can be provided through staff at a POS terminal with Embed SALES, or via self-service Embed Kiosk+.

### Phase 1 functionality

1. Validate guest loyalty account
2. Retrieve guest discount offers specific to products in the current sale
3. Redeem guest discount offers as part of the sale
4. Send finalised sale details to the loyalty platform

---

## Getting Started

![Loyalty Gateway integration diagram](../assets/loyalty-hub-integration.svg)

**Requirements:** TOOLKIT 2026.1.3 or later, and Infinity TOOLKIT INF-2026.10.1 or later.

Guests can access their loyalty accounts through both the Embed self-service Kiosk+ and via a staff member in Embed SALES. Access can be provided using one or two guest identifiers. The guest identifier(s) are completely custom to your loyalty program, and the guest- and staff-facing labels can be customised to suit.

### Key terms

| Term | Definition |
|------|------------|
| Loyalty Platform | A 3rd party loyalty software solution commonly used for guests to record purchase activity and earn points or rewards for later redemption. |
| Customer Integration Layer (CIL) | Middleware that sits between the Embed Loyalty Gateway and a 3rd party loyalty platform as a connector to facilitate data flow. |
| Loyalty offers | Offers or rewards given to or earned by guests that can be used as a form of discount against purchases. Can be in the form of percentage or dollar amounts. |
| Loyalty points | Commonly earned on loyalty programs based on purchases over a period of time. |
| Guest Identifier | Unique guest information used to access guest offers / rewards and record sales against the guest account. |

---

## Authentication

The Loyalty Gateway issues an access token in exchange for a client secret. Request a token first, then use it on subsequent requests.

### Getting an Access Token

Send your `client_secret` as a JSON body to the token endpoint:

```
POST https://{base-uri}/api/v1/token HTTP/1.1
Content-Type: application/json

{
  "client_secret": "{your_client_secret}"
}
```

### Request Body

| Field | Type | Description |
|-------|------|-------------|
| client_secret | string | The client secret provided by Embed. |

### Successful Response

`200 OK`

```json
{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "expires_in": 3600,
  "token_type": "Bearer"
}
```

| Field | Type | Description |
|-------|------|-------------|
| access_token | string | The access token to use on subsequent requests. |
| expires_in | integer | Token lifetime in seconds. |
| token_type | string | The type of token issued. |

### Error Response

`401 Unauthorized` is returned when the client secret is not valid. The body is a standard problem details object:

```json
{
  "type": "string",
  "title": "string",
  "status": 401,
  "detail": "string",
  "instance": "string"
}
```

### The flow to interact with the Loyalty Gateway

1. Obtain Client Secret.
2. Submit client secret to `/api/v1/token` and receive access token to be used in header.
3. Submit CIL details to `/api/v1/operators/config`.

```json
{
  "cilBaseUrl": "string",
  "apiKey": "string",
  "timeoutSeconds": 0
}
```

### CIL Proxy (named HttpClient: CilProxy)

Calls are made to a per-operator configurable base URL (`OperatorConfiguration.CilBaseUrl`), authenticated with a Bearer token and signed with HMAC-SHA256.

#### Resilience policies

| Policy | Configuration |
|--------|---------------|
| Retry | 3 attempts, exponential backoff (1s, 2s, 4s) |
| Circuit Breaker | Opens after 5 consecutive failures, 30s break |
| Timeout | 10 seconds per request |

#### HMAC signing

Every outbound CIL request includes these headers:

| Header | Value |
|--------|-------|
| X-LoyaltyHub-Signature | sha256={hex_digest} |
| X-LoyaltyHub-Timestamp | Unix epoch seconds |
| X-LoyaltyHub-Nonce | GUID |

Signature payload: `"{timestamp}.{nonce}.{body}"`, signed with `HMAC-SHA256(base64_decode(signing_key))`.
