terminal-gateway 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -0
- package/index.js +2 -0
- package/lib/terminal.js +1 -0
- package/package.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Terminal
|
|
2
|
+
|
|
3
|
+
## Browser Support
|
|
4
|
+
|
|
5
|
+
 |  | |
|
|
6
|
+
--- | --- | --- |
|
|
7
|
+
Latest ✔ | Latest ✔ | Latest ✔ |
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Using npm:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
$ npm install terminal-gateway
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Using yarn:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
$ yarn add terminal-gateway
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Using pnpm:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
$ pnpm add terminal-gateway
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Using CDN:
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<script src="http://localhost:3000/terminal-gateway-uat.min.js"></script>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Congfiguration
|
|
37
|
+
|
|
38
|
+
| Key | Type| Default| Description|
|
|
39
|
+
| --- | --- | --- | --- |
|
|
40
|
+
| key | String | | provide by ABA |
|
|
41
|
+
| timeout | Number | `60000` in milliseconds | The Terminal's expiration time |
|
|
42
|
+
| onSuccess | Function | | The callback function will respond with two parameters |
|
|
43
|
+
| onError | Function | | The callback function will respond with two parameters |
|
|
44
|
+
|
|
45
|
+
## Initiation
|
|
46
|
+
|
|
47
|
+
``` javascript
|
|
48
|
+
const terminal = new Terminal({
|
|
49
|
+
key: '001116A775D266AE67DF1F6CA9C7F071',
|
|
50
|
+
timeout: 50000,
|
|
51
|
+
onSuccess: () => {}
|
|
52
|
+
onError: () => {}
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Sale transaction
|
|
57
|
+
__onSale():__ This method allows you to do sale transactions. user needs to call this function to get the result failed or successful. It is required four parameters:
|
|
58
|
+
| Parameter name | Data type | Require | Default | Description |
|
|
59
|
+
| --- | --- | --- | --- | --- |
|
|
60
|
+
| amount | String | Yes | 0 | amount define transaction |
|
|
61
|
+
| type | String | Yes | SHOWQR | SHOWQR: sale by screen QR codeEDC: sale by card |
|
|
62
|
+
| invoice | String | Yes | The invoice number must be unique. Example: INV0011620291635 |
|
|
63
|
+
|
|
64
|
+
Code:
|
|
65
|
+
``` javascript
|
|
66
|
+
terminal.onSale({amount: '0.01', type: 'SHOWQR', currency: 'USD', invoice: 'INV0011620291635'})
|
|
67
|
+
```
|
|
68
|
+
## Enquiry transaction
|
|
69
|
+
__onEnquiry():__ This method allows you to receive the response back with the result status of the transaction whether it's successful or failed. It is required a parameter:
|
|
70
|
+
|
|
71
|
+
| Parameter name | Data type | Require | Default |Description |
|
|
72
|
+
| --- | --- | --- | --- | --- |
|
|
73
|
+
| invoice | String | Yes | | The invoice number must be unique. example: `INV0011620291635`|
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
``` javascript
|
|
77
|
+
terminal.onEnquiry({invoice: 'INV0011620291635'})
|
|
78
|
+
```
|
|
79
|
+
## Void transaction
|
|
80
|
+
__onVoid():__ This method allows you to void the transaction. It is required a parameter:
|
|
81
|
+
| Parameter name | Data type | Require | Default |Description |
|
|
82
|
+
| --- | --- | --- | --- | --- |
|
|
83
|
+
| traceId | String | Yes | | trace number of sale transaction response |
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## Cancelation transaction
|
|
87
|
+
__onCancel():__ This method allows the cancellation of the sale of the transaction.
|
|
88
|
+
``` javascript
|
|
89
|
+
terminal.onCancel()
|
|
90
|
+
```
|
package/index.js
ADDED
package/lib/terminal.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a0_0x2d91cf=a0_0x26aa;(function(_0x3ef4ba,_0x3ba422){const _0x30ae7c=a0_0x26aa,_0x44488f=_0x3ef4ba();while(!![]){try{const _0x5dc3bd=-parseInt(_0x30ae7c(0x89))/0x1+parseInt(_0x30ae7c(0x7b))/0x2*(-parseInt(_0x30ae7c(0x9a))/0x3)+parseInt(_0x30ae7c(0x80))/0x4*(-parseInt(_0x30ae7c(0x6c))/0x5)+-parseInt(_0x30ae7c(0x6d))/0x6*(-parseInt(_0x30ae7c(0x6b))/0x7)+-parseInt(_0x30ae7c(0x7a))/0x8*(parseInt(_0x30ae7c(0x7f))/0x9)+-parseInt(_0x30ae7c(0x6f))/0xa+-parseInt(_0x30ae7c(0xa2))/0xb*(-parseInt(_0x30ae7c(0x90))/0xc);if(_0x5dc3bd===_0x3ba422)break;else _0x44488f['push'](_0x44488f['shift']());}catch(_0x17e3f5){_0x44488f['push'](_0x44488f['shift']());}}}(a0_0xecb8,0x4347d));import a0_0x2ba8a0,{enc}from'crypto-js';function a0_0x26aa(_0x8b77d1,_0x48a653){const _0xecb86a=a0_0xecb8();return a0_0x26aa=function(_0x26aa37,_0x5cc546){_0x26aa37=_0x26aa37-0x6b;let _0xf10656=_0xecb86a[_0x26aa37];return _0xf10656;},a0_0x26aa(_0x8b77d1,_0x48a653);}function a0_0xecb8(){const _0x1d8543=['SALE_CANCEL','your\x20testing\x20it\x20ok','onSuccess','Device\x20lost\x20connection','getWriter','493798JDRMJr','readable','read','VOID','toUpperCase','open','then','12oGudUC','onErrors','close','SALE','requestPort','Timeout','Key\x20is\x20not\x20empty.','replace','getReader','You\x20do\x20not\x20provide\x20me\x20your\x20key.\x20Please\x20help\x20provide\x20me\x20your\x20key.','3NAWquK','writable','pipeTo','Your\x20browser\x20is\x20not\x20supported.','catch','onConnected','write','connect','19839842IzQYzj','MEMENQ','parse','addEventListener','7Qqbdpo','15sIjMUe','3085782nauJvv','getPorts','3632810iMkQgS','split','onSale','onVoid','cancel','serial','disconnect','releaseLock','length','message','stringify','28328ouUtWX','746598WnFyrU','Connected','onCancel','push','1278PQToom','412184KSnVZh','error','toISOString','toString'];a0_0xecb8=function(){return _0x1d8543;};return a0_0xecb8();}class Terminal{#KEY=null;#DATA=null;#PORT=null;#TIMER=null;#WRITER=null;#READER=null;#TIMEOUT=null;#DATE_BITS=0x8;#STOP_BITS=0x1;#BAUD_RATE=0x1c200;#PARITY='none';#BUFFER_SIZE=0x400;#MD5_ENCRYPTION=null;#WRITABLE_STREAM_CLOSED=null;#READABLE_STREAM_CLOSED=null;#DATE_FORMAT=new Date()[a0_0x2d91cf(0x82)]()[a0_0x2d91cf(0x97)]('T','\x20')[a0_0x2d91cf(0x97)]('Z','')[a0_0x2d91cf(0x70)]('.')[0x0];#FILTERS=[{'usbVendorId':0x5c6,'usbProductId':0x9025},{'usbVendorId':0x67b,'usbProductId':0x2303}];#SUPPORTED_BROWSER=0x1;#OPEN_SERIAL_PORT_ERROR=0x2;#OPEN_SERIAL_PORT_PAIR_ERROR=0x3;#WRITE_STREAM_ERROR=0x4;#READ_STREAM_ERROR=0x5;#VALIDATE_KEY=0x6;#CONNECTED_SERIAL_PORT=0x7;#DISCONNECTED_SERIAL_PORT=0x8;constructor({key:_0x4d2d2c,timeout:_0x4631a4,onConnected:_0xd42b17,onSuccess:_0x169d0e,onErrors:_0x57a635}){const _0xa26205=a0_0x2d91cf;if(!_0x4d2d2c)console[_0xa26205(0x81)](_0xa26205(0x99));this.#KEY=_0x4d2d2c,this.#TIMEOUT=_0x4631a4||0xea60,this[_0xa26205(0x86)]=_0x169d0e||function(){},this[_0xa26205(0x91)]=_0x57a635||function(){},this[_0xa26205(0x9f)]=_0xd42b17||function(){},!this.#isSupportedBrowser()&&(console['error']('Your\x20browser\x20is\x20not\x20supported.'),this[_0xa26205(0x91)]({'status':this.#SUPPORTED_BROWSER,'message':_0xa26205(0x9d)})),navigator['serial'][_0xa26205(0xa5)](_0xa26205(0xa1),_0x5f0c96=>{const _0x215a99=_0xa26205;this[_0x215a99(0x86)]({'status':this.#CONNECTED_SERIAL_PORT,'message':'Device\x20has\x20connected.'});if(this.#TIMER)clearTimeout(this.#TIMER);}),navigator[_0xa26205(0x74)]['addEventListener'](_0xa26205(0x75),async _0x5c57c8=>{const _0x5bd1d3=_0xa26205;this[_0x5bd1d3(0x86)]({'status':this.#DISCONNECTED_SERIAL_PORT,'message':_0x5bd1d3(0x87)});if(this.#TIMER)clearTimeout(this.#TIMER);});}#handleRequestSerialPort(){return new Promise((_0x51e6a8,_0x1fc312)=>{const _0x4a873b=a0_0x26aa;return navigator['serial'][_0x4a873b(0x94)]({'filters':this.#FILTERS})['then'](_0x393e44=>{_0x51e6a8(_0x393e44);})[_0x4a873b(0x9e)](_0x37e977=>{const _0x4d5811=_0x4a873b;_0x1fc312({'status':this.#OPEN_SERIAL_PORT_ERROR,'message':_0x37e977?.[_0x4d5811(0x78)]});});});}#handleOpenSerialPort(){return new Promise((_0x435017,_0xcfc273)=>{const _0x59c2a0=a0_0x26aa;return this.#PORT[_0x59c2a0(0x8e)]({'baudRate':this.#BAUD_RATE,'dataBits':this.#DATE_BITS,'stopBits':this.#STOP_BITS,'parity':this.#PARITY,'bufferSize':this.#BUFFER_SIZE})[_0x59c2a0(0x8f)](_0x5e9e64=>_0x435017(_0x5e9e64))[_0x59c2a0(0x9e)](_0x139447=>{const _0x3735db=_0x59c2a0;_0xcfc273({'status':this.#OPEN_SERIAL_PORT_PAIR_ERROR,'message':_0x139447?.[_0x3735db(0x78)]});});});}async[a0_0x2d91cf(0x71)]({amount:_0x5a8b07,type:_0x677add,currency:_0xcecd5e,invoice:_0x337dbf}){const _0x19eab0=a0_0x2d91cf;try{if(!this.#isSupportedBrowser()){console[_0x19eab0(0x81)](_0x19eab0(0x9d)),this['onErrors']({'status':this.#SUPPORTED_BROWSER,'message':_0x19eab0(0x9d)});return;}if(!this.#KEY){this[_0x19eab0(0x91)]({'status':this.#VALIDATE_KEY,'message':_0x19eab0(0x96)});return;}const _0x2c9a7a=await navigator['serial']['getPorts']();!this.#PORT&&!_0x2c9a7a[_0x19eab0(0x77)]?(this.#PORT=await this.#handleRequestSerialPort(),await this.#handleOpenSerialPort(),this[_0x19eab0(0x86)]({'status':this.#SUPPORTED_BROWSER,'message':_0x19eab0(0x7c)})):(this.#PORT=_0x2c9a7a[0x0],await this.#handleOpenSerialPort());this.#DATA=this.#handleGenerateJSONObject({'CMD':'SALE','type':_0x677add,'amount':_0x5a8b07,'currency':_0xcecd5e,'invoice':_0x337dbf});const _0x38f2bd=this.#handleGenerateMD5(this.#DATA);await this.#handleWriteStream(_0x38f2bd),this.#handleSetTimeout(),this.#handleReadStream(),await this.#listenToTerminal();}catch(_0x469ba0){this[_0x19eab0(0x91)](_0x469ba0);}}async[a0_0x2d91cf(0x72)]({traceId:_0x2180ce}){const _0x3d4722=a0_0x2d91cf;try{if(!this.#isSupportedBrowser()){console[_0x3d4722(0x81)](_0x3d4722(0x9d)),this[_0x3d4722(0x91)]({'status':this.#SUPPORTED_BROWSER,'message':'Your\x20browser\x20is\x20not\x20supported.'});return;}if(!this.#KEY){this[_0x3d4722(0x91)]({'status':this.#VALIDATE_KEY,'message':_0x3d4722(0x96)});return;}if(!this.#PORT&&!ports[_0x3d4722(0x77)])this.#PORT=await this.#handleRequestSerialPort(),await this.#handleOpenSerialPort(),this[_0x3d4722(0x86)]({'status':this.#SUPPORTED_BROWSER,'message':'Connected'});else{const _0x39c24b=await navigator[_0x3d4722(0x74)]['getPorts']();this.#PORT=_0x39c24b[0x0],await this.#handleOpenSerialPort();}const _0x59c23e=this.#handleGenerateJSONObject({'CMD':_0x3d4722(0x8c),'traceId':_0x2180ce}),_0x300489=this.#handleGenerateMD5(_0x59c23e);await this.#handleWriteStream(_0x300489),this.#handleReadStream(),await this.#listenToTerminal();}catch(_0xccf83f){this[_0x3d4722(0x91)](_0xccf83f);}}async['onEnquiry']({invoice:_0x12ce86}){const _0x3fa993=a0_0x2d91cf;try{if(!this.#isSupportedBrowser()){console[_0x3fa993(0x81)]('Your\x20browser\x20is\x20not\x20supported.'),this['onErrors']({'status':this.#SUPPORTED_BROWSER,'message':_0x3fa993(0x9d)});return;}if(!this.#KEY){this[_0x3fa993(0x91)]({'status':this.#VALIDATE_KEY,'message':_0x3fa993(0x96)});return;}if(!this.#PORT&&!ports['length'])this.#PORT=await this.#handleRequestSerialPort(),await this.#handleOpenSerialPort(),this[_0x3fa993(0x86)]({'status':this.#SUPPORTED_BROWSER,'message':'Connected'});else{const _0x4fa071=await navigator[_0x3fa993(0x74)][_0x3fa993(0x6e)]();this.#PORT=_0x4fa071[0x0],await this.#handleOpenSerialPort();}const _0x3416b8=this.#handleGenerateJSONObject({'CMD':'MEMENQ','invoice':_0x12ce86}),_0x36913e=this.#handleGenerateMD5(_0x3416b8);await this.#handleWriteStream(_0x36913e),this.#handleReadStream(),await this.#listenToTerminal();}catch(_0x3778aa){this[_0x3fa993(0x91)](_0x3778aa);}}async[a0_0x2d91cf(0x7d)](){const _0x45d83c=a0_0x2d91cf;try{if(!this.#isSupportedBrowser()){console[_0x45d83c(0x81)](_0x45d83c(0x9d)),this[_0x45d83c(0x91)]({'status':this.#SUPPORTED_BROWSER,'message':'Your\x20browser\x20is\x20not\x20supported.'});return;}if(!this.#KEY){this[_0x45d83c(0x91)]({'status':this.#VALIDATE_KEY,'message':_0x45d83c(0x96)});return;}this['handleReleasePort']();const _0x25c0c5=await navigator[_0x45d83c(0x74)][_0x45d83c(0x6e)]();this.#PORT=_0x25c0c5[0x0],await this.#handleOpenSerialPort();const _0x23d1a6=this.#handleGenerateJSONObject({'CMD':_0x45d83c(0x84)}),_0x752375=this.#handleGenerateMD5(_0x23d1a6);await this.#handleWriteStream(_0x752375),this.#handleReadStream(),await this.#listenToTerminal();}catch(_0x108df9){this[_0x45d83c(0x91)](_0x108df9);}}#handleWriteStream(_0x86e4bf){return new Promise((_0x684bda,_0x1140e6)=>{const _0xa3970e=a0_0x26aa,_0x2e8e3f=new TextEncoderStream();return this.#WRITABLE_STREAM_CLOSED=_0x2e8e3f['readable'][_0xa3970e(0x9c)](this.#PORT[_0xa3970e(0x9b)]),this.#WRITER=_0x2e8e3f[_0xa3970e(0x9b)][_0xa3970e(0x88)](),this.#WRITER[_0xa3970e(0xa0)](_0x86e4bf)['then'](_0x4379ab=>{_0x684bda(_0x4379ab);})['catch'](_0xdbdbff=>{const _0x2ff473=_0xa3970e;_0x1140e6({'status':this.#WRITE_STREAM_ERROR,'message':_0xdbdbff?.[_0x2ff473(0x78)]});});});}#handleReadStream(){const _0x3cbab0=a0_0x2d91cf;try{const _0x3c1c1a=new TextDecoderStream();this.#READABLE_STREAM_CLOSED=this.#PORT[_0x3cbab0(0x8a)][_0x3cbab0(0x9c)](_0x3c1c1a[_0x3cbab0(0x9b)]),this.#READER=_0x3c1c1a['readable'][_0x3cbab0(0x98)]();}catch(_0x2d6bc2){this[_0x3cbab0(0x91)]({'status':this.#READ_STREAM_ERROR,'message':_0x2d6bc2?.[_0x3cbab0(0x78)]});}}#handleGenerateJSONObject({CMD:_0x29e629,type:_0x23bc61,amount:_0x3837ca,currency:_0x1bcbb8,invoice:_0x5a266c,traceId:_0x2ff67a}){const _0x2b563c=a0_0x2d91cf;let _0x4210ea={};switch(_0x29e629){case _0x2b563c(0x93):_0x4210ea={'CMD':_0x2b563c(0x93),'TYPE':_0x23bc61[_0x2b563c(0x83)](),'AMT':_0x3837ca[_0x2b563c(0x83)](),'CURRCODE':_0x1bcbb8[_0x2b563c(0x83)](),'TIMESTAMP':this.#DATE_FORMAT,'ECRREF':_0x5a266c[_0x2b563c(0x83)]()};break;case _0x2b563c(0x8c):_0x4210ea={'CMD':'VOID','TIMESTAMP':this.#DATE_FORMAT,'TRACE':_0x2ff67a[_0x2b563c(0x83)]()};break;case _0x2b563c(0xa3):_0x4210ea={'CMD':_0x2b563c(0xa3),'TIMESTAMP':this.#DATE_FORMAT,'ECRREF':_0x5a266c[_0x2b563c(0x83)]()};break;case'SALE_CANCEL':_0x4210ea={'CMD':_0x2b563c(0x84),'TIMESTAMP':this.#DATE_FORMAT};break;}return _0x4210ea;}#handleGenerateMD5(_0x41ae72){const _0x5396ed=a0_0x2d91cf,_0x3ffcaf=JSON[_0x5396ed(0x79)](_0x41ae72)+this.#KEY;return this.#MD5_ENCRYPTION=a0_0x2ba8a0['MD5'](_0x3ffcaf)[_0x5396ed(0x83)]()[_0x5396ed(0x8d)](),'@'+this.#MD5_ENCRYPTION+JSON[_0x5396ed(0x79)](_0x41ae72);}async #listenToTerminal(){const _0x55866e=a0_0x2d91cf;try{const _0x44207a=[];let _0x14feb4='',_0x446b80=0x0;while(!![]){const {value:_0x22ed82,done:_0x503ff7}=await this.#READER[_0x55866e(0x8b)]();if(_0x503ff7){this.#READER[_0x55866e(0x76)]();break;}if(this.#TIMER)clearTimeout(this.#TIMER);_0x14feb4+=_0x22ed82,_0x446b80+=0x1;const _0x5dd332=setTimeout(async()=>{this.#handlePrintResult(_0x14feb4),this.#handleReleasePort();},0x64);_0x44207a[_0x55866e(0x7e)](_0x5dd332),clearTimeout(_0x44207a[_0x446b80-0x2]);}}catch(_0x41e181){this['onErrors']({'status':this.#READ_STREAM_ERROR,'message':_0x41e181?.['message']});}}#handleSetTimeout(){this.#TIMER=setTimeout(async()=>{const _0x45a415=a0_0x26aa,_0x1cfeb4='@'+this.#MD5_ENCRYPTION+JSON['stringify']({...this.#DATA,'APV':'','PAN':'','PAYER':'','MESSAGE':'','TRXN_ID':'','TRACE':'','STATUS':_0x45a415(0x95)});this.#handlePrintResult(_0x1cfeb4),this.#handleReleasePort();},this.#TIMEOUT);}#handlePrintResult(_0x5806d4){const _0x202ef3=a0_0x2d91cf;if(!_0x5806d4)return;this[_0x202ef3(0x86)]({'key':this.#KEY,'value':JSON[_0x202ef3(0xa4)](_0x5806d4['slice'](0x21))});}async #handleReleasePort(){const _0x5eb59d=a0_0x2d91cf;this.#READER[_0x5eb59d(0x73)](),await this.#READABLE_STREAM_CLOSED['catch'](()=>{}),this.#WRITER[_0x5eb59d(0x92)](),await this.#WRITABLE_STREAM_CLOSED[_0x5eb59d(0x9e)](()=>{}),await this.#PORT[_0x5eb59d(0x92)]();}#isSupportedBrowser(){const _0x2f91ef=a0_0x2d91cf;return _0x2f91ef(0x74)in navigator;}['getTesting'](){const _0x1884df=a0_0x2d91cf;return _0x1884df(0x85);}}export default Terminal;
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "terminal-gateway",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "POS SDK is a library that allows users to perform sale transactions on a terminal from a web browser.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"terminal",
|
|
10
|
+
"sdk",
|
|
11
|
+
"terminal-gateway"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"crypto-js": "^4.1.1"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {}
|
|
17
|
+
}
|