# Mobib

The MoBIB container facilitates communication with card readers and inserted MoBIB smart cards. The T1C-JS client library provides functionality to communicate with the smart card and facilitates integration into a web or native application.\
This document describes the functionality provided by the MoBIB container on the T1C-GCL (Generic Connector Library).

## Get MoBIB container object

For more information on how to configure the T1C-JS client library see [Client Configuration](/t1c-js-guide/core/client-configuration.md).\
Initialize a gclClient:

```javascript
GCLLib.GCLClient.initialize(config, function(err, gclClient) {
    // gclClient ready to use
});
```

Get the MoBIB container service:

```javascript
var mobib = gclClient.mobib(reader_id);
```

Call a function for the MoBIB container:

```javascript
function callback(err,data) {
    if(err){console.log("Error:",JSON.stringify(err, null, '  '));}
    else {console.log(JSON.stringify(data, null, '  '));}
}
mobib.status(callback);
```

### Obtain the Reader-ID

The constructor for the MoBIB containers expects a valid reader-ID as parameter. A reader-ID can be obtained from the exposed core functionality, for more information see [Core Services](/t1c-js-guide/core/core-services.md).\
Core services responds with available card-readers, available card in a card-reader, etc.\
For example:\
In order to get all connected card-readers, with available cards:

```javascript
var core = gclClient.core();
core.readersCardAvailable(callback);
```

This function call returns:

```javascript
{
  "data": [
    {
      "card": {
        "atr": "3B6F0000805A2C23C310100511000111829000",
        "description": ["MOBIB Card"]
      },
      "id": "57a3e2e71c48cee9",
      "name": "Bit4id miniLector",
      "pinpad": false
    }
  ],
  "success": true
}
```

We notice that a card object is available in the response in the context of a detected reader.\
The reader in the example above is `Bit4id miniLector`, has no pin-pad capabilities, and there is a card detected with given ATR and description "MOBIB Card". An ATR (**A**nswer **T**o **R**eset) identifies the type of a smart-card.\
The reader, has a unique ID, `reader_id`; this `reader_id` must be used in order to request functionalities for the MoBIB card.\
This must be done upon instantiation of the MoBIB container:

```javascript
var mobib = gclClient.mobib(reader_id);
```

All methods for `mobib` will use the selected reader - identified by the `reader_id`.

## Card data

### Status

The MoBIB card can be locked, this means that application(s) on the MoBIB card have been locked by operators. To retrieve this information, the status of the MoBIB card can be requested. Note that this is not related to the expiry date of the card.\
The service can be called:

```javascript
gclClient.mobib(reader_id).status(callback);
```

An example callback:

```javascript
function callback(err,data) {
    if(err){
        console.log("Error:",JSON.stringify(err, null, '  '));
    }
    else {
        console.log(JSON.stringify(data, null, '  '));
    }
}
```

Response:

```javascript
{
  "data": {
    "active": true
  },
  "success": true
}
```

### Card Issuing

The MoBIB card contains a information about the holder of the card.

The service can be called:

```javascript
gclClient.mobib(reader_id).cardIssuing(callback);
```

Response:

```javascript
{
  "data": {
    "card_expiration_date": "2016-01-31", 
    "card_holder_birth_date": "1964-07-23", 
    "card_holder_end_date": "2016-01-31", 
    "card_holder_id": "6060575401800002365",
    "card_holder_name": "MIAO-                ERH WANG LIU                  ",
    "card_holder_start_date": "2012-02-11",
    "card_revalidation_date": "2012-02-10",
    "card_type": 1,
    "company_id": 18,
    "gender": 1, 
    "language": 2,
    "version": 1
  },
  "success": true
}
```

### Picture

Contains the card holder's picture stored on the smart card. The service can be called:

```javascript
gclClient.mobib(reader_id).picture(callback);
```

Response:

```javascript
{
  "data": "/9j/4AAQSkZJRgABA...59aVpcklSDzyKUTEDGK//9k=",
  "success": true
}
```

### Contracts

The MoBIB card can contains contracts written by the operators (e.g. SNCB, De Lijn, MIVB, TEC).

The service can be called:

```javascript
gclClient.mobib(reader_id).contracts(callback);
```

Response:

