Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/zemuldo/iso_8583

:credit_card::moneybag: JavaScript library for iso 8583 messaging. Handles message validation & conversion between interfaces using iso 8583 standard. Contributors are welcome.
https://github.com/zemuldo/iso_8583

8583 card iso iso8583 node tcpmessage

Last synced: 11 days ago
JSON representation

:credit_card::moneybag: JavaScript library for iso 8583 messaging. Handles message validation & conversion between interfaces using iso 8583 standard. Contributors are welcome.

Lists

README

        

# ISO_8583

[![Greenkeeper badge](https://badges.greenkeeper.io/zemuldo/iso_8583.svg)](https://greenkeeper.io/)~![Travis CI build badge](https://travis-ci.org/zemuldo/iso_8583.svg?branch=main)~[![Known Vulnerabilities](https://snyk.io/test/github/zemuldo/iso_8583/badge.svg?targetFile=package.json)](https://snyk.io/test/github/zemuldo/iso_8583?targetFile=package.json)

ISO_8583 is a Customizable ISO 8583 Library for JavaScript and NodeJS that does message conversion between a system and an interface that exchange [ISO 8583 Financial transaction card originated messages](https://en.wikipedia.org/wiki/ISO_8583).

## Install from npm using

```shell

npm install --save iso_8583
```

### OR

```shell
yarn add iso_8583
```

## Basic Usage: Bitmap Messaging

See the a sample usage example see [this example](https://github.com/zemuldo/iso_8583/tree/main/example)

```javascript
const iso8583 = require('iso_8583');
let data = {
0: "0100",
2: "4761739001010119",
3: "000000",
4: "000000005000",
7: "0911131411",
12: "131411",
13: "0911",
14: "2212",
18: "4111",
22: "051",
23: "001",
25: "00",
26: "12",
32: "423935",
33: "111111111",
35: "4761739001010119D22122011758928889",
41: "12345678",
42: "MOTITILL_000001",
43: "My Termianl Business ",
49: "404",
52: "7434F67813BAE545",
56: "1510",
123: "91010151134C101",
127: "000000800000000001927E1E5F7C0000000000000000500000000000000014A00000000310105C000128FF0061F379D43D5AEEBC8002800000000000000001E0302031F000203001406010A03A09000008CE0D0C840421028004880040417091180000014760BAC24959"
};

let customFormats = {
'3': {
ContentType: 'n',
Label: 'Processing code',
LenType: 'fixed',
MaxLen: 9
}
};

let isopack = new iso8583(data,customFormats);
```

The object initialized has the following methods:

##### To validate the iso message

```javascript
isopack.validateMessage(); // returns true for valid message or error

```

##### To get the mti as a string:
```javascript
isopack.getMti(); // returns a 4 byte buffer containing the mti

```

##### To get the bitmaps in binary:

```javascript
isopack.getBmpsBinary(); // returns a string '1111001000111..' or an error object with error prop

```

##### To get the bitmap active fields:

```javascript
isopack.getBitMapFields();
// returns the array of enabled fields in bitmap, excluding MTI and bitmap fields
// e.g. [2, 3, 4, 7, 12, 13, 14, 18, 22, 23, 25, 26, 32, 33, 35, 41, 42, 43, 49, 52, 56, 123, 127]

```

##### To get the bitmaps in hex for fields 0-127, fields 127 extensions and fields 127.25 extensions

```javascript
isopack.getBitMapHex(); // returns 'f23c46c1a8e091000000000000000022'
isopack.getBitMapHex_127_ext(); // returns '8000008000000000'
isopack.getBitMapHex_127_ext_25(); // returns 'fe1e5f7c00000000'

// in case of error, the error object returned with error prop
```

##### To get a raw message:

```javascript
let bufferMessage = isopack.getRawMessage();
// returns a buffer containing the message (without 2-byte length field) or an error object
\n' +
'0200\n' +
'\n' +
'4839123456709012\n' +
'000000\n' +
'000000001500\n' +
'0604074705\n' +
'804058\n' +
'074808\n' +
'0604\n' +
'0812\n' +
'0905\n' +
'901\n' +
'02\n' +
'05\n' +
'000000500\n' +
'000000500\n' +
'483912\n' +
'4839123456709012=08125876305082011\n' +
'D000A0030000\n' +
'507\n' +
'FOFUGUT1\n' +
'191121119111112\n' +
'Postilion Cafeteria Rondebosch ZA\n' +
'710 1510\n' +
'0000000072\n' +
'211401213041013\n' +
'0007713856\n' +
'013040604040604016501100330000\n' +
'My Terminal Business\n' +
'20100604\n' +
'\n' +
'';

isoPack.getJsonFromXml(xmlData); // returns a json object or an error object
```

## Usage: MTI converting

### Changing current mti type

Initialize the iso object with the json as argument

```javascript
let data = {
0: '0400',
2: '4761739001010119',
3: '000000',
4: '000000005000',
7: '0911131411'
};

let isopack = new isoPack(data);
isoPack.toRetransmit()
isoPack.getMti(); // returns '0401'

isopack = new isoPack(data);
isoPack.toResponse();
isoPack.getMti(); // returns '0410'

isopack = new isoPack(data);
isoPack.toAdvice();
isoPack.getMti(); // returns '0420'

```

There are other cool stuff like ```isoPack.attachTimeStamp()``` which adds times stamps to field 7,12,13, plus more
When working with xml, first change the xml to json then validate.

## Configuration and Customization

### Custom ISO 8583 Formats.

This library Supports custom ISO 8583 Formats, versions 1993 and 2003. This means you can decide what data types are allowed on each field, the length properties of the field and its description.
Custom ISO 8583 formats must be passed in the format below.

```javascript
{
'FIELD_NAME': {
ContentType: 'Types accepted',
Label: 'Description of the field',
LenType: 'Length type can bee fixed or lvar ...',
MaxLen: Maximum length (number)
}
}
```

Here is an example of custom format for field 3. You can refer to formats in the docs to see the default formats.

```javascript

let customFormats = {
'3': {
ContentType: 'n',
Label: 'Processing code',
LenType: 'fixed',
MaxLen: 9
}
};

```

### Required fields

You can also set required field for message types as you desire.
To use required fields you need to create a json config file and add to the class when creating a new message class, thats two ways works:

```javascript
let isopack = new iso8583(iso);
isopack.requiredFieldsSchema = './config/required-fields.json';
```

```javascript
const required_fields = './config/required-fields.json';
let isopack = new iso8583(iso, customFormats, required_fields);
```

And at the config file you can organize by process code and by messages codes, like this:

```json
[
{
"processing_code": "000000",
"required_fields": [0, 2, 4]
},
{
"processing_code": "999999",
"required_fields":[
{
"0100": [3, 7],
"0500": [3, 7, 11]
}
]
}
]
```

### Message Packaging and Un-packaging

This library uses a default mode of message encoding and packaging. If you are using a third party message source or a third party packaging source, you have to pre-format your data to meet the default encoding or configure things for yourself. See configuration for more info.

### Unpacking

This only applies when you are receiving messages from others sources that don't encode as per this library like JPos.
Default unpack conditions:

`2-byte leng header in hex` + `4-byte MTI encoded in utf8` + `16-byte Bitmap encoded in hex`

If the message you are receiving is in a different state, the passing config to `getIsoJSON` like below.

### Packing

Messages are packaged as:

- 2 byte length indicator + 4 byte message type + 16 byte bitmap(primary + secondary bitmap) + message field data.
- Each field with variable length data is preceded with the actual length of the data in that field.

###### Field 127 and 127.25

>The library extends fields 127 and fields 127.25 to their sub fields.
>If you are handling a json with field 127 or 127.25 as one string, the bitmap must be 16 character string then a 4 digit number indicating the length
>In the above case the library will expand them.
>If they are already broken down to subfields, nothing changes.
>To invoke the package initialize with the iso8583 json or object as argument. If the json contains any fields not defined in iso8583 or has no field 0, the error is returned in an object.
>If you want to handle xml iso 8583 messages, the usage is described down there.

## Thanks , Have Fun