---
# System prepended metadata

title: Sancus Front End

---

Sancus Front End
===
Rough working flow of Sancus frontend.

## Table of content
- [Root Route](#Root-Route)
- [Views](#Views)
    - [Home Page](#Home-Page)
    - [Level Details Page](#Level-Details-Page)
    - [Deal Details Page](#Deal-Details-Page)
    - [Benefit Details Page](#Benefit-Details-Page)
    - [QR Scan Benefit](#QR-Scan-Benefit)
        - [Benefit Avail Page](#Benefit-Avail-Page)
        - [Benefit Verification Page](#Benefit-Verification-Page)
- [APIs](#APIs)
    - [Purchase a Deal API](#Purchase-a-Deal-API)
    - [Filter Benefits API](#Filter-Benefits-API)
---

## Root Route
* #### Validate session.
    
```javascript=
pocketClient.ReqValidateSession({
    "token": token
}, pocketMetadata,  (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    }
    console.log(JSON.stringify(response, null, " "))
})
```
1. if the user has valid token, redirect to home url.
2. else, redirect to cancel url.

## Views

### Home Page
* #### Get Pocket by Id
```javascript=
pocketClient.GetPocketByID({
    "id": "858af6104b7e44048bbbe6addad44daf"
}, pocketMetadata,  (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    }
    console.log(JSON.stringify(response, null, " "))
})
```
* #### List Tied Deals for the user
```javascript=
marketplaceClient.ListTiedDeals({
    "user_id": "users legacy_id",
    "level": "user level"
}, marketplaceMetadata, (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    } else {
        console.log(JSON.stringify(response, null, " "))
    }
})
```
- For every returned deal, check,
    1. if the user level is greater than the level of the deals. active the deal.
    2. else, deactivate the deal.

* #### List Benefits
```javascript=
marketplaceClient.ListBenefits({
    "status": "published",
    "level": "user level",
    "city":"user city",
    "visibility": true
}, marketplaceMetadata, (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    } else {
        console.log(JSON.stringify(response, null, " "))
    }
})
```
- For every returned benefit, check,
    1. if that user is eligible for that benefit.if yes, put it on final list that we'll show to that user.


P.S. in case of error at any of the stages, redirect to error page.

### Level Details Page
- Parent page -> [Home Page](#Home-Page)
* #### Load FAQ.
* #### Get Pocket by Id
```javascript=
pocketClient.GetPocketByID({
    "id": "858af6104b7e44048bbbe6addad44daf"
}, pocketMetadata,  (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    }
    console.log(JSON.stringify(response, null, " "))
})
```
1. Take the details of points from the above call.


### Deal Details Page
* #### Get Deal by id.
```javascript=
marketplaceClient.GetDealByID({
    "id": "deal id"
}, marketplaceMetadata,  (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    }
    console.log(JSON.stringify(response, null, " "))
})
```

1. if the user is eligible to get the benefit. activate the purchase button.


### Benefit Details Page
- Parent page -> [Home Page](#Home-Page)

* #### Get Benefit Details by id.
```javascript=
marketplaceClient.GetBenefitByID({
    "id": "603ba0c8c393e30001799d48"
}, marketplaceMetadata,  (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    }
    console.log(JSON.stringify(response, null, " "))
})
```

### QR Scan Benefit

- Parent page -> [Home Page](#Home-Page) or [Benefit Details page](#Benefit-Details-Page)

* #### Get Benefit by QR

```javascript=
marketplaceClient.ListBenefits({
    "partner_mobile_number": "partner mobile number of that benefit",
    "expired": true // true means check if it's already expired or not
}, marketplaceMetadata, (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    } else {
        console.log(JSON.stringify(response, null, " "))
    }
})
```
1. check, 
    1. if the benefit is expired or not.if expired, redirect to expired page.
    2. if it's event exists. if not found, redirect to benefit not found.
3. if published and valid and the user is eligible for that benefit, 
    1. redirect the user to benefit avail page if it's a percentage benefit.
    2. redirect to benefit verification page if its a benefit verification modality.


### Benefit Avail Page
- Parent -> [QR Scan Benefit](#QR-Scan-Benefit)

```javascript=
marketplaceClient.ReqCheckBenefitValidity({
    "benefit_id": "partner mobile number of that benefit",
    "user_id": "user's pocket id",
    "amount": (type int64)
}, marketplaceMetadata, (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    } else {
        console.log(JSON.stringify(response, null, " "))
    }
})
```

### Benefit Verification Page
- Parent -> [QR Scan Benefit](#QR-Scan-Benefit)

```javascript=
marketplaceClient.ReqCheckBenefitValidity({
    "benefit_id": "partner mobile number of that benefit",
    "user_id": "user's pocket id",
    "amount": 0 // as it's a verification modality.
}, marketplaceMetadata, (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    } else {
        console.log(JSON.stringify(response, null, " "))
    }
})
```
---
## APIs

### Purchase a Deal API
* #### Purchase a particular deal.
```javascript=
marketplaceClient.PurchaseDeal({
    "user_id": "user pocket id",
    "deal_id": "deal id"
}, marketplaceMetadata,  (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    }
    console.log(JSON.stringify(response, null, " "))
})
```


### Filter Benefits API
- Parent page -> [Home Page](#Home-Page)


* #### Get user Pocket info
    1. This is required for getting the user_level which is needed for making the list benefits call with user_level.
```javascript=
pocketClient.GetPocketByID({
    "id": "858af6104b7e44048bbbe6addad44daf"
}, pocketMetadata,  (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    }
    console.log(JSON.stringify(response, null, " "))
})
```

* #### List Benefits
```javascript=
marketplaceClient.ListBenefits({
    "status": "published",
    "level": "user level",
    "city":"user city",
    "visibility": true
}, marketplaceMetadata, (err, response) => {
    if (err) {
        console.log(JSON.stringify(err))
    } else {
        console.log(JSON.stringify(response, null, " "))
    }
})
```
- For every returned benefit, check,
    1. if that user is eligible for that benefit.if yes, put it on final list that we'll show to that user.