```javascript
{
  "data": [
    {
      "authenticator_kvc": 17, 
      "authenticator_value": 587, 
      "journey_interchanges_allowed": false, 
      "passengers_max": 7, 
      "period_journeys": {
        "max_number_of_trips": 13, 
        "period": 2
      }, 
      "price_amount": 500, 
      "provider": 1, 
      "restrict_code": 5, 
      "restrict_time": 2, 
      "sale_date": "2014-03-06", 
      "sale_sam_count": 15, 
      "sale_sam_id": 25, 
      "spatials": [
        {
          "type": 7
        }
      ], 
      "tariff": {
        "counter": {
          "time": "2017-02-21T06:20:00", 
          "type": 4
        }, 
        "multimodal": true, 
        "nameref": 231
      }, 
      "validity_duration": {
        "unit": 2, 
        "value": 7
      }, 
      "validity_start_date": "2014-03-06", 
      "vehicle_class_allowed": 1, 
      "version": 4
    },
    {
      "authenticator_kvc": 18, 
      "authenticator_value": 588, 
      "journey_interchanges_allowed": false, 
      "passengers_max": 7, 
      "price_amount": 1000, 
      "provider": 1, 
      "sale_date": "2017-02-06", 
      "sale_sam_count": 1, 
      "sale_sam_id": 2, 
      "spatials": [
        {
          "type": 0
        }
      ], 
      "tariff": {
        "counter": {
          "journeys": "4", 
          "type": 5
        }, 
        "multimodal": true, 
        "nameref": 2
      }, 
      "validity_start_date": "2017-02-06", 
      "vehicle_class_allowed": 1, 
      "version": 4
    }
  ], 
  "success": true
}
```

## Data Filter

### Filter Card Data

All data on the smart card can be dumped at once, or using a filter. In order to read all data at once:

```javascript
var filter = [];
gclClient.mobib(reader_id).allData(filter,callback);
```

Response:

```javascript
{
  "data": {
    "active": false, 
    "card-issuing": {
      "card_expiration_date": "2016-01-31", 
      "card_holder_birth_date": "1964-07-23", 
      "card_holder_end_date": "2016-01-31", 
      "card_holder_id": "6060575401800002365", 
      "card_holder_name": "MIAO-                ERH WANG LIU                  ", 
      "card_holder_start_date": "2012-02-11", 
      "card_revalidation_date": "2012-02-10", 
      "card_type": 1, 
      "company_id": 18, 
      "gender": 1, 
      "language": 2, 
      "version": 1
    }, 
    "contracts": [
      {
      "authenticator_kvc": 17, 
      "authenticator_value": 587, 
      "journey_interchanges_allowed": false, 
      "passengers_max": 7, 
      "period_journeys": {
        "max_number_of_trips": 13, 
        "period": 2
      }, 
      "price_amount": 500, 
      "provider": 1, 
      "restrict_code": 5, 
      "restrict_time": 2, 
      "sale_date": "2014-03-06", 
      "sale_sam_count": 15, 
      "sale_sam_id": 25, 
      "spatials": [
        {
          "type": 7
        }
      ], 
      "tariff": {
        "counter": {
          "time": "2017-02-21T06:20:00", 
          "type": 4
        }, 
        "multimodal": true, 
        "nameref": 231
      }, 
      "validity_duration": {
        "unit": 2, 
        "value": 7
      }, 
      "validity_start_date": "2014-03-06", 
      "vehicle_class_allowed": 1, 
      "version": 4
    },
    {
      "authenticator_kvc": 18, 
      "authenticator_value": 588, 
      "journey_interchanges_allowed": false, 
      "passengers_max": 7, 
      "price_amount": 1000, 
      "provider": 1, 
      "sale_date": "2017-02-06", 
      "sale_sam_count": 1, 
      "sale_sam_id": 2, 
      "spatials": [
        {
          "type": 0
        }
      ], 
      "tariff": {
        "counter": {
          "journeys": "4", 
          "type": 5
        }, 
        "multimodal": true, 
        "nameref": 2
      }, 
      "validity_start_date": "2017-02-06", 
      "vehicle_class_allowed": 1, 
      "version": 4
    }

    ], 
    "picture": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
  }, 
  "success": true
}
```

The filter can be used to ask a list of custom data containers. For example, we want to read only the 'rn', 'picture' and 'rrn certificate':

```javascript
var filter = ['status','card-issuing'];
gclClient.mobib().allData(filter,callback);
```

Response:

```javascript
{
  "data": {
    "active": true, 
    "card-issuing": {
      "card_expiration_date": "2016-01-31", 
      "card_holder_birth_date": "1964-07-23", 
      "card_holder_end_date": "2016-01-31", 
      "card_holder_id": "6060575401800002365", 
      "card_holder_name": "MIAO-                ERH WANG LIU                  ", 
      "card_holder_start_date": "2012-02-11", 
      "card_revalidation_date": "2012-02-10", 
      "card_type": 1, 
      "company_id": 18, 
      "gender": 1, 
      "language": 2, 
      "version": 1
    }
  }, 
  "success": true
}
```

## Error Handling

### Error Object

The functions specified are asynchronous and always need a callback function.\
The callback function will reply with a data object in case of success, or with an error object in case of an error. An example callback:

```javascript
function callback(err,data) {
    if(err){
        console.log("Error:",JSON.stringify(err, null, '  '));
    }
    else {
        console.log(JSON.stringify(data, null, '  '));
    }
}
```

The error object returned:

```javascript
{
  success: false,
  description: "some error description",
  code: "some error code"
}
```

For the error codes and description, see [Status codes](/t1c-js-guide/core/status-codes.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://t1t.gitbook.io/t1c-js-guide/containers/transport/mobib.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
