---
sidebar_label: 'Example: Identity code in kiosk'
sidebar_position: 20
---
# Example: Identity code in kiosk
This page describes an example of what could be done by combining a [Code Interpreter](./code-interpreter.md), a discount calculator [handling deals](../handling-deals/overview.md) and a [frontend plugin](../../frontend-plugins/plugins-intro.md) showing membership information.
The example case supports a guest scanning a QR code in a kiosk. This code is used to authenticate to a loyalty integration (not a full login of the user, only a loyalty identity) and connecting the order to the guest identity for discounts and loyalty points perspective.
:::info
Example of the below is available in demo code on GitHub at [https://github.com/Future-Ordering/loyalty-integration-sample](https://github.com/Future-Ordering/loyalty-integration-sample).
:::
## Scanning a QR code for identity
When scanning the QR code for identity, the code will be sent to the Code Interpreter. If the Code Interpreter identifies that this code is a valid identity code, the Code Interpreter will call the Future Ordering APIs to [create a deal for the order](/api#tag/Deals/operation/creates-a-deal-for-order), then [reserve the deal on the order](/api#tag/Deals/operation/reserv-a-deal) and will finally respond with an action for the UI to welcome the person by name.
The Code Interpreter, when it creates the deal, attaches the identity of the user on the deal itself, so that the identity can be used in discount calculations later.
```mermaid
sequenceDiagram
participant guest as Guest
participant kiosk as Kiosk
participant fo as FO
participant loy as Loyalty
Integration
guest ->>+ kiosk : Scan identity code
kiosk ->>+ fo : What does this
code mean?
fo ->>+ loy : Do you know what
this code means?
note over loy: Validates code
loy -->>- fo: Yes, add deal for
guest 123 and
say "hello 123"
fo -->>- kiosk : say "hello 123"
kiosk -->>- guest : "hello 123"
```
## Discount calculation
Once the user has scanned the QR code for identity, each change to the order will trigger the reserved deal to have fulfillment requested. The fulfillment of a deal is to set which discounts it should provide.
Since the Code Interpreter part of the loyalty integration has attached the loyalty identifier of the user on the Deal, the discount calculation can use that identity to check which discounts the user should get. To see more about calculating discounts, please refer to the article on [handling deals](../handling-deals/overview.md).
```mermaid
sequenceDiagram
participant guest as Guest
participant kiosk as Kiosk
participant fo as FO
participant loy as Loyalty
Integration
note over guest, loy: This scenario is describing the situation
where the guest has previously
scanned an identity code
guest ->>+ kiosk : Add item to basket
kiosk ->>+ fo : Add item to basket
fo ->>+ loy : Order has changed,
what discounts should apply?
note over loy: Checks database to
determine discounts
loy -->>- fo: Set these discounts
fo -->>- kiosk : These discounts
have been set
kiosk -->>- guest : Here is the order
and the discounts
```
## Accumulate loyalty points (earn points)
In order to let guests earn points on their purchases, the loyalty integration can also subscribe a webhook for the event that occurs when the deal is captured. A captured deal means that the order is placed in POS correctly and that the deal is reserved on the order. For more detailed information about handling a captured deal, please refer to the article about [handling deals](../handling-deals/overview.md).
```mermaid
sequenceDiagram
participant guest as Guest
participant kiosk as Kiosk
participant fo as FO
participant loy as Loyalty
Integration
note over guest, loy: This scenario is for when the guest
completes placing their order
after scanning an identity code
guest ->>+ kiosk : Here is the payment
for the order
kiosk ->>+ fo : Register payment
note over fo: Order is paid,
Place in POS
fo -->> kiosk : Order placed
kiosk -->>- guest : Here is the order number
fo ->>+ loy : Capture the identity deal
note over loy: Calculates number of points
and adds to user's point total
loy -->>- fo: Deal captured
deactivate fo
```
## Show loyalty points
Given that the loyalty integration also exposes an endpoint for retrieving the number of accrued loyalty point, a frontend plugin can be made to show the loyalty identity and the number of points the user has.
The plugin could also provide ways for the user to burn points to apply discounts or similar, by calling the loyalty integration APIs which in turn sets new discounts on the order. This last case is not included in the below sequence diagram.
```mermaid
sequenceDiagram
participant guest as Guest
participant plugin as Frontend
Plugin
participant fo as FO
participant loy as Loyalty
Integration
note over guest, loy: Guest navigates to
loyalty plugin page component
or any page with a loyalty block component
plugin ->>+ loy: Get loyalty points for current order
loy ->>+ fo: Get deals on order
fo -->>- loy: Here are the deals
loy ->> loy: Get the loyalty member id
from the identity deal
loy ->> loy: Get the loyalty points
from db or loyalty system
loy ->>- plugin: Return loyalty points
```